Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pages deployments #765

Merged
merged 8 commits into from May 16, 2022
Merged

Pages deployments #765

merged 8 commits into from May 16, 2022

Conversation

WalshyDev
Copy link
Member

Description

This PR covers the Pages Deployment section (https://cfapi.centminmod.com/#pages-deployment-properties). It has been quite a while since I touched Go so any feedback here is appreciated!

Has your change been tested?

Yes, all the code has been tested and the unit tests pass. Here is my test code:

func Test() {
	api, err := cloudflare.New("GLOBAL_KEY", "EMAIL")
	if err != nil {
		panic(err)
	}

	ctx := context.Background()
	_, validateErr := api.UserDetails(ctx)
	if validateErr != nil {
		panic(validateErr)
	}

	const accountId = "ACCOUNT_ID"
	const projectName = "test"

	// Deployment list - /accounts/:account_id/pages/projects/:project_name/deployments
	deployments, _, err1 := api.ListPagesDeployments(ctx, accountId, projectName, cloudflare.PaginationOptions{})
	if err1 != nil {
		panic(err1)
	}
	fmt.Println(deployments[0].ID, deployments[0].ShortID)

	// Deployment - /accounts/:account_id/pages/projects/:project_name/deployments/:deployment_id
	deployment, err2 := api.GetPagesDeploymentInfo(ctx, accountId, projectName, deployments[0].ID)
	if err2 != nil {
		panic(err2)
	}
	fmt.Println(deployment.ID, deployment.ShortID)

	// Logs (default options) - /accounts/:account_id/pages/projects/:project_name/deployments/:deployment_id/history/:deployment_stage_name/logs
	logs, err3 := api.GetPagesDeploymentStageLogs(ctx, accountId, projectName, deployments[0].ID, "build", cloudflare.SizeOptions{})
	if err3 != nil {
		panic(err3)
	}
	fmt.Println(logs.Name, logs.Total, logs.Start, logs.End)
	fmt.Println(logs.Data[0])

	// Logs (custom options) - /accounts/:account_id/pages/projects/:project_name/deployments/:deployment_id/history/:deployment_stage_name/logs
	logsCustom, err4 := api.GetPagesDeploymentStageLogs(ctx, accountId, projectName, deployments[0].ID, "build", cloudflare.SizeOptions{After: 5})
	if err4 != nil {
		panic(err4)
	}
	fmt.Println(logsCustom.Name, logsCustom.Total, logsCustom.Start, logsCustom.End)
	fmt.Println(logsCustom.Data[0])

	// Create deployment - /accounts/:account_id/pages/projects/:project_name/deployments
	newDeployment, err6 := api.CreatePagesDeployment(ctx, accountId, projectName)
	if err6 != nil {
		panic(err6)
	}
	fmt.Println(newDeployment.ID, newDeployment.ShortID)

	// -- Wait for new build to finish --
	WaitToFinish(api, accountId, projectName, newDeployment.ID)

	// Create deployment 2 - Doing this just so I can delete one
	newDeployment2, err7 := api.CreatePagesDeployment(ctx, accountId, projectName)
	if err7 != nil {
		panic(err7)
	}
	fmt.Println("2 -", newDeployment2.ID, newDeployment2.ShortID)

	// -- Wait for new build to finish --
	WaitToFinish(api, accountId, projectName, newDeployment2.ID)

	// Delete deployment - /accounts/:account_id/pages/projects/:project_name/deployments/:deployment_id
	err8 := api.DeletePagesDeployment(ctx, accountId, projectName, newDeployment.ID)
	if err8 != nil {
		panic(err8)
	}

	// Retry deployment - /accounts/:account_id/pages/projects/:project_name/deployments/:deployment_id/retry
	retriedDeployment, err9 := api.RetryPagesDeployment(ctx, accountId, projectName, newDeployment2.ID)
	if err9 != nil {
		panic(err9)
	}
	fmt.Println(retriedDeployment.ID, retriedDeployment.ShortID)

	// -- Wait for retried build to finish --
	WaitToFinish(api, accountId, projectName, retriedDeployment.ID)

	// Rollback deployment - /accounts/:account_id/pages/projects/:project_name/deployments/:deployment_id
	rollbackDeployment, err10 := api.RollbackPagesDeployment(ctx, accountId, projectName, newDeployment2.ID)
	if err10 != nil {
		panic(err10)
	}
	fmt.Println(rollbackDeployment.ID, rollbackDeployment.ShortID)
}

Screenshots (if appropriate):

Tests passing
image

My test code working
image

Types of changes

What sort of change does your code introduce/modify?

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • This change is using publicly documented (api.cloudflare.com or developers.cloudflare.com) and stable APIs.

@jacobbednarz
Copy link
Member

@WalshyDev we're close; are you interested in finishing this off to get it over the line?

@WalshyDev
Copy link
Member Author

Hey, yes I am. Sorry, I haven't had much time lately. It is definitely still something I want to finish and get merged!

(Side note: First day of onboarding at CF :) )

@jacobbednarz
Copy link
Member

good to hear! congrats and feel free to hit me up in chat if you need help getting this done.

@jacobbednarz
Copy link
Member

pushed a small update to this PR to use the experimental approach of passing in params using a struct to better match where we are going with the next major bump but otherwise, we're good here!

@jacobbednarz
Copy link
Member

@jacobbednarz jacobbednarz merged commit 8665ebb into cloudflare:master May 16, 2022
@WalshyDev WalshyDev deleted the feature/pages-deployments branch July 12, 2022 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants