-
Notifications
You must be signed in to change notification settings - Fork 1.5k
266 lines (242 loc) · 11.5 KB
/
Copy pathdoc-check.yaml
File metadata and controls
266 lines (242 loc) · 11.5 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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
# This workflow checks if a PR requires documentation updates.
# It creates a Coder Agent chat session that uses AI to analyze the PR
# changes, search existing docs, and comment with recommendations.
#
# Triggers:
# - New PR opened: Initial documentation review
# - PR updated (synchronize): Re-review after changes
# - Label "doc-check" added: Manual trigger for review
# - PR marked ready for review: Review when draft is promoted
# - Workflow dispatch: Manual run with PR URL
#
# Note: This workflow requires access to secrets and will be skipped for:
# - Any PR where secrets are not available
# For these PRs, maintainers can manually trigger via workflow_dispatch.
name: AI Documentation Check
on:
pull_request:
types:
- opened
- synchronize
- labeled
- ready_for_review
workflow_dispatch:
inputs:
pr_url:
description: "Pull Request URL to check"
required: true
type: string
permissions:
contents: read
jobs:
doc-check:
name: Analyze PR for Documentation Updates Needed
runs-on: ubuntu-latest
# Run on: opened, synchronize, labeled (with doc-check label), ready_for_review, or workflow_dispatch
# Skip draft PRs unless manually triggered
if: |
(
github.event.action == 'opened' ||
github.event.action == 'synchronize' ||
github.event.label.name == 'doc-check' ||
github.event.action == 'ready_for_review' ||
github.event_name == 'workflow_dispatch'
) &&
(github.event.pull_request.draft == false || github.event_name == 'workflow_dispatch') &&
(github.event_name == 'workflow_dispatch' || github.event.pull_request.head.repo.full_name == github.repository)
timeout-minutes: 30
permissions:
contents: read
pull-requests: write
steps:
- name: Check if secrets are available
id: check-secrets
env:
CODER_URL: ${{ secrets.DOC_CHECK_CODER_URL }}
CODER_TOKEN: ${{ secrets.DOC_CHECK_CODER_SESSION_TOKEN }}
run: |
if [[ -z "${CODER_URL}" || -z "${CODER_TOKEN}" ]]; then
echo "skip=true" >> "${GITHUB_OUTPUT}"
echo "Secrets not available - skipping doc-check."
echo "This is expected for PRs where secrets are not available."
echo "Maintainers can manually trigger via workflow_dispatch if needed."
{
echo "⚠️ Workflow skipped: Secrets not available"
echo ""
echo "This workflow requires secrets that are unavailable for this run."
echo "Maintainers can manually trigger via workflow_dispatch if needed."
} >> "${GITHUB_STEP_SUMMARY}"
else
echo "skip=false" >> "${GITHUB_OUTPUT}"
fi
- name: Determine PR Context
if: steps.check-secrets.outputs.skip != 'true'
id: determine-context
env:
GITHUB_EVENT_NAME: ${{ github.event_name }}
GITHUB_EVENT_ACTION: ${{ github.event.action }}
GITHUB_EVENT_PR_HTML_URL: ${{ github.event.pull_request.html_url }}
GITHUB_EVENT_PR_NUMBER: ${{ github.event.pull_request.number }}
INPUTS_PR_URL: ${{ inputs.pr_url }}
run: |
# Determine trigger type for context
if [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" ]]; then
echo "trigger_type=manual" >> "${GITHUB_OUTPUT}"
echo "Using PR URL: ${INPUTS_PR_URL}"
# Validate PR URL format
if [[ ! "${INPUTS_PR_URL}" =~ ^https://github\.com/[^/]+/[^/]+/pull/[0-9]+$ ]]; then
echo "::error::Invalid PR URL format: ${INPUTS_PR_URL}"
echo "::error::Expected format: https://github.com/owner/repo/pull/NUMBER"
exit 1
fi
ISSUE_URL="${INPUTS_PR_URL/\/pull\//\/issues\/}"
echo "pr_url=${ISSUE_URL}" >> "${GITHUB_OUTPUT}"
PR_NUMBER=$(echo "${INPUTS_PR_URL}" | grep -oP '(?<=pull/)\d+')
echo "pr_number=${PR_NUMBER}" >> "${GITHUB_OUTPUT}"
elif [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then
echo "Using PR URL: ${GITHUB_EVENT_PR_HTML_URL}"
ISSUE_URL="${GITHUB_EVENT_PR_HTML_URL/\/pull\//\/issues\/}"
echo "pr_url=${ISSUE_URL}" >> "${GITHUB_OUTPUT}"
echo "pr_number=${GITHUB_EVENT_PR_NUMBER}" >> "${GITHUB_OUTPUT}"
# Set trigger type based on action
case "${GITHUB_EVENT_ACTION}" in
opened)
echo "trigger_type=new_pr" >> "${GITHUB_OUTPUT}"
;;
synchronize)
echo "trigger_type=pr_updated" >> "${GITHUB_OUTPUT}"
;;
labeled)
echo "trigger_type=label_requested" >> "${GITHUB_OUTPUT}"
;;
ready_for_review)
echo "trigger_type=ready_for_review" >> "${GITHUB_OUTPUT}"
;;
*)
echo "trigger_type=unknown" >> "${GITHUB_OUTPUT}"
;;
esac
else
echo "::error::Unsupported event type: ${GITHUB_EVENT_NAME}"
exit 1
fi
- name: Check the review workspace is usable
if: steps.check-secrets.outputs.skip != 'true'
id: check-workspace
env:
CODER_URL: ${{ secrets.DOC_CHECK_CODER_URL }}
CODER_TOKEN: ${{ secrets.DOC_CHECK_CODER_SESSION_TOKEN }}
PR_NUMBER: ${{ steps.determine-context.outputs.pr_number }}
run: |
# A review reuses one chat per PR, and that chat owns one workspace.
# The workspace stops after about a day and then goes dormant. A chat
# cannot repair a dormant workspace: start_workspace and
# create_workspace both fail with
# "unauthorized: rbac: forbidden". The review then reads
# nothing and posts nothing, and this job used to still pass. Fail
# here instead, so the check reports what happened.
# https://linear.app/codercom/issue/CODAGT-1025
WS_NAME="doc-check-pr-${PR_NUMBER}"
RESPONSE=$(curl -sS --fail-with-body -G \
-H "Coder-Session-Token: ${CODER_TOKEN}" \
--data-urlencode "q=owner:me name:${WS_NAME}" \
"${CODER_URL%/}/api/v2/workspaces") || {
echo "::warning::Could not read the workspace state from Coder. Continuing."
exit 0
}
DORMANT_AT=$(echo "${RESPONSE}" | jq -r '.workspaces[0].dormant_at // empty')
if [[ -n "${DORMANT_AT}" ]]; then
echo "::error::${WS_NAME} is dormant since ${DORMANT_AT}. The review cannot run, because a chat cannot start its own dormant workspace: https://linear.app/codercom/issue/CODAGT-1025"
{
echo "### Documentation check did not run"
echo ""
echo "The workspace \`${WS_NAME}\` is dormant since ${DORMANT_AT}."
echo ""
echo "A chat cannot start its own dormant workspace, so the review would read no files and post no comment. See [CODAGT-1025](https://linear.app/codercom/issue/CODAGT-1025)."
echo ""
echo "To run the review now, start \`${WS_NAME}\` in Coder, then push again or re-run this job."
} >> "${GITHUB_STEP_SUMMARY}"
exit 1
fi
echo "Workspace state is usable."
- name: Build chat prompt
if: steps.check-secrets.outputs.skip != 'true'
id: extract-context
env:
PR_NUMBER: ${{ steps.determine-context.outputs.pr_number }}
TRIGGER_TYPE: ${{ steps.determine-context.outputs.trigger_type }}
run: |
echo "Analyzing PR #${PR_NUMBER} (trigger: ${TRIGGER_TYPE})"
# Build context based on trigger type
case "${TRIGGER_TYPE}" in
new_pr)
CONTEXT="This is a NEW PR. Perform initial documentation review."
;;
pr_updated)
CONTEXT="This PR was UPDATED with new commits. Check if previous feedback was addressed or if new doc needs arose."
;;
label_requested)
CONTEXT="A documentation review was REQUESTED via label. Perform a thorough review."
;;
ready_for_review)
CONTEXT="This PR was marked READY FOR REVIEW. Perform a thorough review."
;;
manual)
CONTEXT="This is a MANUAL review request. Perform a thorough review."
;;
*)
CONTEXT="Perform a documentation review."
;;
esac
# Build the chat prompt. Durable rules live in the skill
# (.claude/skills/doc-check/SKILL.md), so this prompt stays short
# and carries only what changes per run.
CHAT_PROMPT="Use the doc-check skill to review PR #${PR_NUMBER} in coder/coder.
${CONTEXT}
Use \`gh\` to read the PR details, the diff, and every comment.
Follow the skill in full: its evidence discipline, its comment
rules, and its comment format. **Do not comment if no
documentation changes are needed.**
## When the workspace is broken
A tool call that fails with \`unauthorized: rbac: forbidden\` is an
infrastructure state, not a bad command, so retrying the same
command changes nothing.
Call \`start_workspace\` with no arguments. If it answers
\`workspace was deleted\` or \`chat has no workspace\`, call
\`list_templates\` for the \`coder-workflow-bot\` template ID, then
\`create_workspace\` with it, and run the failed call again. If it
answers \`load workspace: unauthorized: rbac: forbidden\`, the
workspace is dormant and you cannot repair it: stop, say you could
not review the PR, and name the error. Post no comment, and do not
imply the docs are fine, because you did not read them.
Create any new workspace from the \"coder-workflow-bot\" template."
# Output the prompt
{
echo "chat_prompt<<EOFOUTPUT"
echo "${CHAT_PROMPT}"
echo "EOFOUTPUT"
} >> "${GITHUB_OUTPUT}"
- name: Run doc-check via Coder Agent Chat
if: steps.check-secrets.outputs.skip != 'true'
uses: coder/agents-chat-action@b3fc81d7dae5006dd124e98ef6fada1a36cdd86e # v0.3.0
with:
coder-url: ${{ secrets.DOC_CHECK_CODER_URL }}
coder-token: ${{ secrets.DOC_CHECK_CODER_SESSION_TOKEN }}
# The bot account belongs to many organizations on this deployment,
# where the action's fallback organization choice is not
# deterministic. Pin it, because a model configuration ID only
# resolves inside its own organization.
coder-organization: coder
# Pins the model that reviews the PR. Set this repository variable to
# a model configuration ID in the organization above. Unset means the
# deployment's default model, so clearing the variable is the
# rollback path and needs no code change.
model-config-id: ${{ vars.DOC_CHECK_MODEL_CONFIG_ID }}
chat-prompt: ${{ steps.extract-context.outputs.chat_prompt }}
github-url: ${{ steps.determine-context.outputs.pr_url }}
github-token: ${{ github.token }}
wait: complete
wait-timeout-seconds: "600"
# The doc-check agent posts its own sticky comment when there
# are findings; failures surface in the workflow run log.
comment-on-issue: "false"