-
Notifications
You must be signed in to change notification settings - Fork 141
70 lines (61 loc) · 2.64 KB
/
update-rust.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
# A GitHub Actions workflow that regularly checks for new Rust toolchain release
# and creates a PR on new versions.
name: Rust Update
on:
schedule:
# check for new rust versions weekly
- cron: '30 3 * * FRI'
jobs:
rust-update:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# First, check rust GitHub releases for a new version. We assume that the
# latest version's tag name is the version.
- name: Check new rust version
id: update
run: |
current_rust_version=$(cat ./rust-toolchain.toml | sed -n 's/^channel[[:space:]]*=[[:space:]]"\(.*\)"/\1/p')
echo "current rust version '$current_rust_version'"
release_data=$(curl --silent -H 'Accept: application/vnd.github.v3+json' https://api.github.com/repos/rust-lang/rust/releases/latest)
latest_rust_version=$(echo -n "$release_data" | jq -cMr .tag_name)
# The GitHub API has some hiccups, so we check the value before going further
if [ -z "$latest_rust_version" ] || [ "$latest_rust_version" = "null" ]
then
echo "expected a rust version, got '$latest_rust_version'"
echo "data received from API:"
echo "$release_data"
exit 1
fi
echo "latest rust version '$latest_rust_version'"
if [ "$current_rust_version" != "$latest_rust_version" ]
then
echo rust toolchain needs an update
sed -i -e "s/$current_rust_version/$latest_rust_version/g" ./rust-toolchain.toml
echo "updated=1" >> "$GITHUB_OUTPUT"
else
echo "updated=0" >> "$GITHUB_OUTPUT"
fi
cat ./rust-toolchain.toml
# If the rust-toolchain was updated, create a PR.
- name: Create Pull Request
if: ${{ steps.update.outputs.updated == '1' }}
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GIX_BOT_PAT }}
base: main
add-paths: ./rust-toolchain.toml
commit-message: Update rust version
committer: GitHub <[email protected]>
author: gix-bot <[email protected]>
branch: bot-rust-update
delete-branch: true
title: 'Update rust version'
# Since the this is a scheduled job, a failure won't be shown on any
# PR status. To notify the team, we send a message to our Slack channel on failure.
- name: Notify Slack on failure
uses: ./.github/actions/slack
if: ${{ failure() }}
with:
WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
MESSAGE: "Rust update failed"