-
Notifications
You must be signed in to change notification settings - Fork 0
207 lines (189 loc) · 8.76 KB
/
Copy pathguide-draft.yml
File metadata and controls
207 lines (189 loc) · 8.76 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
name: Guide draft
on:
issues:
types: [labeled]
jobs:
draft:
if: github.event.label.name == 'guide:draft'
runs-on: ubuntu-latest
timeout-minutes: 180
concurrency:
group: guide-draft-issue-${{ github.event.issue.number }}
cancel-in-progress: false
permissions:
contents: write
issues: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0
token: ${{ secrets.AGENT_PAT || secrets.GITHUB_TOKEN }}
- name: Configure runner temp
run: printf 'TMPDIR=%s\n' "$RUNNER_TEMP" >>"$GITHUB_ENV"
- name: Set up publisher
id: publisher_setup
env:
GH_TOKEN: ${{ secrets.AGENT_PAT || secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
run: |
printf '%s\n' 'Publisher setup failed.' >"$RUNNER_TEMP/failure-reason.txt"
mkdir -p "$RUNNER_TEMP/guide-factory-publisher/factory/scripts"
cp factory/scripts/publish.sh factory/scripts/lib.sh \
"$RUNNER_TEMP/guide-factory-publisher/factory/scripts/"
PUBLISHER_PATH="$RUNNER_TEMP/guide-factory-publisher/factory/scripts/publish.sh"
printf 'PUBLISHER_PATH=%s\n' "$PUBLISHER_PATH" >>"$GITHUB_ENV"
bash "$PUBLISHER_PATH" ensure-labels
- name: Preflight existing factory work
id: preflight
env:
GH_TOKEN: ${{ secrets.AGENT_PAT || secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
run: |
printf '%s\n' 'Preflight failed.' >"$RUNNER_TEMP/failure-reason.txt"
bash factory/scripts/preflight.sh
- name: Refuse non-factory pull request
id: refusal
if: success() && steps.preflight.outputs.refused == 'true'
env:
GH_TOKEN: ${{ secrets.AGENT_PAT || secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
run: |
printf '%s\n' 'Refusal reporting failed.' >"$RUNNER_TEMP/failure-reason.txt"
bash "$PUBLISHER_PATH" refuse '${{ steps.preflight.outputs.refused_pr_url }}'
- name: Checkout resume branch and sync main
id: resume_sync
if: success() && steps.refusal.outcome != 'success' && steps.preflight.outputs.resume == 'true'
env:
RESUME_BRANCH: ${{ steps.preflight.outputs.resume_branch }}
run: |
printf '%s\n' 'Resume branch synchronization failed.' >"$RUNNER_TEMP/failure-reason.txt"
git config --local user.name github-actions[bot]
git config --local user.email 41898282+github-actions[bot]@users.noreply.github.com
git fetch origin main "$RESUME_BRANCH"
git checkout -B "$RESUME_BRANCH" "origin/$RESUME_BRANCH"
git merge --no-edit origin/main
- name: Transition labels
id: transition
if: success() && steps.refusal.outcome != 'success'
env:
GH_TOKEN: ${{ secrets.AGENT_PAT || secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
run: |
printf '%s\n' 'Label transition failed.' >"$RUNNER_TEMP/failure-reason.txt"
bash "$PUBLISHER_PATH" transition
- name: Prepare issue input
id: prepare_input
if: success() && steps.refusal.outcome != 'success'
env:
GH_TOKEN: ${{ secrets.AGENT_PAT || secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
run: |
printf '%s\n' 'Issue input preparation failed.' >"$RUNNER_TEMP/failure-reason.txt"
bash factory/scripts/prepare-input.sh '${{ github.event.issue.number }}' "$RUNNER_TEMP/issue.json"
- name: Prepare catalog snapshot
id: prepare_catalog
if: success() && steps.refusal.outcome != 'success'
env:
PULSE_REGISTRY_KEY: ${{ secrets.PULSE_REGISTRY_KEY }}
PULSE_REGISTRY_TENANT: ${{ secrets.PULSE_REGISTRY_TENANT }}
PULSE_REGISTRY_URL: ${{ secrets.PULSE_REGISTRY_URL }}
run: |
printf '%s\n' 'Catalog snapshot preparation failed.' >"$RUNNER_TEMP/failure-reason.txt"
bash factory/scripts/prepare-catalog.sh "$RUNNER_TEMP/catalog.json"
- name: Run Kit
id: kit
if: success() && steps.refusal.outcome != 'success'
env:
OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }}
run: |
printf '%s\n' 'Kit execution failed.' >"$RUNNER_TEMP/failure-reason.txt"
bash factory/scripts/run-kit.sh \
"$RUNNER_TEMP/issue.json" \
"$RUNNER_TEMP/catalog.json" \
"$RUNNER_TEMP/export"
cp "$RUNNER_TEMP/export/run-report.json" "$RUNNER_TEMP/run-report.json"
- name: Upload safe factory diagnostics
if: failure() && steps.kit.outcome == 'failure'
uses: actions/upload-artifact@v4
with:
name: guide-factory-diagnostics-${{ github.run_id }}-${{ github.run_attempt }}
path: ${{ runner.temp }}/export/factory-diagnostics.json
retention-days: 7
if-no-files-found: ignore
- name: Validate export
id: validate
if: success() && steps.refusal.outcome != 'success'
run: |
printf '%s\n' 'Factory export validation failed.' >"$RUNNER_TEMP/failure-reason.txt"
bash factory/scripts/validate.sh "$RUNNER_TEMP/export" "$GITHUB_WORKSPACE"
- name: Publish guide
id: publish
if: success() && steps.refusal.outcome != 'success'
env:
GH_TOKEN: ${{ secrets.AGENT_PAT || secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
RESUME: ${{ steps.preflight.outputs.resume }}
RESUME_BRANCH: ${{ steps.preflight.outputs.resume_branch }}
RESUME_PR_NUMBER: ${{ steps.preflight.outputs.resume_pr_number }}
run: |
printf '%s\n' 'Guide publication failed.' >"$RUNNER_TEMP/failure-reason.txt"
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
bash "$PUBLISHER_PATH" publish "$RUNNER_TEMP/run-report.json"
- name: Report failure
id: failure_report
if: failure() && steps.publisher_setup.outcome == 'success' && steps.refusal.outcome != 'success'
env:
GH_TOKEN: ${{ secrets.AGENT_PAT || secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
run: bash "$PUBLISHER_PATH" fail "$RUNNER_TEMP/failure-reason.txt"
- name: Cleanup labels
id: cleanup
if: always() && steps.publisher_setup.outcome == 'success'
env:
GH_TOKEN: ${{ secrets.AGENT_PAT || secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
run: bash "$PUBLISHER_PATH" cleanup
- name: Bootstrap failure fallback
id: bootstrap_failure
if: always() && steps.publisher_setup.outcome != 'success'
env:
GH_TOKEN: ${{ secrets.AGENT_PAT || secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
status=0
gh label view guide:blocked --repo "$GH_REPO" >/dev/null 2>&1 ||
gh label create guide:blocked --repo "$GH_REPO" --color D73A4A \
--description 'Guide draft factory blocked' >/dev/null || status=$?
gh issue edit "$ISSUE_NUMBER" --repo "$GH_REPO" \
--remove-label guide:draft >/dev/null || status=$?
gh issue edit "$ISSUE_NUMBER" --repo "$GH_REPO" \
--remove-label guide:in-progress >/dev/null || status=$?
gh issue edit "$ISSUE_NUMBER" --repo "$GH_REPO" \
--add-label guide:blocked >/dev/null || status=$?
labels="$(gh issue view "$ISSUE_NUMBER" --repo "$GH_REPO" \
--json labels --jq '.labels[].name')" || status=$?
if grep -Fqx guide:draft <<<"$labels" ||
grep -Fqx guide:in-progress <<<"$labels" ||
! grep -Fqx guide:blocked <<<"$labels"; then
status=1
fi
printf '%s\n' \
'## Guide factory failed during publisher setup' '' \
"**Workflow run:** $RUN_URL" \
>"$RUNNER_TEMP/bootstrap-comment.md"
gh issue comment "$ISSUE_NUMBER" --repo "$GH_REPO" \
--body-file "$RUNNER_TEMP/bootstrap-comment.md" || status=$?
exit "$status"