Skip to content

Commit 979ade4

Browse files
committed
improvement(ci): cache documentation inputs and parallelize acceptance
1 parent f60c772 commit 979ade4

6 files changed

Lines changed: 468 additions & 76 deletions

File tree

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Docs content cache
2+
description: Reuse validated incremental documentation compilation without sharing concurrent writer snapshots.
3+
inputs:
4+
provider:
5+
description: The CI_PROVIDER repo variable.
6+
required: false
7+
default: ''
8+
namespace:
9+
description: A distinct name for each concurrently writing job.
10+
required: true
11+
generate:
12+
description: Generate and validate content after restoring it. Set false only when the following build already runs content:generate.
13+
required: false
14+
default: 'true'
15+
next-cache:
16+
description: Also restore the incremental Next build cache.
17+
required: false
18+
default: 'false'
19+
runs:
20+
using: composite
21+
steps:
22+
- name: Identify the compiler runtime
23+
id: runtime
24+
shell: bash
25+
env:
26+
CACHE_NAMESPACE: ${{ inputs.namespace }}
27+
GENERATE: ${{ inputs.generate }}
28+
NEXT_CACHE: ${{ inputs.next-cache }}
29+
run: |
30+
[[ "$CACHE_NAMESPACE" =~ ^[a-z0-9][a-z0-9-]*$ ]]
31+
[[ "$GENERATE" == true || "$GENERATE" == false ]]
32+
[[ "$NEXT_CACHE" == true || "$NEXT_CACHE" == false ]]
33+
toolchain=$(node --version)
34+
toolchain="$toolchain-$(bun --version)"
35+
echo "toolchain=$toolchain" >> "$GITHUB_OUTPUT"
36+
compiler=$(git ls-files -s -- bun.lock package.json patches apps/docs/package.json apps/docs/scripts/compile-content.ts apps/docs/lib apps/docs/components/workflow-preview packages | sha256sum | awk '{ print $1 }')
37+
echo "compiler=$compiler" >> "$GITHUB_OUTPUT"
38+
- name: Restore incremental content
39+
continue-on-error: true
40+
uses: ./.github/actions/cache
41+
with:
42+
provider: ${{ inputs.provider }}
43+
key: ${{ github.repository }}-docs-content-v1-${{ inputs.namespace }}-${{ runner.os }}-${{ runner.arch }}-${{ steps.runtime.outputs.toolchain }}-${{ github.event_name }}${{ github.event.pull_request.head.repo.fork && format('-fork-{0}', github.event.pull_request.number) || '' }}-${{ steps.runtime.outputs.compiler }}
44+
path: ./apps/docs/.content
45+
- name: Bound restored content
46+
shell: bash
47+
run: bash .github/actions/docs-content-cache/prune.sh content
48+
- name: Restore incremental Next build
49+
if: inputs.next-cache == 'true'
50+
continue-on-error: true
51+
uses: ./.github/actions/cache
52+
with:
53+
provider: ${{ inputs.provider }}
54+
key: ${{ github.repository }}-docs-next-v1-${{ inputs.namespace }}-${{ runner.os }}-${{ runner.arch }}-${{ steps.runtime.outputs.toolchain }}-${{ github.event_name }}${{ github.event.pull_request.head.repo.fork && format('-fork-{0}', github.event.pull_request.number) || '' }}-${{ hashFiles('bun.lock') }}
55+
path: ./apps/docs/.next/cache
56+
- name: Bound the incremental build cache
57+
if: inputs.next-cache == 'true'
58+
shell: bash
59+
run: bash .github/actions/docs-content-cache/prune.sh next
60+
- name: Generate and validate documentation modules
61+
id: generate
62+
if: inputs.generate == 'true'
63+
shell: bash
64+
run: bun run --cwd apps/docs content:generate --prune
65+
- name: Bound content after an unsuccessful generation
66+
if: always() && inputs.generate == 'true' && steps.generate.outcome != 'success'
67+
shell: bash
68+
run: bash .github/actions/docs-content-cache/prune.sh content
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
case ${1:-} in
5+
content)
6+
cache=apps/docs/.content
7+
maximum_kilobytes=524288
8+
;;
9+
next)
10+
cache=apps/docs/.next/cache
11+
maximum_kilobytes=2097152
12+
;;
13+
*) echo 'Usage: prune.sh <content|next>' >&2; exit 2 ;;
14+
esac
15+
if [ ! -d "$cache" ]; then exit 0; fi
16+
if [ "$1" = next ]; then find "$cache" -type f -mtime +7 -delete; fi
17+
kilobytes=$(du -sk "$cache" | awk '{ print $1 }')
18+
if [ "$kilobytes" -gt "$maximum_kilobytes" ]; then
19+
find "$cache" -mindepth 1 -delete
20+
fi

0 commit comments

Comments
 (0)