Repository navigation
219 lines (189 loc) · 8.14 KB
/
Copy pathbuild-deploy.yml
File metadata and controls
219 lines (189 loc) · 8.14 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
name: Build & Deploy
on:
push:
branches: ['**']
pull_request:
types: [opened, synchronize, reopened]
workflow_dispatch:
permissions:
contents: read
concurrency:
group: pages
cancel-in-progress: false
jobs:
build:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Setup Node
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: '22'
- name: Build platform data
run: node docs/build.js
- name: Check catalog and lesson starters
run: |
node --test scripts/test-catalog-grouping.js modules/ghaw/resources/examples/*.test.cjs modules/ghec/resources/integration/handler.test.cjs
PYTHONDONTWRITEBYTECODE=1 python3 -m unittest discover -s modules/ghec/resources/drift -p 'test_*.py'
PYTHONDONTWRITEBYTECODE=1 python3 -S modules/ghec/resources/release/test_release.py -v
PYTHONDONTWRITEBYTECODE=1 python3 -S modules/ghec/resources/ci/test_workflows.py -v
PYTHONDONTWRITEBYTECODE=1 python3 -S modules/ghec/resources/intake/test_provision.py -v
npm run test:setup-plugin
- name: Restore branch previews
run: |
preview_ref="$(git ls-remote --heads origin refs/heads/gh-pages)"
if [ -n "${preview_ref}" ]; then
git fetch --no-tags origin gh-pages
if [ -n "$(git ls-tree FETCH_HEAD previews)" ]; then
git archive FETCH_HEAD previews | tar -x -C docs
fi
fi
- name: Configure GitHub Pages
uses: actions/configure-pages@45bfe0192ca1faeb007ade9deae92b16b8254a0d # v6.0.0
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9 # v5.0.0
with:
path: docs/
deploy:
needs: build
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-24.04
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@368f82528645a54fb793d4d04e342629a3f51346 # v5.0.1
build-preview:
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-24.04
permissions:
contents: write
outputs:
preview_path: ${{ steps.preview_path.outputs.value }}
steps:
- name: Checkout production source
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: main
path: production
- name: Checkout branch source
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.event.pull_request.head.sha || github.sha }}
path: preview
- name: Checkout preview state
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: main
path: preview-state
- name: Load or initialize preview state
working-directory: preview-state
run: |
preview_ref="$(git ls-remote --heads origin refs/heads/gh-pages)"
if [ -n "${preview_ref}" ]; then
git fetch --no-tags origin gh-pages
git checkout -B gh-pages FETCH_HEAD
else
git checkout --orphan gh-pages
git rm -rf -- .
fi
- name: Setup Node
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: '22'
- name: Build production site
run: node docs/build.js
working-directory: production
- name: Build branch preview
run: node docs/build.js
working-directory: preview
- name: Check preview catalog and lesson starters
working-directory: preview
run: |
node --test scripts/test-catalog-grouping.js modules/ghaw/resources/examples/*.test.cjs modules/ghec/resources/integration/handler.test.cjs
PYTHONDONTWRITEBYTECODE=1 python3 -m unittest discover -s modules/ghec/resources/drift -p 'test_*.py'
PYTHONDONTWRITEBYTECODE=1 python3 -S modules/ghec/resources/release/test_release.py -v
PYTHONDONTWRITEBYTECODE=1 python3 -S modules/ghec/resources/ci/test_workflows.py -v
PYTHONDONTWRITEBYTECODE=1 python3 -S modules/ghec/resources/intake/test_provision.py -v
npm run test:setup-plugin
- name: Set preview path
id: preview_path
env:
PREVIEW_NAME: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.pull_request.number) || github.ref_name }}
run: |
slug="$(printf '%s' "${PREVIEW_NAME}" | tr '[:upper:]' '[:lower:]' | sed -E 's/[^a-z0-9]+/-/g; s/^-+|-+$//g')"
suffix="$(printf '%s' "${PREVIEW_NAME}" | sha256sum | cut -c1-10)"
echo "value=previews/${slug:-branch}-${suffix}" >> "${GITHUB_OUTPUT}"
- name: Update preview state
env:
PREVIEW_PATH: ${{ steps.preview_path.outputs.value }}
run: |
rm -rf "preview-state/${PREVIEW_PATH}"
mkdir -p "preview-state/${PREVIEW_PATH}"
cp -a preview/docs/. "preview-state/${PREVIEW_PATH}/"
git -C preview-state config user.name "github-actions[bot]"
git -C preview-state config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git -C preview-state add -- "${PREVIEW_PATH}"
if ! git -C preview-state diff --cached --quiet; then
git -C preview-state commit -m "Update preview for ${PREVIEW_PATH}"
git -C preview-state push origin HEAD:gh-pages
fi
- name: Assemble production site and previews
run: |
mkdir site
cp -a production/docs/. site/
mkdir -p site/previews
cp -a preview-state/previews/. site/previews/
- name: Configure GitHub Pages
uses: actions/configure-pages@45bfe0192ca1faeb007ade9deae92b16b8254a0d # v6.0.0
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9 # v5.0.0
with:
path: site/
deploy-preview:
needs: build-preview
runs-on: ubuntu-24.04
permissions:
pages: write
id-token: write
pull-requests: write
environment:
name: github-pages
url: "${{ steps.deployment.outputs.page_url }}${{ needs.build-preview.outputs.preview_path }}/"
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@368f82528645a54fb793d4d04e342629a3f51346 # v5.0.1
- name: Add preview URL to workflow summary
env:
PREVIEW_PATH: ${{ needs.build-preview.outputs.preview_path }}
SITE_URL: ${{ steps.deployment.outputs.page_url }}
run: |
echo "Preview: ${SITE_URL}${PREVIEW_PATH}/" >> "${GITHUB_STEP_SUMMARY}"
- name: Comment preview URL
if: github.event_name == 'pull_request'
env:
GH_TOKEN: ${{ github.token }}
PREVIEW_PATH: ${{ needs.build-preview.outputs.preview_path }}
PR_NUMBER: ${{ github.event.pull_request.number }}
SITE_URL: ${{ steps.deployment.outputs.page_url }}
PREVIEW_SHA: ${{ github.event.pull_request.head.sha }}
run: |
MARKER="<!-- pages-preview-url -->"
PREVIEW_URL="${SITE_URL}${PREVIEW_PATH}/"
BODY="${MARKER}
Preview: ${PREVIEW_URL}
Updated for commit ${PREVIEW_SHA}."
COMMENT_ID="$(gh api --paginate "repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments" --jq ".[] | select(.user.login == \"github-actions[bot]\" and (.body | contains(\"${MARKER}\"))) | .id" | tail -n 1)"
if [ -n "${COMMENT_ID}" ]; then
gh api --method PATCH "repos/${GITHUB_REPOSITORY}/issues/comments/${COMMENT_ID}" -f body="${BODY}"
else
gh api --method POST "repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments" -f body="${BODY}"
fi