-
-
Notifications
You must be signed in to change notification settings - Fork 68
295 lines (256 loc) · 10 KB
/
dependencies.yml
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
# Automatically run `cargo update` periodically.
#
# Originally based on
# [Rust's own dependency-upgrading workflow](https://github.com/rust-lang/rust/blob/master/.github/workflows/dependencies.yml)
# and subsequently adapted to the needs of this project.
# Rust source code may be used under the terms of the MIT or Apache 2.0 licenses,
# which we do here.
---
name: Bump dependencies in Cargo.lock
on:
schedule:
# Run weekly early in the morning on Mondays.
- cron: '37 03 * * MON'
workflow_dispatch:
# Needed so we can run it manually
permissions:
contents: read
defaults:
run:
shell: bash
env:
MAIN_CARGO_PR_TITLE: Weekly `cargo update` of primary dependencies
MAIN_CARGO_PR_MESSAGE: |
Automation to keep dependencies in the primary `Cargo.lock` current.
The following is the output from `cargo update`:
FUZZ_CARGO_PR_TITLE: Weekly `cargo update` of fuzzing dependencies
FUZZ_CARGO_PR_MESSAGE: |
Automation to keep dependencies in the fuzzing `Cargo.lock` current.
The following is the output from `cargo update`:
CARGO_COMMIT_MESSAGE: "cargo update \n\n"
jobs:
update-main-cargo:
if: github.repository_owner == 'obi1kenobi'
name: update main dependencies
runs-on: ubuntu-latest
steps:
- name: checkout the source code
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Install rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
cache: false
- name: cargo update
# Remove first line that always just says "Updating crates.io index"
run: CARGO_TERM_COLOR=never cargo update 2>&1 | sed '/crates.io index/d' | tee -a cargo_update.log
- name: upload Cargo.lock artifact for use in PR
uses: actions/upload-artifact@v4
with:
name: main-Cargo-lock
path: Cargo.lock
retention-days: 1
- name: upload cargo-update log artifact for use in PR
uses: actions/upload-artifact@v4
with:
name: main-cargo-updates
path: cargo_update.log
retention-days: 1
pr-main-cargo:
if: github.repository_owner == 'obi1kenobi'
name: open or amend PR (main)
needs: update-main-cargo
runs-on: ubuntu-latest
env:
BRANCH_NAME: main_cargo_update
permissions:
contents: write
pull-requests: write
steps:
- name: checkout the source code
uses: actions/checkout@v4
with:
persist-credentials: true
- name: download Cargo.lock from update job
uses: actions/download-artifact@v4
with:
name: main-Cargo-lock
- name: download cargo-update log from update job
uses: actions/download-artifact@v4
with:
name: main-cargo-updates
- name: craft PR body and commit message
run: |
set -euo pipefail
echo "${CARGO_COMMIT_MESSAGE}" > commit.txt
cat cargo_update.log >> commit.txt
echo "${MAIN_CARGO_PR_MESSAGE}" > body.md
echo '```txt' >> body.md
cat cargo_update.log >> body.md
echo '```' >> body.md
- name: commit
run: |
set -euo pipefail
git config user.name github-actions
git config user.email github-actions@github.com
git switch --force-create "$BRANCH_NAME"
git add ./Cargo.lock
DIFF="$(git diff --staged)"
if [[ "$DIFF" == "" ]]; then
echo "Cargo.lock was not changed, bailing out and not making a PR"
exit 1
fi
git commit --no-verify --file=commit.txt
- name: push
run: |
set -euo pipefail
git push --no-verify --force --set-upstream origin "$BRANCH_NAME"
- name: edit existing open pull request
id: edit
# Don't fail job if we need to open new PR
continue-on-error: true
env:
# We have to use a Personal Access Token (PAT) here.
# PRs opened from a workflow using the standard `GITHUB_TOKEN` in GitHub Actions
# do not automatically trigger more workflows:
# https://docs.github.com/en/actions/security-guides/automatic-token-authentication#using-the-github_token-in-a-workflow
GITHUB_TOKEN: ${{ secrets.DEPS_UPDATER_GITHUB_TOKEN }}
run: |
set -euo pipefail
# Exit with error if PR is closed
STATE="$(gh pr view "$BRANCH_NAME" --repo "$GITHUB_REPOSITORY" --json state --jq '.state')"
if [[ "$STATE" != "OPEN" ]]; then
exit 1
fi
gh pr edit "$BRANCH_NAME" --title "${MAIN_CARGO_PR_TITLE}" --body-file body.md --repo "$GITHUB_REPOSITORY"
- name: open new pull request
# Only run if there wasn't an existing PR
if: steps.edit.outcome != 'success'
env:
# We have to use a Personal Access Token (PAT) here.
# PRs opened from a workflow using the standard `GITHUB_TOKEN` in GitHub Actions
# do not automatically trigger more workflows:
# https://docs.github.com/en/actions/security-guides/automatic-token-authentication#using-the-github_token-in-a-workflow
GITHUB_TOKEN: ${{ secrets.DEPS_UPDATER_GITHUB_TOKEN }}
run: |
set -euo pipefail
gh pr create --title "${MAIN_CARGO_PR_TITLE}" --body-file body.md --repo "$GITHUB_REPOSITORY" --label R-automated
- name: set PR to auto-merge
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh pr merge --squash --auto --delete-branch
update-fuzz-cargo:
if: github.repository_owner == 'obi1kenobi'
name: update fuzz dependencies
runs-on: ubuntu-latest
steps:
- name: checkout the source code
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Install rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
cache: false
- name: cargo update
# Remove first line that always just says "Updating crates.io index"
run: |
cd trustfall_core/fuzz/
CARGO_TERM_COLOR=never cargo update 2>&1 | sed '/crates.io index/d' | tee -a cargo_update.log
- name: upload Cargo.lock artifact for use in PR
uses: actions/upload-artifact@v4
with:
name: fuzz-Cargo-lock
path: trustfall_core/fuzz/Cargo.lock
retention-days: 1
- name: upload cargo-update log artifact for use in PR
uses: actions/upload-artifact@v4
with:
name: fuzz-cargo-updates
path: trustfall_core/fuzz/cargo_update.log
retention-days: 1
pr-fuzz-cargo:
if: github.repository_owner == 'obi1kenobi'
name: open or amend PR (fuzz)
needs: update-fuzz-cargo
runs-on: ubuntu-latest
env:
BRANCH_NAME: fuzz_cargo_update
permissions:
contents: write
pull-requests: write
steps:
- name: checkout the source code
uses: actions/checkout@v4
with:
persist-credentials: true
- name: download Cargo.lock from update job
uses: actions/download-artifact@v4
with:
name: fuzz-Cargo-lock
path: trustfall_core/fuzz/
- name: download cargo-update log from update job
uses: actions/download-artifact@v4
with:
name: fuzz-cargo-updates
- name: craft PR body and commit message
run: |
set -euo pipefail
echo "${CARGO_COMMIT_MESSAGE}" > commit.txt
cat cargo_update.log >> commit.txt
echo "${FUZZ_CARGO_PR_TITLE}" > body.md
echo '```txt' >> body.md
cat cargo_update.log >> body.md
echo '```' >> body.md
- name: commit
run: |
set -euo pipefail
git config user.name github-actions
git config user.email github-actions@github.com
git switch --force-create "$BRANCH_NAME"
git add ./trustfall_core/fuzz/Cargo.lock
DIFF="$(git diff --staged)"
if [[ "$DIFF" == "" ]]; then
echo "Cargo.lock was not changed, bailing out and not making a PR"
exit 1
fi
git commit --no-verify --file=commit.txt
- name: push
run: |
set -euo pipefail
git push --no-verify --force --set-upstream origin "$BRANCH_NAME"
- name: edit existing open pull request
id: edit
# Don't fail job if we need to open new PR
continue-on-error: true
env:
# We have to use a Personal Access Token (PAT) here.
# PRs opened from a workflow using the standard `GITHUB_TOKEN` in GitHub Actions
# do not automatically trigger more workflows:
# https://docs.github.com/en/actions/security-guides/automatic-token-authentication#using-the-github_token-in-a-workflow
GITHUB_TOKEN: ${{ secrets.DEPS_UPDATER_GITHUB_TOKEN }}
run: |
set -euo pipefail
# Exit with error if PR is closed
STATE="$(gh pr view "$BRANCH_NAME" --repo "$GITHUB_REPOSITORY" --json state --jq '.state')"
if [[ "$STATE" != "OPEN" ]]; then
exit 1
fi
gh pr edit "$BRANCH_NAME" --title "${FUZZ_CARGO_PR_TITLE}" --body-file body.md --repo "$GITHUB_REPOSITORY"
- name: open new pull request
# Only run if there wasn't an existing PR
if: steps.edit.outcome != 'success'
env:
# We have to use a Personal Access Token (PAT) here.
# PRs opened from a workflow using the standard `GITHUB_TOKEN` in GitHub Actions
# do not automatically trigger more workflows:
# https://docs.github.com/en/actions/security-guides/automatic-token-authentication#using-the-github_token-in-a-workflow
GITHUB_TOKEN: ${{ secrets.DEPS_UPDATER_GITHUB_TOKEN }}
run: |
set -euo pipefail
gh pr create --title "${FUZZ_CARGO_PR_TITLE}" --body-file body.md --repo "$GITHUB_REPOSITORY" --label R-automated
- name: set PR to auto-merge
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh pr merge --squash --auto --delete-branch