pages-action branch preview URL

Is it possible to grab the branch preview URL out of cloudflare/pages-action? I'm trying to simulate the nice chatops-y build status message the cloudflare build process creates when building in Github instead for more control.
1 Reply
Marcus
MarcusOP11mo ago
Right now I've got
- name: Deploy preview to Cloudflare
uses: cloudflare/pages-action@1
id: pages-action
with:
apiToken: ${{ secrets.CI_CF_PAGES }}
accountId: ${{ secrets.CF_ACCOUNT_ID }}
projectName: ${{ env.PAGES_PROJECT_NAME }}
directory: dist
gitHubToken: ${{ secrets.GITHUB_TOKEN }}

- name: Comment PR
uses: thollander/actions-comment-pull-request@v2
with:
message: |
id: ${{ steps.pages-action.outputs.id }}
url: ${{ steps.pages-action.outputs.url }}
alias: ${{ steps.pages-action.outputs.alias }}
environment: ${{ steps.pages-action.outputs.environment }}
comment_tag: deployment
mode: upsert
- name: Deploy preview to Cloudflare
uses: cloudflare/pages-action@1
id: pages-action
with:
apiToken: ${{ secrets.CI_CF_PAGES }}
accountId: ${{ secrets.CF_ACCOUNT_ID }}
projectName: ${{ env.PAGES_PROJECT_NAME }}
directory: dist
gitHubToken: ${{ secrets.GITHUB_TOKEN }}

- name: Comment PR
uses: thollander/actions-comment-pull-request@v2
with:
message: |
id: ${{ steps.pages-action.outputs.id }}
url: ${{ steps.pages-action.outputs.url }}
alias: ${{ steps.pages-action.outputs.alias }}
environment: ${{ steps.pages-action.outputs.environment }}
comment_tag: deployment
mode: upsert
Or—I see, right now I'm not creating a branch preview URL, am I. Hence why alias is just the URL For anyone who finds this via search, it looks like there are a number of issues with cloudflare/pages-action that prevent this from working, as noted in the issues for the repo: a) one needs to manually set the deployment branch to ${{ github.head_ref || github.ref_name }} even though the documentation suggests you don't, and b) even if you do, outputs.alias doesn't work. The wrangler action is way more updated (supports pnpm, for one), and you can use command: pages deploy with it, but it doesn't output the branch URL (or make a github deployment?) either. For now I just faked the whole thing:
- name: Deploy preview to Cloudflare
uses: cloudflare/pages-action@1
id: pages-action
with:
apiToken: ${{ secrets.CI_CF_PAGES }}
accountId: ${{ secrets.CF_ACCOUNT_ID }}
projectName: ${{ env.PAGES_PROJECT_NAME }}
directory: dist
branch: ${{ github.head_ref || github.ref_name }}
gitHubToken: ${{ secrets.GITHUB_TOKEN }}

- name: Comment PR
uses: thollander/actions-comment-pull-request@v2
with:
message: |
Deployed ${{ steps.pages-action.outputs.environment }} build to Cloudflare!

| | |
| ----------------------- | - |
| **Last commit:** | ${{ github.event.pull_request.head.sha || github.event.workflow_run.head_sha || github.sha }} |
| **Preview URL**: | ${{ steps.pages-action.outputs.url }} |
| **Branch Preview URL**: | https://${{ github.head_ref || github.ref_name }}.${{ env.PAGES_PROJECT_NAME }}.pages.dev |
comment_tag: deployment
mode: upsert
- name: Deploy preview to Cloudflare
uses: cloudflare/pages-action@1
id: pages-action
with:
apiToken: ${{ secrets.CI_CF_PAGES }}
accountId: ${{ secrets.CF_ACCOUNT_ID }}
projectName: ${{ env.PAGES_PROJECT_NAME }}
directory: dist
branch: ${{ github.head_ref || github.ref_name }}
gitHubToken: ${{ secrets.GITHUB_TOKEN }}

- name: Comment PR
uses: thollander/actions-comment-pull-request@v2
with:
message: |
Deployed ${{ steps.pages-action.outputs.environment }} build to Cloudflare!

| | |
| ----------------------- | - |
| **Last commit:** | ${{ github.event.pull_request.head.sha || github.event.workflow_run.head_sha || github.sha }} |
| **Preview URL**: | ${{ steps.pages-action.outputs.url }} |
| **Branch Preview URL**: | https://${{ github.head_ref || github.ref_name }}.${{ env.PAGES_PROJECT_NAME }}.pages.dev |
comment_tag: deployment
mode: upsert
Want results from more Discord servers?
Add your server