1212permissions :
1313 contents : read
1414 packages : read
15- pull-requests : read
1615
1716jobs :
1817 identity :
5756 contents : read
5857 deployments : write
5958 packages : read
60- pull-requests : read
6159 runs-on : ubuntu-latest
6260 timeout-minutes : 25
6361 environment : preview
@@ -123,61 +121,6 @@ jobs:
123121 cp -R .preview-registry/. apps/client-web/dist/
124122 cp -R apps/client-web/dist "$GITHUB_WORKSPACE/.pages-preview"
125123
126- - name : Reverify pull-request identity before delivery
127- uses : actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
128- env :
129- PREVIEW_BRANCH : ${{ needs.identity.outputs.branch }}
130- PREVIEW_HEAD_SHA : ${{ needs.identity.outputs.head_sha }}
131- PULL_NUMBER : ${{ needs.identity.outputs.pull_number }}
132- with :
133- script : |
134- const expectedBranch = `preview/client-web/pr-${process.env.PULL_NUMBER}`
135- if (process.env.PREVIEW_BRANCH !== expectedBranch) {
136- core.setFailed(`Unexpected Pages preview branch: ${process.env.PREVIEW_BRANCH}`)
137- return
138- }
139- const { data: pull } = await github.rest.pulls.get({
140- owner: context.repo.owner,
141- repo: context.repo.repo,
142- pull_number: Number(process.env.PULL_NUMBER),
143- })
144- if (
145- pull.state !== 'open' ||
146- pull.base.ref !== 'main' ||
147- pull.head.sha !== process.env.PREVIEW_HEAD_SHA ||
148- pull.head.repo?.full_name !== `${context.repo.owner}/${context.repo.repo}`
149- ) {
150- core.setFailed('Pull-request identity changed after the exact-head build.')
151- }
152-
153- - name : Register the pull-request deployment
154- id : github-deployment
155- uses : actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
156- env :
157- PREVIEW_HEAD_SHA : ${{ needs.identity.outputs.head_sha }}
158- PULL_NUMBER : ${{ needs.identity.outputs.pull_number }}
159- with :
160- script : |
161- const { data: deployment } = await github.rest.repos.createDeployment({
162- owner: context.repo.owner,
163- repo: context.repo.repo,
164- ref: process.env.PREVIEW_HEAD_SHA,
165- environment: 'preview',
166- description: `Cloudflare Pages preview for PR #${process.env.PULL_NUMBER}`,
167- auto_merge: false,
168- required_contexts: [],
169- transient_environment: true,
170- production_environment: false,
171- })
172- core.setOutput('deployment_id', String(deployment.id))
173- await github.rest.repos.createDeploymentStatus({
174- owner: context.repo.owner,
175- repo: context.repo.repo,
176- deployment_id: deployment.id,
177- state: 'in_progress',
178- log_url: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
179- })
180-
181124 - name : Deploy to the isolated Pages preview branch
182125 id : pages
183126 uses : cloudflare/wrangler-action@ebbaa1584979971c8614a24965b4405ff95890e0 # v4.0.0
@@ -193,25 +136,3 @@ jobs:
193136 --branch=${{ needs.identity.outputs.branch }}
194137 --commit-hash=${{ needs.identity.outputs.head_sha }}
195138 --commit-dirty=false
196-
197- - name : Report the pull-request deployment
198- if : ${{ always() && steps.github-deployment.outputs.deployment_id != '' }}
199- uses : actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
200- env :
201- DEPLOYMENT_ID : ${{ steps.github-deployment.outputs.deployment_id }}
202- JOB_STATUS : ${{ job.status }}
203- PREVIEW_URL : ${{ steps.pages.outputs.pages-deployment-alias-url }}
204- with :
205- script : |
206- const success = process.env.JOB_STATUS === 'success'
207- await github.rest.repos.createDeploymentStatus({
208- owner: context.repo.owner,
209- repo: context.repo.repo,
210- deployment_id: Number(process.env.DEPLOYMENT_ID),
211- state: success ? 'success' : 'failure',
212- description: success ? 'Pull-request preview is ready' : 'Pull-request preview failed',
213- log_url: `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
214- ...(success && process.env.PREVIEW_URL
215- ? { environment_url: process.env.PREVIEW_URL }
216- : {}),
217- })
0 commit comments