forked from TraceMachina/nativelink
-
Notifications
You must be signed in to change notification settings - Fork 0
139 lines (126 loc) · 5.34 KB
/
Copy pathconfig-reference.yaml
File metadata and controls
139 lines (126 loc) · 5.34 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
---
# Automates step 8 of the release process in CONTRIBUTING.md: when a release
# tag is pushed, regenerate the versioned NativeLink configuration reference
# (web/apps/docs) from that tag and open a PR against main with auto-merge
# enabled.
#
# The generator needs the tag to exist (it builds the config schema from a
# `git worktree` of the tag), which is why this runs on tag push rather than
# on the release PR itself.
#
# Full automation requires two repository settings:
# - "Allow auto-merge" must be enabled (Settings → General).
# - A `WORKFLOW_PR_TOKEN` secret (fine-grained PAT or GitHub App token with
# contents:write + pull-requests:write). PRs created with the default
# GITHUB_TOKEN do not trigger CI workflows, so required checks would never
# report and auto-merge would never fire. Without the secret this workflow
# still opens the PR; it just needs a human to merge it.
name: Regenerate config reference
on:
push:
tags:
- 'v1.*'
# Manual entry point to (re)generate docs for an existing tag, e.g. to
# backfill a release where this workflow failed.
workflow_dispatch:
inputs:
tag:
description: 'Existing release tag to regenerate the config reference for (e.g. v1.6.1) or blank for all'
required: false # Blank to allow full regen
type: string
# Weekly docs regeneration to catch any cases where we've made updates but haven't changed anything
schedule:
# Sunday 4:13am randomly picked
- cron: 13 4 * * SUN
permissions: read-all
concurrency:
group: ${{ github.workflow }}-${{ inputs.tag || github.ref_name }}
cancel-in-progress: false
jobs:
regenerate:
name: Regenerate and open PR
runs-on: ubuntu-24.04
timeout-minutes: 60
permissions:
contents: write
pull-requests: write
id-token: write
steps:
- name: Resolve tag
id: resolve
run: |
set -euo pipefail
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
TAG="${{ inputs.tag }}"
elif [[ "${{ github.event_name }}" == "schedule" ]]; then
TAG=
else
TAG="${{ github.ref_name }}"
fi
if [[ "${TAG}" != "" && "${TAG}" != "main" && ( ! "${TAG}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ) ]]; then
echo "::error::'${TAG}' is not a release tag (vMAJOR.MINOR.PATCH); refusing to regenerate."
exit 1
fi
echo "tag=${TAG}" >> "${GITHUB_OUTPUT}"
- name: Checkout
uses: >- # v6.0.2
actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:
# The docs update lands on main; the generator resolves every
# release tag itself, so it needs the full history and all tags.
ref: main
fetch-depth: 0
- name: Prepare Worker
uses: ./.github/actions/prepare-nix
with:
nativelink_attic_token: ${{ secrets.NATIVELINK_ATTIC_TOKEN }}
- name: Regenerate config reference
working-directory: web
run: |
nix develop --impure --command bash -c "
bun install && bun --filter @nativelink/docs gen:config-reference ${{ steps.resolve.outputs.tag }}
"
- name: Lint generated docs
run: |
nix develop --impure --command bash -c "
vale web/apps/docs/content/docs/reference/nativelink-config/*.mdx
"
- name: Open auto-merge PR
env:
GH_TOKEN: ${{ secrets.WORKFLOW_PR_TOKEN || github.token }}
TAG: ${{ steps.resolve.outputs.tag }}
run: |
set -euo pipefail
# The generator also creates new untracked pages (the previous
# latest release gets its own versioned page), so check the whole
# docs tree, not just tracked modifications.
if [[ -z "$(git status --porcelain -- web/apps/docs)" ]]; then
echo "Config reference already up to date for ${TAG}; nothing to do."
exit 0
fi
BRANCH="docs/config-reference-${TAG}"
git config user.name "config reference bot"
git config user.email "bot@tracemachina.com"
git switch -c "${BRANCH}"
git add web/apps/docs
git commit -m "docs(config-reference): regenerate for NativeLink ${TAG}"
git push --force origin "${BRANCH}"
PR_URL=$(gh pr list --head "${BRANCH}" --base main --state open --json url --jq '.[0].url // empty')
if [[ -z "${PR_URL}" ]]; then
PR_URL=$(gh pr create \
--base main \
--head "${BRANCH}" \
--title "docs(config-reference): regenerate for NativeLink ${TAG}" \
--body "Automated regeneration of the NativeLink configuration reference for ${TAG} (CONTRIBUTING.md release step 8). Generated by the \`${{ github.workflow }}\` workflow.")
fi
echo "PR: ${PR_URL}"
# Best effort: requires "Allow auto-merge" in the repo settings and,
# with the default GITHUB_TOKEN, required checks never run — see the
# header comment.
gh pr merge --auto --squash "${PR_URL}" ||
echo "::notice::Auto-merge could not be enabled; merge ${PR_URL} manually."
- name: Teardown Worker
uses: ./.github/actions/end-nix
if: always()
with:
nativelink_attic_token: ${{ secrets.NATIVELINK_ATTIC_TOKEN }}