@@ -16,121 +16,99 @@ defaults:
16
16
env :
17
17
# So cargo doesn't complain about unstable features
18
18
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 "
25
19
26
20
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
-
46
21
update :
47
22
if : github.repository_owner == 'rust-lang'
48
23
name : update dependencies
49
- needs : not-waiting-on-bors
50
24
runs-on : ubuntu-latest
25
+ outputs :
26
+ lockfile_names : ${{ steps.update_script.outputs.lockfile_names }}
51
27
steps :
52
28
- name : checkout the source code
53
29
uses : actions/checkout@v4
54
30
with :
55
31
submodules : recursive
32
+
56
33
- name : install the bootstrap toolchain
57
34
run : |
58
35
# Extract the stage0 version
59
- TOOLCHAIN =$(awk -F= '{a[$1]=$2} END {print(a["compiler_version"] "-" a["compiler_date"])}' src/stage0)
36
+ toolchain =$(awk -F= '{a[$1]=$2} END {print(a["compiler_version"] "-" a["compiler_date"])}' src/stage0)
60
37
# Install and set as default
61
- rustup toolchain install --no-self-update --profile minimal $TOOLCHAIN
62
- rustup default $TOOLCHAIN
38
+ rustup toolchain install --no-self-update --profile minimal "$toolchain"
39
+ rustup default "$toolchain"
63
40
64
- - name : cargo update compiler & tools
65
- # Remove first line that always just says "Updating crates.io index"
41
+ - name : run update script
42
+ id : update_script
66
43
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
74
- 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
44
+ # Update all lockfiles
45
+ ./src/ci/scripts/update-all-lockfiles.py --run-update
46
+ # Make a list of which lockfiles were updated for future use
47
+ lockfile_names="$(./src/ci/scripts/update-all-lockfiles.py --print-names)"
48
+ echo "lockfile_names=$lockfile_names" >> "$GITHUB_OUTPUT"
49
+
50
+ - name : upload output file
87
51
uses : actions/upload-artifact@v4
88
52
with :
89
- name : cargo-updates
90
- path : cargo_update.log
53
+ name : update-output
54
+ path : update_output.json
91
55
retention-days : 1
92
56
93
- pr :
57
+ check_bors_status :
94
58
if : github.repository_owner == 'rust-lang'
95
- name : amend PR
59
+ name : check for S-waiting-on-bors
60
+ runs-on : ubuntu-latest
96
61
needs : update
62
+ outputs :
63
+ skip_keys : ${{ steps.check_status.outputs.skip_keys }}
64
+ steps :
65
+ - env :
66
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
67
+ id : check_status
68
+ run : |
69
+ # Build a json array of items to skip
70
+ skip_keys="$(./src/ci/scripts/update-all-lockfiles.py --list-skip-branches)"
71
+ echo "skip_keys=$skip_keys" >> "$GITHUB_OUTPUT"
72
+
73
+ pr :
74
+ name : create or update PR
75
+ needs : [update, check_bors_status]
76
+ strategy :
77
+ fail-fast : false
78
+ matrix :
79
+ name : ${{ fromJson(needs.update.outputs.lockfile_names) }}
80
+ if : >
81
+ github.repository_owner == 'rust-lang' &&
82
+ !contains(fromJSON(needs.check_bors_status.outputs.skip_keys), matrix.name)
97
83
runs-on : ubuntu-latest
98
84
permissions :
99
85
contents : write
100
86
pull-requests : write
87
+ env :
88
+ PR_TITLE : Weekly ${{ matrix.name }} `cargo update`
89
+ BRANCH : cargo-update-${{ matrix.name }}
101
90
steps :
102
91
- name : checkout the source code
103
92
uses : actions/checkout@v4
104
93
105
- - name : download Cargo.lock from update job
94
+ - name : download output file from update job
106
95
uses : actions/download-artifact@v4
107
96
with :
108
- name : Cargo-lock
109
- - name : download cargo-update log from update job
110
- uses : actions/download-artifact@v4
111
- with :
112
- name : cargo-updates
97
+ name : update-output
113
98
114
99
- name : craft PR body and commit message
115
- run : |
116
- echo "${COMMIT_MESSAGE}" > commit.txt
117
- cat cargo_update.log >> commit.txt
118
-
119
- echo "${PR_MESSAGE}" > body.md
120
- echo '```txt' >> body.md
121
- cat cargo_update.log >> body.md
122
- echo '```' >> body.md
100
+ run : ./src/ci/scripts/update-all-lockfiles.py --prepare-pr-files "${{ matrix.name }}"
123
101
124
102
- name : commit
125
103
run : |
126
104
git config user.name github-actions
127
105
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
106
+ git switch --force-create "$BRANCH"
107
+ git add "$(jq -r '.${{ matrix.name }}.lockfile_path' update_output.json)"
130
108
git commit --no-verify --file=commit.txt
131
109
132
110
- 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"
134
112
135
113
- name : edit existing open pull request
136
114
id : edit
@@ -140,16 +118,16 @@ jobs:
140
118
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
141
119
run : |
142
120
# 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
121
+ state =$(gh pr view "$BRANCH" --repo " $GITHUB_REPOSITORY" --json state --jq '.state')
122
+ if [[ "$state " != "OPEN" ]]; then
145
123
exit 1
146
124
fi
147
125
148
- gh pr edit cargo_update --title "${ PR_TITLE} " --body-file body .md --repo $GITHUB_REPOSITORY
126
+ gh pr edit "$BRANCH" --title "$PR_TITLE" --body-file pr_body .md --repo " $GITHUB_REPOSITORY"
149
127
150
128
- name : open new pull request
151
129
# Only run if there wasn't an existing PR
152
130
if : steps.edit.outcome != 'success'
153
131
env :
154
132
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
155
- run : gh pr create --title "${ PR_TITLE} " --body-file body .md --repo $GITHUB_REPOSITORY
133
+ run : gh pr create --title "$PR_TITLE" --body-file pr_body .md --repo " $GITHUB_REPOSITORY"
0 commit comments