Repository navigation
213 lines (199 loc) · 8.85 KB
/
Copy paththeme-release.yml
File metadata and controls
213 lines (199 loc) · 8.85 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
name: Theme Release
on:
workflow_dispatch:
inputs:
operation:
description: Publish a new version or recover a missing source tag
required: true
default: publish
type: choice
options:
- publish
- recover-tag
version:
description: Exact @aeei/docusaurus-theme version from package.json
required: true
type: string
confirmation:
description: Type the operation-specific confirmation shown in UPSTREAM.md
required: true
type: string
source_sha:
description: Original 40-character source commit for retry or recover-tag
required: false
type: string
permissions: {}
concurrency:
group: theme-release
cancel-in-progress: false
jobs:
prepare:
name: Build immutable theme artifact
if: ${{ github.repository == 'aeei/docusaurus-theme' && github.ref == 'refs/heads/main' }}
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
contents: read
outputs:
file: ${{ steps.package.outputs.file }}
integrity: ${{ steps.package.outputs.integrity }}
version: ${{ steps.intent.outputs.version }}
source_sha: ${{ steps.intent.outputs.source_sha }}
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
fetch-depth: 0
ref: ${{ inputs.source_sha || github.sha }}
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: 24.18.0
cache: yarn
- run: npm install --global npm@11.16.0
- name: Validate explicit release intent
id: intent
env:
OPERATION: ${{ inputs.operation }}
VERSION: ${{ inputs.version }}
CONFIRMATION: ${{ inputs.confirmation }}
INPUT_SOURCE_SHA: ${{ inputs.source_sha }}
run: |
actual=$(node -p "require('./packages/docusaurus-theme/package.json').version")
test "$actual" = "$VERSION"
case "$OPERATION" in
publish)
expected="publish @aeei/docusaurus-theme@${VERSION}"
source_sha="${INPUT_SOURCE_SHA:-$GITHUB_SHA}"
printf '%s' "$source_sha" | grep -Eq '^[0-9a-f]{40}$'
git fetch origin main --no-tags
git merge-base --is-ancestor "$source_sha" origin/main
test "$(git rev-parse HEAD)" = "$source_sha"
;;
recover-tag)
expected="recover theme-v${VERSION} for @aeei/docusaurus-theme@${VERSION}"
printf '%s' "$INPUT_SOURCE_SHA" | grep -Eq '^[0-9a-f]{40}$'
source_sha="$INPUT_SOURCE_SHA"
git fetch origin main --no-tags
git merge-base --is-ancestor "$source_sha" origin/main
test "$(git rev-parse HEAD)" = "$source_sha"
;;
*) echo "Unsupported operation: $OPERATION" >&2; exit 1 ;;
esac
test "$CONFIRMATION" = "$expected"
tag_ref=$(git ls-remote --tags origin "refs/tags/theme-v${VERSION}" | awk '{print $1}')
tag_commit=$(git ls-remote --tags origin "refs/tags/theme-v${VERSION}^{}" | awk '{print $1}')
if [ -n "$tag_ref" ]; then
test -n "$tag_commit"
test "$tag_commit" = "$source_sha"
fi
published=$(npm view "@aeei/docusaurus-theme@${VERSION}" dist.integrity 2>/dev/null || true)
if [ "$OPERATION" = publish ]; then
test -z "$published"
else
test -n "$published"
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "source_sha=$source_sha" >> "$GITHUB_OUTPUT"
- run: yarn install --frozen-lockfile --ignore-scripts
- run: yarn workspace @aeei/docusaurus-theme build
- name: Theme release contracts
run: >-
NODE_OPTIONS=--experimental-vm-modules yarn jest
packages/docusaurus-theme/src/package-contract.test.ts
packages/docusaurus-theme/src/legal-notices.test.ts
examples/docs-starter/config-contract.test.ts
--runInBand
- run: yarn workspace @aeei/docs-starter build
- name: Pack immutable artifact
id: package
working-directory: packages/docusaurus-theme
env:
VERSION: ${{ inputs.version }}
run: |
npm pack --json > /tmp/aeei-theme-pack.json
file=$(node -p "JSON.parse(require('fs').readFileSync('/tmp/aeei-theme-pack.json','utf8'))[0].filename")
packed_name=$(tar -xOzf "$file" package/package.json | node -e "let s=''; process.stdin.on('data',d=>s+=d).on('end',()=>process.stdout.write(JSON.parse(s).name))")
packed_version=$(tar -xOzf "$file" package/package.json | node -e "let s=''; process.stdin.on('data',d=>s+=d).on('end',()=>process.stdout.write(JSON.parse(s).version))")
test "$packed_name" = "@aeei/docusaurus-theme"
test "$packed_version" = "$VERSION"
mv "$file" "$GITHUB_WORKSPACE/$file"
integrity=$(node -e "const fs=require('fs'),crypto=require('crypto'); const bytes=fs.readFileSync(process.argv[1]); process.stdout.write('sha512-'+crypto.createHash('sha512').update(bytes).digest('base64'))" "$GITHUB_WORKSPACE/$file")
echo "file=$file" >> "$GITHUB_OUTPUT"
echo "integrity=$integrity" >> "$GITHUB_OUTPUT"
printf '%s %s\n' "$integrity" "$file"
- name: Verify recovery artifact
if: ${{ inputs.operation == 'recover-tag' }}
env:
VERSION: ${{ inputs.version }}
INTEGRITY: ${{ steps.package.outputs.integrity }}
run: test "$(npm view "@aeei/docusaurus-theme@${VERSION}" dist.integrity)" = "$INTEGRITY"
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: aeei-docusaurus-theme-${{ inputs.version }}
path: ${{ steps.package.outputs.file }}
if-no-files-found: error
retention-days: 7
release:
name: Publish and tag approved artifact
needs: prepare
runs-on: ubuntu-latest
timeout-minutes: 10
environment: theme-release
permissions:
contents: write
id-token: write
steps:
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: 24.18.0
registry-url: https://registry.npmjs.org
- run: npm install --global npm@11.16.0
- uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: aeei-docusaurus-theme-${{ needs.prepare.outputs.version }}
- name: Verify downloaded artifact
env:
FILE: ${{ needs.prepare.outputs.file }}
INTEGRITY: ${{ needs.prepare.outputs.integrity }}
run: |
actual=$(node -e "const fs=require('fs'),crypto=require('crypto'); const bytes=fs.readFileSync(process.argv[1]); process.stdout.write('sha512-'+crypto.createHash('sha512').update(bytes).digest('base64'))" "$FILE")
test "$actual" = "$INTEGRITY"
- name: Reserve or verify immutable source tag
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ needs.prepare.outputs.version }}
REPOSITORY: ${{ github.repository }}
TARGET_SHA: ${{ needs.prepare.outputs.source_sha }}
run: |
if ref=$(gh api "repos/${REPOSITORY}/git/ref/tags/theme-v${VERSION}" 2>/dev/null); then
tag_object=$(printf '%s' "$ref" | node -e "let s=''; process.stdin.on('data',d=>s+=d).on('end',()=>process.stdout.write(JSON.parse(s).object.sha))")
existing_target=$(gh api "repos/${REPOSITORY}/git/tags/${tag_object}" --jq .object.sha)
test "$existing_target" = "$TARGET_SHA"
else
tag_object=$(gh api --method POST "repos/${REPOSITORY}/git/tags" \
-f tag="theme-v${VERSION}" \
-f message="@aeei/docusaurus-theme ${VERSION}" \
-f object="$TARGET_SHA" \
-f type=commit \
--jq .sha)
gh api --method POST "repos/${REPOSITORY}/git/refs" \
-f ref="refs/tags/theme-v${VERSION}" \
-f sha="$tag_object"
fi
- name: Publish theme through npm trusted publishing
if: ${{ inputs.operation == 'publish' }}
env:
FILE: ${{ needs.prepare.outputs.file }}
run: npm publish "$FILE" --access public
- name: Verify registry integrity
env:
VERSION: ${{ needs.prepare.outputs.version }}
INTEGRITY: ${{ needs.prepare.outputs.integrity }}
run: |
registry_integrity=""
for _ in $(seq 1 12); do
registry_integrity=$(npm view "@aeei/docusaurus-theme@${VERSION}" dist.integrity 2>/dev/null || true)
[ -n "$registry_integrity" ] && break
sleep 5
done
test "$registry_integrity" = "$INTEGRITY"