Repository navigation
152 lines (139 loc) · 6.35 KB
/
Copy pathgraphify.yml
File metadata and controls
152 lines (139 loc) · 6.35 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
# Rebuilds the committed knowledge graph in `graphify-out/`.
#
# Why this is a workflow and not a git hook (#1345): `graphify hook install`
# offers `post-commit` and `post-checkout` hooks, and both are a bad fit here
# because `graphify-out/` is *tracked* in this repo. `post-checkout` runs a
# full re-extraction on every branch switch — minutes of work, and it leaves
# the tree dirty right after a commit — which with several worktrees in play
# fires constantly. Moving the rebuild here keeps every local checkout clean
# and puts the cost on CI, the same shape as the README badge bot in
# `test.yml`.
#
# Deliberately NOT on every push. `graph.json` is ~36 MB and reorders on
# rebuild, so it deltas poorly; a commit per push would add gigabytes to a
# history that is already 210 MB. Weekly keeps the graph at most seven days
# behind, and `workflow_dispatch` covers "I just landed a big refactor".
#
# Scope: this refreshes the **code** side only (AST extraction — deterministic,
# no LLM, no API key). Documentation nodes come from semantic extraction and
# still need a deliberate `/graphify <path> --update` run in an agent session.
# Community labels are re-derived here: clustering re-runs and Louvain ids move
# whenever nodes change, so hand-curated labels cannot survive an automated
# rebuild — that is a known trade-off, not a defect (#1345).
#
# Two jobs, and the split is the security property (#1623), the same answer
# #622 gave the README badge and #703 gave publishing: `rebuild` installs and
# runs a third-party Python package with no credential at all, and `push`
# holds `contents: write` and installs nothing. They communicate only through
# the uploaded `graphify-out/` artifact, which `push` commits as data and never
# executes.
name: graphify
on:
schedule:
# Sundays, 03:17 UTC — off-peak, and a full week of commits per rebuild.
- cron: '17 3 * * 0'
workflow_dispatch:
permissions:
contents: read
# Serialise against the badge bot and against a manual run overlapping the
# scheduled one; both push to develop and would otherwise race on `git push`.
concurrency:
group: graphify-rebuild
cancel-in-progress: false
jobs:
rebuild:
name: Rebuild knowledge graph
runs-on: ubuntu-latest
# No write scope: this job runs graphify and its whole Python closure.
timeout-minutes: 60
outputs:
commit: ${{ steps.source.outputs.commit }}
changed: ${{ steps.moved.outputs.changed }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
# The graph belongs on develop; a dispatch from any other branch
# still rebuilds and pushes there rather than forking the artifact.
ref: develop
# Nothing here talks to the remote, so the credential checkout
# would leave in `.git/config` is pure attack surface for the
# package installed next.
persist-credentials: false
# The push job commits on top of exactly the tree this graph describes.
- name: Record the source commit
id: source
run: echo "commit=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
# Pinned on purpose, in .github/graphify/requirements.txt. The AST cache
# is keyed by version (`graphify-out/cache/ast/v<version>/`), so a silent
# upgrade would orphan the committed cache, force a full re-extraction
# and commit a second copy of it. Bumping it is a deliberate change, and
# the rebuild that follows it is expected to be large.
#
# The whole closure is pinned, not just the top level: `--require-hashes`
# refuses any distribution whose sha256 is not in the file, and
# `--only-binary :all:` refuses an sdist, so no package's build or setup
# code runs at install time (#1623).
- name: Install graphify
run: >-
python3 -m pip install --disable-pip-version-check
--require-hashes --only-binary ':all:' --no-deps
-r .github/graphify/requirements.txt
- name: Rebuild code side of the graph
run: graphify update .
- name: Did the graph move?
id: moved
run: |
if [[ -z "$(git status --porcelain graphify-out/)" ]]; then
echo "graph unchanged — nothing to commit"
echo "changed=false" >> "$GITHUB_OUTPUT"
else
echo "changed=true" >> "$GITHUB_OUTPUT"
fi
- name: Hand the graph to the push job
if: steps.moved.outputs.changed == 'true'
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: graphify-out
path: graphify-out/
if-no-files-found: error
retention-days: 1
push:
name: Commit + push the graph
needs: rebuild
if: needs.rebuild.outputs.changed == 'true'
runs-on: ubuntu-latest
# The only scope in the file that can change anything, on the one job that
# needs it (#621) — and that job installs and runs nothing (#1623).
permissions:
contents: write
timeout-minutes: 15
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ needs.rebuild.outputs.commit }}
# Replaced wholesale, so a cache entry the rebuild dropped is dropped
# here too.
- name: Clear the old graph
run: rm -rf graphify-out
- name: Fetch the rebuilt graph
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: graphify-out
path: graphify-out
# Only `graphify-out/` is staged: the artifact is the one thing that
# crossed over from the job that ran third-party code, and it lands as
# data in that directory and nowhere else. A push that fails because
# develop moved meanwhile fails loudly, as it did before the split; the
# next weekly run rebuilds on top.
- name: Commit + push
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add graphify-out/
if git diff --cached --quiet; then
echo "graph unchanged — nothing to commit"
exit 0
fi
git commit -m "chore(graphify): refresh knowledge graph [skip ci]"
git push origin HEAD:develop
echo "pushed graph refresh"