Skip to content

2 - Deploy Web Page PR #13

2 - Deploy Web Page PR

2 - Deploy Web Page PR #13

Workflow file for this run

# .github/workflows/deploy-pr.yml
name: 2 - Deploy Web Page PR
on:
workflow_run:
workflows: ["1 - Check and Build Web Page PR"]
types: [completed]
# CRITICAL: Grant the workflow permission to write comments on PRs
permissions:
pull-requests: write
jobs:
deploy-preview:
if: github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
environment: Cloudflare Pages
permissions:
# actions: read # Only required for private GitHub Repo
contents: read
deployments: write
pull-requests: write
steps:
- name: Download Site Artifact
uses: actions/download-artifact@v4
with:
name: preview-site
path: site/
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
# NEW: Download the PR metadata artifact
- name: Download PR Number Artifact
uses: actions/download-artifact@v4
with:
name: pr-metadata
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Set PR Number Context
run: |
PR_NUMBER=$(cat pr-number.txt)
# This syntax makes it available to subsequent steps as ${{ env.PR_NUMBER }}
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
- name: Deploy
id: deploy
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: |
pages deploy site/ --project-name=openshift-examples --branch pr-${{ env.PR_NUMBER }}
# Optional: Enable this if you want to have GitHub Deployments triggered
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
- name: Comment on PR
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CMD_OUTPUT: ${{ steps.deploy.outputs.command-output }}
DEPLOYMENT_URL: ${{ steps.deploy.outputs.deployment-url }}
run: |
gh pr comment ${{ env.PR_NUMBER }} \
--repo ${{ github.repository }} \
--body "πŸš€ **Preview Deployment Success!** View your live changes here: $DEPLOYMENT_URL\n\n$CMD_OUTPUT"