Skip to content

Commit f403153

Browse files
committed
ci: build docs previews only with a docs-engine commit on main
docs/.engine-ref comes from the pull request, so the PR chooses which docs-engine commit runs. Once docs-engine is public, a commit pushed to any fork of it can be fetched by SHA through coder/docs-engine, so a format check alone would let a PR build with unreviewed engine code. The engine job now checks out full history and fails before packing unless the pinned commit is an ancestor of docs-engine main. Assisted-by: AI
1 parent 4bf624f commit f403153

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

‎.github/workflows/docs-pr-preview-deploy.yaml‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,18 @@ jobs:
109109
ref: ${{ steps.ref.outputs.ref }}
110110
token: ${{ steps.app-token.outputs.token }}
111111
path: engine
112+
fetch-depth: 0
112113
persist-credentials: false
113114

115+
# A fork's commit can be fetched by SHA through a public repository, so
116+
# only a commit on docs-engine main may build.
117+
- name: Check the pin is on docs-engine main
118+
env:
119+
REF: ${{ steps.ref.outputs.ref }}
120+
run: |
121+
set -euo pipefail
122+
git -C engine merge-base --is-ancestor "$REF" origin/main || { echo "::error::docs/.engine-ref must name a commit on coder/docs-engine main" >&2; exit 1; }
123+
114124
- name: Pack the engine source
115125
id: pack
116126
run: |

‎.github/workflows/test-docs-preview-mapper.sh‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,22 @@ else
936936
failures=$((failures + 1))
937937
fi
938938

939+
# The PR picks the engine commit through docs/.engine-ref. Once docs-engine is
940+
# public, a commit pushed to any fork of it can be fetched by SHA through
941+
# coder/docs-engine, so the engine job builds only commits on docs-engine main:
942+
# it checks out full history and fails before packing unless the pin is an
943+
# ancestor of origin/main.
944+
engine_job=$(awk '/^ engine:/{on=1} /^ build:/{on=0} on' "$deploy_workflow")
945+
# shellcheck disable=SC2016 # the expected lines are literal workflow text.
946+
if grep -qF 'fetch-depth: 0' <<<"$engine_job" &&
947+
grep -qF 'git -C engine merge-base --is-ancestor "$REF" origin/main' <<<"$engine_job" &&
948+
awk '/merge-base --is-ancestor/{seen=1} /name: Pack the engine source/{exit !seen}' <<<"$engine_job"; then
949+
echo "PASS: the engine job builds only commits on docs-engine main"
950+
else
951+
echo "FAIL: docs/.engine-ref can pin a docs-engine commit that is not on main"
952+
failures=$((failures + 1))
953+
fi
954+
939955
if [ "$failures" -gt 0 ]; then
940956
echo ""
941957
echo "$failures test(s) failed."

0 commit comments

Comments
 (0)