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

Create new Action to create GitHub deployments from Cloudflare #469

Merged
merged 4 commits into from
Jul 3, 2024

Conversation

edoardopirovano
Copy link
Contributor

This is a production-ready version of a script I wrote for a customer. I've expanded it to include waiting if the deployment isn't ready.

@edoardopirovano edoardopirovano requested a review from a team July 3, 2024 13:53
Copy link

vercel bot commented Jul 3, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
report-diffs-action ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 3, 2024 4:53pm

Copy link

alwaysmeticulous bot commented Jul 3, 2024

🤖 Meticulous replayed 1 user sessions and took 8 visual snapshots. There were no comparisons made.
If you recently setup Meticulous, this is expected. Meticulous will start reporting comparisons for new pull requests after the next commit to the main branch.

Test suite: public-tests. Last updated for commit 036865a. This comment will update as new commits are pushed.

Copy link

github-actions bot commented Jul 3, 2024

🤖 Meticulous replayed 1 user sessions and took 8 visual snapshots. Meticulous did not run on null of the main branch and so there was nothing to compare against.

Please merge your pull request for setting up Meticulous in CI and ensure that it’s running on push events to the main branch.

Test suite: test Meticulous with deployment url. Last updated for commit 036865a. This comment will update as new commits are pushed.

Copy link

github-actions bot commented Jul 3, 2024

✅ Meticulous spotted zero visual differences across 8 screens tested: view results.

Test suite: test Meticulous with app url. Last updated for commit 036865a. This comment will update as new commits are pushed.

sleep-seconds:
description: 'Time to sleep before starting to poll deployment status (in seconds)'
required: false
default: "300"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the API limits? Is there a risk we'll hit those if we reduce the polling / wait times? 5 minutes initial wait feels long, assuming build times are similar to Vercel, can we wait, say < 30 sec? And also poll every 10 sec or so.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's 1200 requests per 5 minutes. So assuming the user's token is only being used by us, polling once a minute would mean we can be waiting on 240 concurrent builds without hitting the limit. It might be safe to reduce that, but we might break in cases of tools like dependabot opening a load of PRs at once. Still, halving to 30 seconds is probably safe, I'll do that.

token: "${{ inputs.github-token }}"
target_url: "${{ steps.get-url.outputs.url }}"
initial_status: "success"
environment: "Meticulous"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does CF Pages return environment name? If so can we use that from there? If not should we give this deployment some non-Meticulous specific name which mentions CF?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, let's do Cloudfront Pages: << name there >>.

Comment on lines 1 to 2
name: 'Meticulous - Trigger tests for Cloudflare Pages'
description: 'Trigger Meticulous tests for a Cloudflare Pages deployment'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

naming nit: I think a name that relates to how the action works, ie something like 'create a deployment from CF pages preview environment'. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good!

Comment on lines 54 to 55
echo "Deployment is ready!"
echo "url=`curl -s -X GET "https://api.cloudflare.com/client/v4/accounts/${{ inputs.cloudflare-account-id }}/pages/projects/${{ inputs.cloudflare-project-name }}/deployments" -H "Authorization: Bearer ${{ inputs.cloudflare-api-token }}" -H "Content-Type:application/json" | jq -c 'first(.result[] | select(.deployment_trigger.metadata.commit_hash == "${{ github.sha }}") | .url)' --raw-output | tr -d '\n'`" >> $GITHUB_OUTPUT
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does cloudflare-project-name (or any other part) need to be URL encoded?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the project name is alphanumeric plus - which doesn't need to be encoded. The others are all just alphanumeric.

@edoardopirovano edoardopirovano merged commit bd953a6 into main Jul 3, 2024
10 checks passed
@edoardopirovano edoardopirovano deleted the edoardo/cloudflare branch July 3, 2024 16:59
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.

2 participants