Skip to content

Commit 5eb339d

Browse files
fix(ci): add actions/checkout to docs preview + split build into two jobs
Without checkout the preview job cannot resolve the ./.github/actions/setup-pnpm-node composite. Sparse-checkout fetches only the composite + .node-version so the runner does not download the full repo for a Surge deploy. Splitting the matrix into build-preview / build-production avoids spinning a runner on the idle flavor. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent a96291c commit 5eb339d

1 file changed

Lines changed: 57 additions & 72 deletions

File tree

.github/workflows/cd-docs.yml

Lines changed: 57 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -31,91 +31,83 @@ permissions:
3131
statuses: write
3232

3333
jobs:
34-
build:
35-
name: Build (${{ matrix.flavor }})
34+
# build-preview and build-production are split so each only spins up a runner
35+
# for the event it serves; collapsing into a matrix would burn ~30s on the
36+
# idle flavor for every trigger. The shared steps live in setup-pnpm-node.
37+
build-preview:
38+
name: Build (preview)
39+
if: github.event_name == 'pull_request'
3640
runs-on: ubuntu-latest
37-
strategy:
38-
fail-fast: false
39-
matrix:
40-
include:
41-
- flavor: preview
42-
condition: pull_request
43-
base_url: "/"
44-
- flavor: production
45-
condition: push
46-
base_url: "/Hephaestus/"
4741
steps:
48-
- name: Gate by event
49-
id: gate
50-
run: |
51-
if [[ "${{ matrix.condition }}" == "pull_request" && "${{ github.event_name }}" != "pull_request" ]]; then
52-
echo "run=false" >> "$GITHUB_OUTPUT"
53-
elif [[ "${{ matrix.condition }}" == "push" && ! ( "${{ github.event_name }}" == "push" && "${{ github.ref }}" == "refs/heads/main" ) ]]; then
54-
echo "run=false" >> "$GITHUB_OUTPUT"
55-
else
56-
echo "run=true" >> "$GITHUB_OUTPUT"
57-
fi
58-
59-
- name: Checkout repository
60-
if: steps.gate.outputs.run == 'true'
61-
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
62-
63-
- name: Setup pnpm + Node.js
64-
if: steps.gate.outputs.run == 'true'
65-
uses: ./.github/actions/setup-pnpm-node
66-
67-
- name: Cache Docusaurus build
68-
if: steps.gate.outputs.run == 'true'
69-
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
42+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
43+
- uses: ./.github/actions/setup-pnpm-node
44+
- uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
7045
with:
7146
path: |
7247
docs/.docusaurus
7348
docs/node_modules/.cache
74-
key: ${{ runner.os }}-docusaurus-${{ matrix.flavor }}-${{ hashFiles('pnpm-lock.yaml') }}-${{ hashFiles('docs/**/*.md', 'docs/**/*.mdx', 'docs/**/*.ts') }}
49+
key: ${{ runner.os }}-docusaurus-preview-${{ hashFiles('pnpm-lock.yaml') }}-${{ hashFiles('docs/**/*.md', 'docs/**/*.mdx', 'docs/**/*.ts') }}
7550
restore-keys: |
76-
${{ runner.os }}-docusaurus-${{ matrix.flavor }}-${{ hashFiles('pnpm-lock.yaml') }}-
77-
${{ runner.os }}-docusaurus-${{ matrix.flavor }}-
78-
79-
- name: Install dependencies
80-
if: steps.gate.outputs.run == 'true'
81-
run: pnpm install --frozen-lockfile
82-
83-
- name: Build documentation
84-
if: steps.gate.outputs.run == 'true'
85-
run: pnpm --filter docs run build
51+
${{ runner.os }}-docusaurus-preview-${{ hashFiles('pnpm-lock.yaml') }}-
52+
${{ runner.os }}-docusaurus-preview-
53+
- run: pnpm install --frozen-lockfile
54+
- run: pnpm --filter docs run build
8655
env:
87-
DOCUSAURUS_BASE_URL: ${{ matrix.base_url }}
56+
DOCUSAURUS_BASE_URL: "/"
57+
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
58+
with:
59+
name: docs-build-preview
60+
path: docs/build
61+
retention-days: 1
8862

89-
- name: Upload build artifact
90-
if: steps.gate.outputs.run == 'true'
91-
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
63+
build-production:
64+
name: Build (production)
65+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
66+
runs-on: ubuntu-latest
67+
steps:
68+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
69+
- uses: ./.github/actions/setup-pnpm-node
70+
- uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
9271
with:
93-
name: docs-build-${{ matrix.flavor }}
72+
path: |
73+
docs/.docusaurus
74+
docs/node_modules/.cache
75+
key: ${{ runner.os }}-docusaurus-production-${{ hashFiles('pnpm-lock.yaml') }}-${{ hashFiles('docs/**/*.md', 'docs/**/*.mdx', 'docs/**/*.ts') }}
76+
restore-keys: |
77+
${{ runner.os }}-docusaurus-production-${{ hashFiles('pnpm-lock.yaml') }}-
78+
${{ runner.os }}-docusaurus-production-
79+
- run: pnpm install --frozen-lockfile
80+
- run: pnpm --filter docs run build
81+
env:
82+
DOCUSAURUS_BASE_URL: "/Hephaestus/"
83+
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
84+
with:
85+
name: docs-build-production
9486
path: docs/build
9587
retention-days: 1
9688

9789
preview:
9890
name: PR Preview
99-
needs: build
91+
needs: build-preview
10092
if: github.event_name == 'pull_request'
10193
runs-on: ubuntu-latest
10294
env:
10395
PREVIEW_URL: ls1intum-hephaestus-docs-pr-${{ github.event.number }}.surge.sh
10496
steps:
105-
- name: Download build artifact
106-
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
97+
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
98+
with:
99+
sparse-checkout: |
100+
.github/actions/setup-pnpm-node
101+
.node-version
102+
sparse-checkout-cone-mode: false
103+
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
107104
with:
108105
name: docs-build-preview
109106
path: docs-build
110-
111-
- name: Setup pnpm + Node.js
112-
uses: ./.github/actions/setup-pnpm-node
113-
107+
- uses: ./.github/actions/setup-pnpm-node
114108
- name: Deploy to Surge.sh
115109
run: pnpm dlx surge ./docs-build ${{ env.PREVIEW_URL }} --token ${{ secrets.SURGE_TOKEN }}
116-
117-
- name: Comment on PR
118-
uses: marocchino/sticky-pull-request-comment@773744901bac0e8cbb5a0dc842800d45e9b2b405 # v2
110+
- uses: marocchino/sticky-pull-request-comment@773744901bac0e8cbb5a0dc842800d45e9b2b405 # v2
119111
with:
120112
header: docs-preview
121113
message: |
@@ -126,9 +118,7 @@ jobs:
126118
🔗 **[View Docs Preview](https://${{ env.PREVIEW_URL }})**
127119
128120
<sub>Preview for commit ${{ github.event.pull_request.head.sha }}. Updates automatically on new commits.</sub>
129-
130-
- name: Create Docs Preview status check
131-
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
121+
- uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
132122
with:
133123
script: |
134124
const sha = context.payload.pull_request?.head?.sha || context.sha;
@@ -144,24 +134,19 @@ jobs:
144134
145135
deploy:
146136
name: GitHub Pages
147-
needs: build
137+
needs: build-production
148138
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
149139
runs-on: ubuntu-latest
150140
environment:
151141
name: github-pages
152142
url: ${{ steps.deployment.outputs.page_url }}
153143
steps:
154-
- name: Download build artifact
155-
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
144+
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
156145
with:
157146
name: docs-build-production
158147
path: docs-build
159-
160-
- name: Upload to GitHub Pages
161-
uses: actions/upload-pages-artifact@56afc609e74202658d3ffba0e8f6dda462b719fa # v3
148+
- uses: actions/upload-pages-artifact@56afc609e74202658d3ffba0e8f6dda462b719fa # v3
162149
with:
163150
path: docs-build
164-
165-
- name: Deploy to GitHub Pages
166-
id: deployment
151+
- id: deployment
167152
uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4

0 commit comments

Comments
 (0)