Retrieve the preview URL from the Cloudflare API, filtered by the repository and branch. The URL can then be used for further end-to-end tests, link checks and other PR integrations/actions.
Cloudflare needs a little time to build the preview, you can check the average build time in your deployments and add the seconds plus a little to a sleep
action, to wait until the deployment is ready. The action only works on branches, so make sure you exclude the main
branch from the trigger:
on:
push:
branches:
- '**'
- '!main'
Here are the steps for an example job:
- run: sleep 30
- name: cloudflare-preview-url
uses: zentered/cloudflare-preview-url@v1.0.0
id: cloudflare_preview_url
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_EMAIL: ${{ secrets.CLOUDFLARE_ACCOUNT_EMAIL }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
with:
cloudflare_project_id: 'repo-name'
wait_until_ready: true
- name: Get URL
run: echo "https://${{ steps.cloudflare_preview_url.outputs.preview_url }}"
We recommend to set a timeout for this action, if something goes wrong with the build, the Action should stop after 10 minutes:
runs-on: ubuntu-latest
timeout-minutes: 10
In the repository, go to "Settings", then "Secrets" and add "CLOUDFLARE_API_TOKEN", the value you can retrieve on your Cloudflare account. You also need to add:
CLOUDFLARE_ACCOUNT_EMAIL
(your login email, optional)CLOUDFLARE_ACCOUNT_ID
(from the URL:https://dash.cloudflare.com/123abc....
)
Name | Requirement | Description |
---|---|---|
cloudflare_project_id |
required | Cloudflare project id/name |
wait_until_ready |
optional | Wait until the Cloudflare deployment is ready, defaults to "false" |
environment |
optional | Which Cloudflare deployment environments to allow. If set to null, doesn't filter deploys by environment. Defaults to "preview" |
commit_hash |
optional | Optional commit hash to filter deployments on. Useful when the same branch can have multiple deploys. |
branch |
optional | Optional branch name to filter deployments on. Useful when the branch name is not available in the action context. |
Name | Description |
---|---|
preview_url |
A string with the unique URL of the deployment. If it hasn't finished uploading (is incomplete), the value will be null |
See CONTRIBUTING.
See LICENSE.