Skip to content

Commit 7aac0ed

Browse files
committed
Adjust the weekly dependency update job to create separate PRs
Previously there was only one main workspace; within the past few months, it was split into three (root, library, and rustbook). These workspaces have somewhat different requirements for what can be updated and what may be problematic, and making one large PR for everything doesn't suit this well. Change the jobs to create separate pull requests for each relevant update. This will also make it easier to create a distinct job for bootstrap.
1 parent 33c245b commit 7aac0ed

File tree

2 files changed

+302
-77
lines changed

2 files changed

+302
-77
lines changed

.github/workflows/dependencies.yml

+54-77
Original file line numberDiff line numberDiff line change
@@ -16,84 +16,63 @@ defaults:
1616
env:
1717
# So cargo doesn't complain about unstable features
1818
RUSTC_BOOTSTRAP: 1
19-
PR_TITLE: Weekly `cargo update`
20-
PR_MESSAGE: |
21-
Automation to keep dependencies in `Cargo.lock` current.
22-
23-
The following is the output from `cargo update`:
24-
COMMIT_MESSAGE: "cargo update \n\n"
2519

2620
jobs:
27-
not-waiting-on-bors:
28-
if: github.repository_owner == 'rust-lang'
29-
name: skip if S-waiting-on-bors
30-
runs-on: ubuntu-latest
31-
steps:
32-
- env:
33-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34-
run: |
35-
# Fetch state and labels of PR
36-
# Or exit successfully if PR does not exist
37-
JSON=$(gh pr view cargo_update --repo $GITHUB_REPOSITORY --json labels,state || exit 0)
38-
STATE=$(echo "$JSON" | jq -r '.state')
39-
WAITING_ON_BORS=$(echo "$JSON" | jq '.labels[] | any(.name == "S-waiting-on-bors"; .)')
40-
41-
# Exit with error if open and S-waiting-on-bors
42-
if [[ "$STATE" == "OPEN" && "$WAITING_ON_BORS" == "true" ]]; then
43-
exit 1
44-
fi
45-
4621
update:
4722
if: github.repository_owner == 'rust-lang'
4823
name: update dependencies
49-
needs: not-waiting-on-bors
5024
runs-on: ubuntu-latest
25+
outputs:
26+
all_lockfiles: ${{ steps.update_script.outputs.all_lockfiles }}
27+
enqueued_lockfiles: ${{ steps.update_script.outputs.enqueued_lockfiles }}
5128
steps:
5229
- name: checkout the source code
5330
uses: actions/checkout@v4
5431
with:
5532
submodules: recursive
33+
5634
- name: install the bootstrap toolchain
5735
run: |
5836
# Extract the stage0 version
59-
TOOLCHAIN=$(awk -F= '{a[$1]=$2} END {print(a["compiler_version"] "-" a["compiler_date"])}' src/stage0)
37+
toolchain=$(awk -F= '{a[$1]=$2} END {print(a["compiler_version"] "-" a["compiler_date"])}' src/stage0)
6038
# Install and set as default
61-
rustup toolchain install --no-self-update --profile minimal $TOOLCHAIN
62-
rustup default $TOOLCHAIN
39+
rustup toolchain install --no-self-update --profile minimal "$toolchain"
40+
rustup default "$toolchain"
6341
64-
- name: cargo update compiler & tools
65-
# Remove first line that always just says "Updating crates.io index"
66-
run: |
67-
echo -e "\ncompiler & tools dependencies:" >> cargo_update.log
68-
cargo update 2>&1 | sed '/crates.io index/d' | tee -a cargo_update.log
69-
- name: cargo update library
70-
run: |
71-
echo -e "\nlibrary dependencies:" >> cargo_update.log
72-
cargo update --manifest-path library/Cargo.toml 2>&1 | sed '/crates.io index/d' | tee -a cargo_update.log
73-
- name: cargo update rustbook
42+
- name: run update script
43+
id: update_script
44+
env:
45+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7446
run: |
75-
echo -e "\nrustbook dependencies:" >> cargo_update.log
76-
cargo update --manifest-path src/tools/rustbook/Cargo.toml 2>&1 | sed '/crates.io index/d' | tee -a cargo_update.log
77-
- name: upload Cargo.lock artifact for use in PR
78-
uses: actions/upload-artifact@v4
79-
with:
80-
name: Cargo-lock
81-
path: |
82-
Cargo.lock
83-
library/Cargo.lock
84-
src/tools/rustbook/Cargo.lock
85-
retention-days: 1
86-
- name: upload cargo-update log artifact for use in PR
47+
# Update all lockfiles
48+
./src/ci/scripts/update-all-lockfiles.py --run-update
49+
50+
# Make a list of all lockfiles that we manage, as well as a list of
51+
# those that already have PRs in the queue. Save this for use in
52+
# later jobs.
53+
all_lockfiles="$(./src/ci/scripts/update-all-lockfiles.py --list-all)"
54+
enqueued_lockfiles="$(./src/ci/scripts/update-all-lockfiles.py --list-enqueued)"
55+
echo "all_lockfiles=$all_lockfiles" >> "$GITHUB_OUTPUT"
56+
echo "enqueued_lockfiles=$enqueued_lockfiles" >> "$GITHUB_OUTPUT"
57+
58+
- name: upload output file
8759
uses: actions/upload-artifact@v4
8860
with:
89-
name: cargo-updates
90-
path: cargo_update.log
61+
name: update-output
62+
path: update_output.json
9163
retention-days: 1
9264

9365
pr:
94-
if: github.repository_owner == 'rust-lang'
95-
name: amend PR
96-
needs: update
66+
name: create or update PR
67+
needs: [update]
68+
strategy:
69+
fail-fast: false
70+
matrix:
71+
name: ${{ fromJson(needs.update.outputs.all_lockfiles) }}
72+
# Don't run the job for a branch if a merge is already in progress.
73+
if: >
74+
github.repository_owner == 'rust-lang' &&
75+
!contains(fromJSON(needs.update.outputs.enqueued_lockfiles), matrix.name)
9776
runs-on: ubuntu-latest
9877
permissions:
9978
contents: write
@@ -102,35 +81,34 @@ jobs:
10281
- name: checkout the source code
10382
uses: actions/checkout@v4
10483

105-
- name: download Cargo.lock from update job
106-
uses: actions/download-artifact@v4
107-
with:
108-
name: Cargo-lock
109-
- name: download cargo-update log from update job
84+
- name: download output file from update job
11085
uses: actions/download-artifact@v4
11186
with:
112-
name: cargo-updates
87+
name: update-output
11388

11489
- name: craft PR body and commit message
11590
run: |
116-
echo "${COMMIT_MESSAGE}" > commit.txt
117-
cat cargo_update.log >> commit.txt
91+
# Create `commit.txt` and `pr_body.md`
92+
./src/ci/scripts/update-all-lockfiles.py --prepare-pr-files "${{ matrix.name }}"
11893
119-
echo "${PR_MESSAGE}" > body.md
120-
echo '```txt' >> body.md
121-
cat cargo_update.log >> body.md
122-
echo '```' >> body.md
94+
# Set some environment variables from the JSON file
95+
echo "BRANCH=$(jq -r '.${{ matrix.name }}.branch' update_output.json)" >> "$GITHUB_ENV"
96+
echo "PR_TITLE=$(jq -r '.${{ matrix.name }}.pr_title' update_output.json)" >> "$GITHUB_ENV"
12397
12498
- name: commit
12599
run: |
126100
git config user.name github-actions
127101
git config user.email [email protected]
128-
git switch --force-create cargo_update
129-
git add ./Cargo.lock ./library/Cargo.lock ./src/tools/rustbook/Cargo.lock
102+
git switch --force-create "$BRANCH"
103+
104+
# Update and add only the relevant lockfile
105+
./src/ci/scripts/update-all-lockfiles.py --restore-lockfile "${{ matrix.name }}"
106+
git add "$(jq -r '.${{ matrix.name }}.lockfile_path' update_output.json)"
107+
130108
git commit --no-verify --file=commit.txt
131109
132110
- name: push
133-
run: git push --no-verify --force --set-upstream origin cargo_update
111+
run: git push --no-verify --force --set-upstream origin "$BRANCH"
134112

135113
- name: edit existing open pull request
136114
id: edit
@@ -140,16 +118,15 @@ jobs:
140118
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
141119
run: |
142120
# Exit with error if PR is closed
143-
STATE=$(gh pr view cargo_update --repo $GITHUB_REPOSITORY --json state --jq '.state')
144-
if [[ "$STATE" != "OPEN" ]]; then
145-
exit 1
146-
fi
121+
state=$(gh pr view "$BRANCH" --repo "$GITHUB_REPOSITORY" --json state --jq '.state')
122+
[ "$state" != "OPEN" ] && exit 1
147123
148-
gh pr edit cargo_update --title "${PR_TITLE}" --body-file body.md --repo $GITHUB_REPOSITORY
124+
# Replace the title and body with what we generated
125+
gh pr edit "$BRANCH" --title "$PR_TITLE" --body-file pr_body.md --repo "$GITHUB_REPOSITORY"
149126
150127
- name: open new pull request
151128
# Only run if there wasn't an existing PR
152129
if: steps.edit.outcome != 'success'
153130
env:
154131
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
155-
run: gh pr create --title "${PR_TITLE}" --body-file body.md --repo $GITHUB_REPOSITORY
132+
run: gh pr create --title "$PR_TITLE" --body-file pr_body.md --repo "$GITHUB_REPOSITORY"

0 commit comments

Comments
 (0)