-
Notifications
You must be signed in to change notification settings - Fork 0
144 lines (131 loc) · 5.37 KB
/
Copy pathpages-preview.yml
File metadata and controls
144 lines (131 loc) · 5.37 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
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
142
143
144
name: Pages preview
on:
workflow_run:
workflows:
- Website checks
types:
- completed
permissions:
actions: read
contents: read
pull-requests: read
jobs:
identity:
name: Resolve trusted preview identity
if: >-
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.head_repository.full_name == github.repository
runs-on: ubuntu-latest
outputs:
branch: ${{ steps.identity.outputs.branch }}
head_sha: ${{ steps.identity.outputs.head_sha }}
pull_number: ${{ steps.identity.outputs.pull_number }}
steps:
- name: Resolve exact internal pull request
id: identity
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const runId = context.payload.workflow_run.id
const { data: run } = await github.rest.actions.getWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: runId,
})
if (run.name !== 'Website checks' || run.path !== '.github/workflows/website-check.yml') {
core.setFailed('Preview must be orchestrated by the trusted Website checks workflow.')
return
}
if (run.conclusion !== 'success' || run.event !== 'pull_request') {
core.setFailed('Preview delivery requires a successful pull-request check run.')
return
}
if (run.head_repository?.full_name !== `${context.repo.owner}/${context.repo.repo}`) {
core.setFailed('Fork pull requests are not eligible for preview credentials.')
return
}
const pulls = await github.rest.repos.listPullRequestsAssociatedWithCommit({
owner: context.repo.owner,
repo: context.repo.repo,
commit_sha: run.head_sha,
})
const pull = pulls.data.find((candidate) =>
candidate.state === 'open' &&
candidate.base.ref === 'main' &&
candidate.head.sha === run.head_sha &&
candidate.head.repo?.full_name === `${context.repo.owner}/${context.repo.repo}`
)
if (!pull) {
core.setFailed('Run is not the exact head of an eligible internal pull request.')
return
}
core.setOutput('branch', `preview/docs/pr-${pull.number}`)
core.setOutput('head_sha', run.head_sha)
core.setOutput('pull_number', String(pull.number))
deploy:
name: Deploy isolated pull-request preview
needs: identity
concurrency:
group: pages-preview-docs-${{ needs.identity.outputs.pull_number }}
cancel-in-progress: true
permissions:
contents: read
deployments: write
runs-on: ubuntu-latest
timeout-minutes: 15
environment:
name: preview
url: ${{ steps.pages.outputs.pages-deployment-alias-url }}
steps:
- name: Checkout the trusted preview controller
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.workflow_sha }}
path: controller
persist-credentials: false
- name: Checkout the exact pull-request head
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ needs.identity.outputs.head_sha }}
path: candidate
persist-credentials: false
- name: Install the pinned pnpm release
uses: pnpm/action-setup@0977fd99725f1db4007ccb2928dbb4e90d06cc86 # v6.0.10
with:
package_json_file: candidate/website/package.json
- name: Set up Node
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version-file: candidate/website/package.json
cache: pnpm
cache-dependency-path: candidate/website/pnpm-lock.yaml
- name: Build the exact-head website preview
run: |
pnpm --dir candidate/website install --frozen-lockfile
pnpm --dir candidate/website check
- name: Prepare the isolated Pages delivery
run: |
mkdir --parents .pages-preview
cp --recursive candidate/website/.vitepress/dist .pages-preview/dist
- name: Deploy to the isolated Pages preview branch
id: pages
uses: cloudflare/wrangler-action@ebbaa1584979971c8614a24965b4405ff95890e0 # v4.0.0
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
packageManager: npm
wranglerVersion: 4.114.0
workingDirectory: .pages-preview
command: >-
pages deploy dist
--project-name=${{ vars.CLOUDFLARE_PAGES_PROJECT }}
--branch=${{ needs.identity.outputs.branch }}
--commit-hash=${{ needs.identity.outputs.head_sha }}
--commit-dirty=false
- name: Smoke-test the exact preview deployment
run: node controller/website/scripts/verify-pages-deployment.mjs
env:
CLOUDFLARE_PAGES_DEPLOYMENT_ID: ${{ steps.pages.outputs.pages-deployment-id }}
CLOUDFLARE_PAGES_DEPLOYMENT_URL: ${{ steps.pages.outputs.pages-deployment-alias-url }}
INKCRE_PAGES_SMOKE_MODE: preview