-
Notifications
You must be signed in to change notification settings - Fork 1
141 lines (129 loc) · 4.95 KB
/
pr-preview.yml
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#################### 🚧 WARNING: READ THIS BEFORE USING THIS FILE 🚧 ####################
#
#
#
# IF YOU DON'T KNOW WHAT YOU'RE DOING, YOU CAN EASILY LEAK SECRETS BY USING A
# `pull_request_target` WORKFLOW INSTEAD OF `pull_request`! SERIOUSLY, DO NOT
# BLINDLY COPY AND PASTE THIS FILE WITHOUT UNDERSTANDING THE FULL IMPLICATIONS
# OF WHAT YOU'RE DOING! WE HAVE TESTED THIS FOR OUR OWN USE CASES, WHICH ARE
# NOT NECESSARILY THE SAME AS YOURS! WHILE WE AREN'T EXPOSING ANY OF OUR SECRETS,
# ONE COULD EASILY DO SO BY MODIFYING OR ADDING A STEP TO THIS WORKFLOW!
#
#
#
#################### 🚧 WARNING: READ THIS BEFORE USING THIS FILE 🚧 ####################
name: Preview Deployment
on:
pull_request_target:
types:
- opened
- synchronize
- closed
# cancel in-progress runs on new commits to same PR (github.event.number)
concurrency:
group: ${{ github.workflow }}-${{ github.event.number || github.sha }}
cancel-in-progress: true
jobs:
deploy-preview:
if: ${{ github.event.action != 'closed' }}
permissions:
contents: read
pull-requests: write
deployments: write
runs-on: ubuntu-latest
name: Deploy Preview to Cloudflare Pages
env:
BRANCH_NAME: preview-${{ github.head_ref }}
ACTION_RUN: ${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}}
steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
- name: Create comment
id: comment
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body: |
## ⚡ Cloudflare Pages Deployment
| Name | Status | Preview |
| :--- | :----- | :------ |
| ${{env.BRANCH_NAME}} | 🔨 Building ([Logs](${{env.ACTION_RUN}})) | waiting... |
- uses: pnpm/action-setup@v4
with:
version: 9
- name: Build
# env:
# COLLABORATORS_API_TOKEN: ${{ secrets.COLLABORATORS_API_TOKEN }}
run: |
pnpm install --frozen
pnpm run build
- name: Deploy
id: deploy
uses: cloudflare/wrangler-action@v3
env:
AUTH_GITHUB_ID: ${{ secrets.AUTH_GITHUB_ID }}
AUTH_GITHUB_SECRET: ${{ secrets.AUTH_GITHUB_SECRET }}
AUTH_SECRET: ${{ secrets.AUTH_SECRET }}
AUTH_TRUST_HOST: ${{ secrets.AUTH_TRUST_HOST }}
ADMINS: ${{ secrets.ADMINS }}
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
wranglerVersion: '3.67.0'
command: pages deploy ./dist --project-name=dashboard --branch="${{ env.BRANCH_NAME }}"
secrets: |
ADMINS
AUTH_GITHUB_ID
AUTH_GITHUB_SECRET
AUTH_SECRET
AUTH_TRUST_HOST
- name: Extract hash from CF url Deploy
run: |
url_hash=$(echo "${{ steps.deploy.outputs.deployment-url }}" | sed -n 's|https://\([^.]*\).dashboard.*|\1|p')
echo "SHA_SHORT=$url_hash" >> $GITHUB_ENV
- name: Create comment
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.pull_request.number }}
comment-id: ${{ steps.comment.outputs.comment-id }}
edit-mode: replace
body: |
## ⚡ Cloudflare Pages Deployment
| Name | Status | Preview |
| :--- | :----- | :------ |
| ${{env.BRANCH_NAME}} | ✅ Ready ([Logs](${{env.ACTION_RUN}})) | [${{env.SHA_SHORT}}](${{ steps.deploy.outputs.deployment-url }}) |
# remove-preview:
# if: ${{ github.event.action == "closed" }}
# permissions:
# contents: read
# pull-requests: write
# deployments: write
# runs-on: ubuntu-latest
# name: Remove Preview of Cloudflare Pages
# steps:
# - uses: actions/checkout@v3
# with:
# submodules: "recursive"
# ref: ${{ github.event.pull_request.head.ref }}
# repository: ${{ github.event.pull_request.head.repo.full_name }}
# - name: Deploy
# id: deploy
# uses: cloudflare/wrangler-action@v3
# with:
# apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
# accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
# command: pages --project-name=homepage --branch="${ env.BRANCH_NAME }"
# - name: Create comment
# uses: peter-evans/create-or-update-comment@v4
# with:
# issue-number: ${{ github.event.pull_request.number }}
# comment-author: 'github-actions[bot]'
# body: |
# ## ⚡ Removing Cloudflare Pages Preview
# | Name | Status |
# | :--- | :----- |
# | ${{env.BRANCH_NAME}} | ✅ Removed |