Repository navigation
212 lines (187 loc) · 8.24 KB
/
Copy pathdocs-deploy.yml
File metadata and controls
212 lines (187 loc) · 8.24 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
name: Docs Deploy
on:
pull_request:
paths:
- "apps/docs/**"
- "!apps/docs/zh/guide/bibo.md"
- "!apps/docs/en/guide/bibo.md"
- "scripts/deploy/docs/**"
- "infra/docs-delivery/**"
- ".github/workflows/docs-deploy.yml"
- "package.json"
- "pnpm-lock.yaml"
push:
branches: [master]
paths:
# Bibo is delivered independently; its legacy guide does not trigger this site.
- "apps/docs/**"
- "!apps/docs/zh/guide/bibo.md"
- "!apps/docs/en/guide/bibo.md"
- "scripts/deploy/docs/**"
- "infra/docs-delivery/**"
- "package.json"
- "pnpm-lock.yaml"
workflow_dispatch:
permissions:
contents: read
concurrency:
group: docs-production
cancel-in-progress: false
env:
ARTIFACT_NAME: nextclaw-docs-${{ github.sha }}-${{ github.run_id }}
RELEASE_COMMIT: ${{ github.sha }}
jobs:
build:
runs-on: ubuntu-latest
outputs:
tree_sha256: ${{ steps.manifest.outputs.tree_sha256 }}
steps:
- name: Checkout
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Setup Node
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version-file: .nvmrc
- name: Setup pnpm
uses: pnpm/action-setup@0ebf47130e4866e96fce0953f49152a61190b271 # v6.0.9
with:
version: 9.15.1
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Validate localized documentation
run: pnpm docs:i18n:check
- name: Build documentation once
run: pnpm metrics:loc && pnpm --filter @nextclaw/docs build
- name: Create immutable release manifest
id: manifest
env:
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
node scripts/deploy/docs/create-docs-release-manifest.mjs \
--dist apps/docs/.vitepress/dist \
--commit "$RELEASE_COMMIT" \
--run-url "$RUN_URL"
echo "tree_sha256=$(jq -r .treeSha256 apps/docs/.vitepress/dist/release-manifest.json)" >> "$GITHUB_OUTPUT"
echo "Release identity: $RELEASE_COMMIT/$(jq -r .treeSha256 apps/docs/.vitepress/dist/release-manifest.json)" >> "$GITHUB_STEP_SUMMARY"
- name: Upload documentation artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: ${{ env.ARTIFACT_NAME }}
path: apps/docs/.vitepress/dist
if-no-files-found: error
retention-days: 90
deploy-global:
needs: build
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
environment: production
steps:
- name: Download documentation artifact
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: ${{ env.ARTIFACT_NAME }}
path: docs-dist
- name: Deploy immutable artifact to Cloudflare Pages
uses: cloudflare/wrangler-action@ebbaa1584979971c8614a24965b4405ff95890e0 # v4.0.0
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
wranglerVersion: "4.67.0"
command: >-
pages deploy docs-dist
--project-name=nextclaw-docs
--branch=master
--commit-hash=${{ env.RELEASE_COMMIT }}
deploy-domestic:
needs: build
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
environment: docs-cn-production
permissions:
contents: read
id-token: write
steps:
- name: Checkout infrastructure contract
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Download documentation artifact
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: ${{ env.ARTIFACT_NAME }}
path: docs-dist
- name: Install pinned cloud CLIs
run: |
mkdir -p "$RUNNER_TEMP/bin"
echo "$RUNNER_TEMP/bin" >> "$GITHUB_PATH"
curl -fsSLo "$RUNNER_TEMP/ossutil.zip" \
https://gosspublic.alicdn.com/ossutil/v2/2.3.0/ossutil-2.3.0-linux-amd64.zip
echo "3ae4d9fc85a7a6e9f5654d1599766f1a3a42a3692870887b5ae9338d582ef65a $RUNNER_TEMP/ossutil.zip" | sha256sum -c -
unzip -q "$RUNNER_TEMP/ossutil.zip" -d "$RUNNER_TEMP"
install -m 0755 "$RUNNER_TEMP/ossutil-2.3.0-linux-amd64/ossutil" "$RUNNER_TEMP/bin/ossutil"
- name: Setup Alibaba Cloud CLI
uses: aliyun/setup-aliyun-cli-action@09a5f86915bb556e27bf050e9a5e339aeb073df5
with:
version: "3.4.6"
- name: Exchange GitHub identity for archive upload credentials
uses: aliyun/configure-aliyun-credentials-action@1e5248c8d5d93a8781ac344a68e19a43341e79e6
with:
audience: sts.aliyuncs.com
oidc-provider-arn: ${{ vars.ALIYUN_DOCS_OIDC_PROVIDER_ARN }}
role-to-assume: ${{ vars.ALIYUN_DOCS_ROLE_ARN }}
role-session-expiration: 3600
role-session-name: docs-${{ github.run_id }}-${{ github.run_attempt }}-archive
- name: Archive the same artifact in private OSS
env:
BUCKET: ${{ vars.ALIYUN_DOCS_BUCKET }}
REGION: ${{ vars.ALIYUN_DOCS_REGION }}
RELEASE_TREE: ${{ needs.build.outputs.tree_sha256 }}
run: |
export OSS_ACCESS_KEY_ID="$ALIBABA_CLOUD_ACCESS_KEY_ID"
export OSS_ACCESS_KEY_SECRET="$ALIBABA_CLOUD_ACCESS_KEY_SECRET"
export OSS_SESSION_TOKEN="$ALIBABA_CLOUD_SECURITY_TOKEN"
export OSS_REGION="$REGION"
ossutil sync docs-dist "oss://$BUCKET/_releases/$RELEASE_COMMIT/$RELEASE_TREE/" --region "$REGION" --mode StsToken --force
- name: Renew Alibaba credentials for site publication
uses: aliyun/configure-aliyun-credentials-action@1e5248c8d5d93a8781ac344a68e19a43341e79e6
with:
audience: sts.aliyuncs.com
oidc-provider-arn: ${{ vars.ALIYUN_DOCS_OIDC_PROVIDER_ARN }}
role-to-assume: ${{ vars.ALIYUN_DOCS_ROLE_ARN }}
role-session-expiration: 3600
role-session-name: docs-${{ github.run_id }}-${{ github.run_attempt }}-site
- name: Publish the same artifact to the domestic site
env:
BUCKET: ${{ vars.ALIYUN_DOCS_BUCKET }}
REGION: ${{ vars.ALIYUN_DOCS_REGION }}
run: |
export OSS_ACCESS_KEY_ID="$ALIBABA_CLOUD_ACCESS_KEY_ID"
export OSS_ACCESS_KEY_SECRET="$ALIBABA_CLOUD_ACCESS_KEY_SECRET"
export OSS_SESSION_TOKEN="$ALIBABA_CLOUD_SECURITY_TOKEN"
export OSS_REGION="$REGION"
ossutil sync docs-dist "oss://$BUCKET/" --region "$REGION" --mode StsToken --force
ossutil set-props "oss://$BUCKET/release-manifest.json" --region "$REGION" --mode StsToken --metadata-directive replace --content-type application/json --cache-control no-store --force
ossutil api put-bucket-lifecycle \
--bucket "$BUCKET" \
--region "$REGION" \
--mode StsToken \
--lifecycle-configuration file://infra/docs-delivery/lifecycle.config.json
- name: Refresh domestic CDN
env:
CDN_DOMAIN: ${{ vars.ALIYUN_DOCS_CDN_DOMAIN }}
REGION: ${{ vars.ALIYUN_DOCS_REGION }}
run: |
refresh_paths=$(node scripts/deploy/docs/create-cdn-refresh-paths.mjs --dist docs-dist --domain "$CDN_DOMAIN")
aliyun cdn RefreshObjectCaches --region "$REGION" --ObjectPath "$refresh_paths" --ObjectType File
verify:
needs: [build, deploy-global, deploy-domestic]
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
steps:
- name: Checkout verifier
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
- name: Verify both production domains report the same artifact
env:
NEXTCLAW_DOCS_CN_CNAME: ${{ vars.ALIYUN_DOCS_CDN_CNAME }}
run: >-
node scripts/deploy/docs/verify-docs-deployment.mjs
--expected-commit "${{ env.RELEASE_COMMIT }}"
--expected-tree "${{ needs.build.outputs.tree_sha256 }}"