Repository navigation
Expand file tree
/
Copy pathpull-request-code-quality-review.yml
More file actions
194 lines (176 loc) · 7.62 KB
/
Copy pathpull-request-code-quality-review.yml
File metadata and controls
194 lines (176 loc) · 7.62 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
on:
workflow_call:
permissions: {}
env:
UV_LOCKED: 1
jobs:
review:
name: "code quality review"
if: >-
${{
github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.full_name == github.repository &&
(
github.repository == 'astral-sh/uv-dev' ||
(
github.repository == 'astral-sh/uv' &&
contains(fromJSON('["astral-automations-bot[bot]", "charliermarsh", "woodruffw", "zanieb", "zaniebot", "zsol"]'), github.event.pull_request.user.login)
)
)
}}
runs-on: depot-ubuntu-24.04-16
environment:
name: automations
deployment: false
timeout-minutes: 30
permissions:
contents: read
issues: read
pull-requests: read
outputs:
result: ${{ steps.review.outputs.final-message }}
steps:
- name: "Checkout caller repository"
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
- uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
with:
# renovate: datasource=github-release-attachments depName=astral-sh/uv
version: "0.13.6"
checksum: "f29c3e94ffabd7e6f3ba521dba169a9b7ec12100bf3257087f0f24f6123f3645"
- name: "Prepare review configuration"
env:
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
UV_PYTHON_DOWNLOADS_JSON_URL: ${{ github.workspace }}/crates/uv-python-managed/download-metadata.json
run: |
export REVIEW_CONFIG="$RUNNER_TEMP/pull-request-code-quality-review"
mkdir -p "$REVIEW_CONFIG/codex" "$RUNNER_TEMP/codex-code-quality-review"
printf 'REVIEW_CONFIG=%s\n' "$REVIEW_CONFIG" >> "$GITHUB_ENV"
cp agents/codex/config.toml "$REVIEW_CONFIG/codex/"
printf '\n[features]\nnetwork_proxy = true\n' >> "$REVIEW_CONFIG/codex/config.toml"
cp agents/prompts/pull-request-code-quality-review.md "$REVIEW_CONFIG/prompt.md"
cp agents/schemas/pull-request-code-quality-review.json "$REVIEW_CONFIG/schema.json"
cp agents/scripts/collect-pull-request-review-context.sh "$REVIEW_CONFIG/"
cp AGENTS.md CONTRIBUTING.md STYLE.md "$REVIEW_CONFIG/"
git rev-parse HEAD > "$REVIEW_CONFIG/configuration-revision.txt"
export UV_PROJECT_ENVIRONMENT="$RUNNER_TEMP/pull-request-code-quality-review-tools"
uv sync --locked --only-dev
echo "$UV_PROJECT_ENVIRONMENT/bin" >> "$GITHUB_PATH"
git checkout --detach "$HEAD_SHA"
- name: "Collect pull request context"
run: bash "$REVIEW_CONFIG/collect-pull-request-review-context.sh"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
# codex-action configures these only on GitHub-hosted runners.
- name: "Enable Linux user namespaces for bubblewrap"
run: |
current_userns="$(sysctl -n kernel.unprivileged_userns_clone 2>/dev/null || true)"
if [ -n "$current_userns" ] && [ "$current_userns" != "1" ]; then
sudo sysctl -w kernel.unprivileged_userns_clone=1
fi
current_apparmor="$(sysctl -n kernel.apparmor_restrict_unprivileged_userns 2>/dev/null || true)"
if [ -n "$current_apparmor" ] && [ "$current_apparmor" != "0" ]; then
sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0
fi
- name: "Review pull request"
id: review
uses: openai/codex-action@c05cfd74ad95c626cdf05c6685e62becc3bf7813
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TMPDIR: ${{ runner.temp }}/codex-code-quality-review
with:
openai-api-key: ${{ secrets.OPENAI_API_KEY }}
codex-version: "0.157.1"
codex-home: "${{ env.REVIEW_CONFIG }}/codex"
model: gpt-6-astra
effort: xhigh
permission-profile: "pull-request-review"
safety-strategy: drop-sudo
allow-bot-users: "astral-automations-bot[bot],renovate[bot]"
prompt-file: "${{ env.REVIEW_CONFIG }}/prompt.md"
output-schema-file: "${{ env.REVIEW_CONFIG }}/schema.json"
output-file: "${{ runner.temp }}/pull-request-code-quality-review-result.json"
- name: "Check reviewed checkout"
env:
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
if [ "$(git rev-parse HEAD)" != "$HEAD_SHA" ]; then
echo "The review changed the checked-out revision." >&2
exit 1
fi
git diff --no-ext-diff --no-textconv --exit-code HEAD --
- name: "Upload Codex thread"
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: codex-thread-pull-request-code-quality-review-${{ github.run_id }}-${{ github.run_attempt }}
path: ${{ env.REVIEW_CONFIG }}/codex/sessions
if-no-files-found: warn
prepare:
needs: review
if: needs.review.outputs.result != ''
runs-on: github-ubuntu-24.04-x86_64-4
timeout-minutes: 5
permissions:
contents: read
outputs:
result: ${{ steps.comments.outputs.result }}
steps:
- name: "Checkout review helpers"
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: astral-sh/github-actions
ref: 3c57a5dba8ad854a97e8b9fbf454286a7574e677
sparse-checkout: pull-request-review
persist-credentials: false
- uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
with:
# renovate: datasource=github-release-attachments depName=astral-sh/uv
version: "0.13.6"
checksum: "f29c3e94ffabd7e6f3ba521dba169a9b7ec12100bf3257087f0f24f6123f3645"
- name: "Prepare review findings"
id: comments
run: bash pull-request-review/scripts/prepare.sh
env:
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
REVIEW_RESULT: ${{ needs.review.outputs.result }}
report:
needs: prepare
if: needs.prepare.outputs.result != '' && fromJSON(needs.prepare.outputs.result).comments[0] != null
runs-on: github-ubuntu-24.04-x86_64-4
environment:
name: automations
deployment: false
timeout-minutes: 5
permissions:
contents: read
id-token: write # for the credential broker
steps:
- name: "Checkout review helpers"
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: astral-sh/github-actions
ref: 3c57a5dba8ad854a97e8b9fbf454286a7574e677
sparse-checkout: pull-request-review
persist-credentials: false
- name: "Get repository token"
id: token
uses: astral-sh/github-actions/simple-token-service@eb81cf4d13127c3f9539f621c17e4c65327636c8
with:
exchange-url: ${{ secrets.STS_API_URL }}/exchange
audience: ${{ secrets.STS_API_URL }}
repository: ${{ github.repository }}
permissions: |
pull_requests: write
- name: "Publish review findings"
run: bash pull-request-review/scripts/publish.sh
env:
GH_TOKEN: ${{ steps.token.outputs.token }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number }}
REVIEW_RESULT: ${{ needs.prepare.outputs.result }}