https://github.com/zentered/cloudflare-preview-url
GitHub Action to return the Cloudflare Pages Preview URL
https://github.com/zentered/cloudflare-preview-url
Last synced: 10 months ago
JSON representation
GitHub Action to return the Cloudflare Pages Preview URL
- Host: GitHub
- URL: https://github.com/zentered/cloudflare-preview-url
- Owner: zentered
- License: mit
- Created: 2021-07-05T07:47:59.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2024-06-23T15:54:54.000Z (about 2 years ago)
- Last Synced: 2025-04-02T23:05:58.500Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 1.22 MB
- Stars: 11
- Watchers: 1
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Cloudflare Preview URL


[](https://github.com/semantic-release/semantic-release)
[](https://conventionalcommits.org)
Retrieve the preview/deployment 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.
## Usage
### API Token (recommended)
Navigate to the
[Cloudflare API Tokens](https://dash.cloudflare.com/profile/api-tokens) page and
create a new token with the following permissions:
- Account - Cloudflare Pages - Read
- Include - [your page]
Copy the token and add it to your repository secrets as `CLOUDFLARE_API_TOKEN`.
### Global API Key
[Copy your "Global API Key"](https://dash.cloudflare.com/profile/api-tokens) -
this also requires the Account Email to be set.
### Workflow template
```yaml
on:
push:
branches:
- '**'
- '!main'
# Add a sleep action to wait until the deployment is ready
- run: sleep 30
- name: cloudflare-preview-url
# Use the latest version
uses: zentered/cloudflare-preview-url@v1.4.2
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 setting a timeout for this action, if something goes wrong with the
build, the Action should stop after 10 minutes:
```yaml
runs-on: ubuntu-latest
timeout-minutes: 10
```
## Environment Variables / Secrets
In the repository, go to "Settings", then "Secrets" and add
`CLOUDFLARE_API_TOKEN`, the value you can retrieve on your
[Cloudflare account](https://dash.cloudflare.com/profile/api-tokens). You also
need to add:
- `CLOUDFLARE_ACCOUNT_ID` (from the URL:
`https://dash.cloudflare.com/123abc....`)
- [optional] `CLOUDFLARE_ACCOUNT_EMAIL` (your login email)
When providing an account email address, the token will not be used as `Bearer`
token.
## Inputs
| 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. |
## Outputs
| 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 |
## Contributing
See [CONTRIBUTING](CONTRIBUTING.md).
## License
See [LICENSE](LICENSE).