-
Notifications
You must be signed in to change notification settings - Fork 19
211 lines (183 loc) · 6.51 KB
/
Copy pathpr-fix.yml
File metadata and controls
211 lines (183 loc) · 6.51 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
name: pr-fix
on:
issue_comment:
types:
- created
permissions:
contents: write
issues: read
pull-requests: read
concurrency:
group: ${{ github.workflow }}-${{ github.event.issue.number }}
cancel-in-progress: true
defaults:
run:
shell: bash -xe {0}
jobs:
load-pr:
if: >
github.event.issue.pull_request &&
github.event.comment.body == 'fix' &&
contains(fromJson('["OWNER","MEMBER","COLLABORATOR"]'), github.event.comment.author_association)
outputs:
head_ref: ${{ steps.pr.outputs.head_ref }}
head_sha: ${{ steps.pr.outputs.head_sha }}
head_repo: ${{ steps.pr.outputs.head_repo }}
base_repo: ${{ steps.pr.outputs.base_repo }}
runs-on: ubuntu-24.04
steps:
- name: Load PR metadata
id: pr
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_API_URL: ${{ github.event.issue.pull_request.url }}
run: |
curl -fsSL \
-H "Authorization: Bearer ${GH_TOKEN}" \
-H "Accept: application/vnd.github+json" \
"${PR_API_URL}" > /tmp/pr.json
{
echo "head_ref=$(jq -r '.head.ref' /tmp/pr.json)"
echo "head_sha=$(jq -r '.head.sha' /tmp/pr.json)"
echo "head_repo=$(jq -r '.head.repo.full_name' /tmp/pr.json)"
echo "base_repo=$(jq -r '.base.repo.full_name' /tmp/pr.json)"
} >> "$GITHUB_OUTPUT"
- name: Reject fork PRs
run: |
if [ "${{ steps.pr.outputs.head_repo }}" != "${{ steps.pr.outputs.base_repo }}" ]; then
echo "::error::fix only supports pull requests from branches in ${GITHUB_REPOSITORY}."
exit 1
fi
fix-part:
needs: load-pr
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
include:
- part: schemas
artifact: pr-fix-schemas
commit_message: "chore: Update schemas"
needs_postgres: "false"
needs_rust_cache: "false"
- part: snapshots
artifact: pr-fix-snapshots
commit_message: "chore: Update snapshots"
needs_postgres: "true"
needs_rust_cache: "true"
- part: clippy
artifact: pr-fix-clippy
commit_message: "chore: Run clippy"
needs_postgres: "false"
needs_rust_cache: "true"
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:
repository: ${{ needs.load-pr.outputs.head_repo }}
ref: ${{ needs.load-pr.outputs.head_sha }}
fetch-depth: 0
persist-credentials: false
- name: Configure git identity
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Free disk space
run: |
df -h
sudo rm -rf /usr/share/dotnet
sudo rm -rf /usr/local/lib/android
sudo rm -rf /opt/ghc
sudo rm -rf /opt/hostedtoolcache
docker system prune -af || true
df -h
- uses: nixbuild/nix-quick-install-action@2c9db80fb984ceb1bcaa77cdda3fdf8cfba92035
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}
- name: Start postgres
if: matrix.needs_postgres == 'true'
run: docker run -d -e POSTGRES_PASSWORD=postgres -p 5432:5432 postgres:18
- name: Populate the nix store
run: nix develop --command echo
- uses: Swatinem/rust-cache@c19371144df3bb44fab255c43d04cbc2ab54d1c4 # v2.9.1
if: matrix.needs_rust_cache == 'true'
with:
cache-on-failure: true
key: pr-fix-${{ matrix.part }}
- name: Run fixer
env:
CI: true
INSTA_UPDATE: always
TEST_POSTGRES_HOST: "localhost"
TEST_POSTGRES_USER: "postgres"
TEST_POSTGRES_PASSWORD: "postgres"
TEST_POSTGRES_DATABASE_PREFIX: "obelisk_test"
run: |
case "${{ matrix.part }}" in
schemas)
nix develop --command scripts/update-schemas.sh
;;
snapshots)
find . -name '*.snap' -delete
nix develop --command scripts/test.sh
;;
clippy)
nix develop --command scripts/clippy.sh
;;
esac
- name: Create patch artifact
run: |
mkdir -p ".pr-fix/${{ matrix.part }}"
printf '%s\n' "${{ matrix.part }}" > ".pr-fix/${{ matrix.part }}/part.txt"
git add -A
if git diff --cached --quiet; then
echo "No changes for ${{ matrix.part }}"
printf 'false\n' > ".pr-fix/${{ matrix.part }}/changed.txt"
else
git commit -m "${{ matrix.commit_message }}"
git format-patch --stdout HEAD~1 > ".pr-fix/${{ matrix.part }}/update.patch"
printf 'true\n' > ".pr-fix/${{ matrix.part }}/changed.txt"
fi
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a
with:
name: ${{ matrix.artifact }}
path: .pr-fix/${{ matrix.part }}
combine-fixes:
needs:
- load-pr
- fix-part
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
with:
repository: ${{ needs.load-pr.outputs.head_repo }}
ref: ${{ needs.load-pr.outputs.head_ref }}
fetch-depth: 0
persist-credentials: false
- name: Configure git identity
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- uses: actions/download-artifact@v4
with:
pattern: pr-fix-*
path: /tmp/pr-fix-artifacts
- name: Apply patches
run: |
for part in schemas snapshots clippy; do
patch_file="/tmp/pr-fix-artifacts/pr-fix-${part}/update.patch"
if [ ! -f "${patch_file}" ]; then
echo "No patch for ${part}"
continue
fi
git am --3way "${patch_file}"
done
- name: Push changes
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if git diff --quiet HEAD origin/"${{ needs.load-pr.outputs.head_ref }}"; then
echo "No commits to push"
exit 0
fi
git push "https://x-access-token:${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" \
HEAD:${{ needs.load-pr.outputs.head_ref }}