-
Notifications
You must be signed in to change notification settings - Fork 25
174 lines (152 loc) · 6.69 KB
/
Copy pathsource-audit.yml
File metadata and controls
174 lines (152 loc) · 6.69 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
name: Audit source health
on:
schedule:
# Sunday 06:37 Asia/Shanghai, before the weekly refresh.
- cron: "37 22 * * 6"
workflow_dispatch:
permissions:
actions: write
contents: write
issues: write
concurrency:
group: agent-pulse-repository-data-main
cancel-in-progress: false
jobs:
audit:
runs-on: ubuntu-latest
timeout-minutes: 45
env:
DATABASE_URL: sqlite:./var/source-audit.db
COLLECTOR_CONCURRENCY: 4
steps:
- name: Check out main
uses: actions/checkout@v7
with:
ref: main
fetch-depth: 0
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version: 24
cache: npm
- name: Install locked dependencies
run: npm ci
- name: Restore auditable repository snapshot
run: npm run db:snapshot -- restore
- name: Capture the current public source fingerprint
shell: bash
run: |
set -euo pipefail
npm run export -- --skip-seed
npm run --silent public:fingerprint -- --include-sources > "$RUNNER_TEMP/public-before.sha256"
- name: Audit every configured source
run: npm run sources:audit -- --concurrency=4 --report=data/reports/source-health.json
- name: Reconcile unstable sources and radar
run: npm run ops:reconcile
- name: Reconcile eligible shadow observation
run: npm run observe:sources -- --confirm
- name: Activate only qualified observation sources
run: npm run activate:auto
- name: Merge latest remote repository snapshot
shell: bash
run: |
set -euo pipefail
git fetch origin main
git show origin/main:data/snapshot/v1.json > "$RUNNER_TEMP/remote-snapshot.json"
npm run db:snapshot -- merge --file="$RUNNER_TEMP/remote-snapshot.json"
- name: Export converged source state and detect a material public change
id: public
shell: bash
run: |
set -euo pipefail
npm run export -- --skip-seed
npm run --silent public:validate -- --output="$RUNNER_TEMP/public-integrity.json"
npm run --silent public:fingerprint -- --include-sources > "$RUNNER_TEMP/public-after.sha256"
if cmp -s "$RUNNER_TEMP/public-before.sha256" "$RUNNER_TEMP/public-after.sha256"; then
echo "No material public source changes."
echo "changed=false" >> "$GITHUB_OUTPUT"
else
echo "Material public source state changed."
echo "changed=true" >> "$GITHUB_OUTPUT"
fi
- name: Upload public integrity evidence
if: always()
uses: actions/upload-artifact@v7
with:
name: source-audit-public-integrity-${{ github.run_id }}
path: ${{ runner.temp }}/public-integrity.json
if-no-files-found: ignore
retention-days: 14
- name: Write privacy-safe snapshot with accumulated checks
run: npm run db:snapshot -- write
- name: Validate report privacy and shape
shell: bash
run: |
set -euo pipefail
test -s data/reports/source-health.json
test -s data/snapshot/v1.json
git diff --check -- data/reports/source-health.json data/snapshot/v1.json
if grep -E 'gh[opsu]_[A-Za-z0-9_]{20,}|-----BEGIN .*PRIVATE KEY-----|/Users/[^/]+/|/home/runner/|"(token|secret|password|cookie|authorization|api[_-]?key)"[[:space:]]*:' data/reports/source-health.json data/snapshot/v1.json; then
echo "Private material detected in source health output" >&2
exit 1
fi
- name: Render compact source health summary
run: npm run --silent sources:health:issue -- --report data/reports/source-health.json > "$RUNNER_TEMP/source-health-summary.md"
- name: Update the single automated source health issue
id: health_issue
env:
GH_TOKEN: ${{ github.token }}
shell: bash
run: |
set -euo pipefail
gh label create "source:health" --color fbca04 --description "Source health and maintenance" --force
existing="$(gh issue list --state all --label "source:health" --limit 100 --json number,body,state \
--jq '.[] | select(.body | contains("agent-pulse-source-health-summary:v1")) | [.number, .state] | @tsv' | head -n 1)"
if [[ -n "$existing" ]]; then
issue_number="${existing%%$'\t'*}"
issue_state="${existing##*$'\t'}"
gh issue edit "$issue_number" --body-file "$RUNNER_TEMP/source-health-summary.md"
if [[ "$issue_state" == "CLOSED" ]]; then gh issue reopen "$issue_number"; fi
else
issue_url="$(gh issue create --title "[Source health] Automated source health summary" \
--label "source:health" --body-file "$RUNNER_TEMP/source-health-summary.md")"
issue_number="${issue_url##*/}"
fi
echo "issue_number=$issue_number" >> "$GITHUB_OUTPUT"
- name: Verify source health issue freshness
env:
GH_TOKEN: ${{ github.token }}
ISSUE_NUMBER: ${{ steps.health_issue.outputs.issue_number }}
shell: bash
run: |
set -euo pipefail
test -n "$ISSUE_NUMBER"
issue_state="$(gh issue view "$ISSUE_NUMBER" --json state --jq '.state')"
test "$issue_state" = "OPEN"
gh issue view "$ISSUE_NUMBER" --json body --jq '.body' > "$RUNNER_TEMP/source-health-issue.md"
grep -F '<!-- agent-pulse-source-health-summary:v1 -->' "$RUNNER_TEMP/source-health-issue.md" >/dev/null
finished_at="$(jq -r '.finishedAt' data/reports/source-health.json)"
test -n "$finished_at"
grep -F "$finished_at" "$RUNNER_TEMP/source-health-issue.md" >/dev/null
- name: Commit report when changed
id: commit
shell: bash
run: |
set -euo pipefail
git add -- data/reports/source-health.json data/snapshot/v1.json
if git diff --cached --quiet; then
echo "No report changes."
echo "changed=false" >> "$GITHUB_OUTPUT"
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git commit -m "chore(data): refresh source health report"
git rebase origin/main
git push origin HEAD:main
echo "changed=true" >> "$GITHUB_OUTPUT"
- name: Dispatch Pages deployment for material public source changes
if: steps.commit.outputs.changed == 'true' && steps.public.outputs.changed == 'true'
env:
GH_TOKEN: ${{ github.token }}
run: gh workflow run pages.yml --ref main