-
Notifications
You must be signed in to change notification settings - Fork 97
66 lines (58 loc) · 2.2 KB
/
deploy-pr.yaml
File metadata and controls
66 lines (58 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# .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"