Repository navigation
188 lines (173 loc) · 7.05 KB
/
Copy pathdocs-api-reference-deploy.yml
File metadata and controls
188 lines (173 loc) · 7.05 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
name: "Deploy API reference preview"
permissions:
actions: read
contents: read
pull-requests: write
# Deploys the artifact built by docs-api-reference.yml to
# <org>-<repo>-<pr-number>-api.surge.sh
#
# NOTE: workflow_run workflows only ever run from the version of this file on the
# default branch. Changes here have no effect on PR runs until they are merged to main.
on:
workflow_run:
workflows: ["Build API reference"]
types:
- completed
jobs:
deploy-api-reference:
name: Deploy API reference preview
# A failed build has no artifact to deploy, and a workflow_dispatch run has no PR to
# deploy for. The head_branch check is belt-and-braces: a dependabot run is already
# 'skipped' rather than 'success'.
if: |
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.event == 'pull_request' &&
!startsWith(github.event.workflow_run.head_branch, 'dependabot/')
runs-on: ubuntu-latest
steps:
- name: Patch eMudhra CA compromise (CVE-2026-111943)
shell: bash
working-directory: .
run: |
sudo apt-get update
sudo apt-get install --only-upgrade -y ca-certificates
sudo update-ca-certificates --fresh
- name: "Download built API reference"
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
RUN_ID: ${{ github.event.workflow_run.id }}
ARTIFACT_DIR: ${{ runner.temp }}/artifacts
with:
script: |
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: process.env.RUN_ID,
});
const match = artifacts.data.artifacts.find((a) => a.name === "api-reference");
if (!match) {
core.setFailed(`No "api-reference" artifact on run ${process.env.RUN_ID}`);
return;
}
const download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: match.id,
archive_format: 'zip',
});
const fs = require('fs');
fs.mkdirSync(process.env.ARTIFACT_DIR, { recursive: true });
fs.writeFileSync(
`${process.env.ARTIFACT_DIR}/api-reference.zip`,
Buffer.from(download.data),
);
# Check the entry names before unzipping, so a hostile archive cannot write
# outside the extraction directory in the first place.
- id: suspicious-path-check
name: Suspicious paths check
shell: bash
env:
ARTIFACT_DIR: ${{ runner.temp }}/artifacts
run: |
set -euo pipefail
cd "$ARTIFACT_DIR"
mapfile -t ZIP_ENTRIES < <(zipinfo -1 api-reference.zip)
if [ "${#ZIP_ENTRIES[@]}" -eq 0 ]; then
echo "api-reference.zip is empty"
exit 1
fi
for entry in "${ZIP_ENTRIES[@]}"; do
if [[ "$entry" =~ ^/ ]]; then
echo "Blocked absolute path in artifact: $entry"
exit 1
fi
if [[ "$entry" =~ (^|/)\.\.(/|$) ]]; then
echo "Blocked path traversal in artifact: $entry"
exit 1
fi
if [[ "$entry" == *\\* ]]; then
echo "Blocked Windows-style path separator in artifact: $entry"
exit 1
fi
done
- id: unzip
name: Unzip API reference artifact
env:
ARTIFACT_DIR: ${{ runner.temp }}/artifacts
run: |
cd "$ARTIFACT_DIR"
unzip -q api-reference.zip
if [ ! -d site ]; then
echo "Artifact has no site/ directory"
exit 1
fi
# surge uploads the content a symlink resolves to, so a symlink in the published
# tree is an exfiltration primitive - it would publish whatever the runner can
# read. Sphinx emits neither symlinks nor (after .buildinfo is dropped in the
# build job) dotfiles, so both are treated as tampering.
- id: content-check
name: Suspicious content check
env:
SITE_DIR: ${{ runner.temp }}/artifacts/site
run: |
set -euo pipefail
cd "$SITE_DIR"
if [ -n "$(find . -type l)" ]; then
echo "Security Alert: symlinks in the publish tree - refusing!"
find . -type l
exit 1
fi
if [ -n "$(find . -name '.*' ! -name .)" ]; then
echo "Security Alert: unexpected hidden files detected!"
find . -name '.*' ! -name .
exit 1
fi
# The PR number cannot be read from github.event.workflow_run.pull_requests -
# that array is empty for fork PRs - so it is carried in the artifact instead.
# It comes from untrusted content and ends up in a hostname, so validate it.
- id: get-deploy-id
name: Get deploy ID
env:
ARTIFACT_DIR: ${{ runner.temp }}/artifacts
run: |
deployid=$(<"$ARTIFACT_DIR/deployid")
case "$deployid" in ''|*[!0-9]*) echo "Provided PR number is not an integer"; exit 1 ;; esac
echo "deploy-id=$deployid" >> "$GITHUB_OUTPUT"
# Same formula as docs-api-reference-teardown.yml and the gds-api-uri override in
# docs-pr-checks.yml - keep the three in sync.
- id: get-deploy-url
name: Get deploy URL
env:
ORG: ${{ github.event.repository.owner.login }}
REPO: ${{ github.event.repository.name }}
DEPLOYID: ${{ steps.get-deploy-id.outputs.deploy-id }}
run: |
deployurl=$ORG-$REPO-$DEPLOYID-api.surge.sh
echo "deploy-url=$deployurl" >> $GITHUB_OUTPUT
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v6
with:
node-version: "24.22.1"
- name: Deploy API reference to surge
shell: bash
env:
DEPLOY_URL: ${{ steps.get-deploy-url.outputs.deploy-url }}
SURGE_TOKEN: "${{ secrets.DOCS_SURGE_TOKEN }}"
SITE_DIR: ${{ runner.temp }}/artifacts/site
run: |
npm install -g surge
cd "$SITE_DIR"
surge . "$DEPLOY_URL" --token "$SURGE_TOKEN"
# Own comment/header, separate from docs-deploy-surge.yml's "docs-pr-changes"
# comment, so the two previews don't overwrite each other on the PR
- name: Comment on PR
env:
DEPLOY_URL: ${{ steps.get-deploy-url.outputs.deploy-url }}
uses: marocchino/sticky-pull-request-comment@5770ad5eb8f42dd2c4f34da00c94c5381e49af88 #v3
with:
number: ${{ steps.get-deploy-id.outputs.deploy-id }}
header: docs-api-reference-changes
message: |
Looks like you've updated the API reference!
Check out your changes at https://${{ env.DEPLOY_URL }}
If this PR also previews the manual, its API reference links point here.
GITHUB_TOKEN: ${{ secrets.DOCS_PR_COMMENT_TOKEN }}