-
Notifications
You must be signed in to change notification settings - Fork 97
79 lines (70 loc) · 2.78 KB
/
deploy-pr.yaml
File metadata and controls
79 lines (70 loc) · 2.78 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
67
68
69
70
71
72
73
74
75
76
77
78
79
# .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 to Cloudflare Pages
uses: andykenward/github-actions-cloudflare-pages@v3.5.0
id: pages
with:
cloudflare-api-token: ${{ secrets.CLOUDFLARE_API_TOKEN }}
cloudflare-account-id: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
cloudflare-project-name: ${{ vars.CLOUDFLARE_PROJECT_NAME }}
directory: site
github-token: ${{ secrets.GITHUB_TOKEN }}
github-environment: Cloudflare Pages
pr-number: ${{ env.PR_NUMBER }}
branch: pr-${{ env.PR_NUMBER }}
# - 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"