]>
Commit | Line | Data |
---|---|---|
ff7c6d11 XL |
1 | #!/bin/sh |
2 | ||
ff7c6d11 XL |
3 | # This file provides the function `commit_toolstate_change` for pushing a change |
4 | # to the `rust-toolstate` repository. | |
5 | # | |
6 | # The function relies on a GitHub bot user, which should have a Personal access | |
7 | # token defined in the environment variable $TOOLSTATE_REPO_ACCESS_TOKEN. If for | |
416331ca XL |
8 | # some reason you need to change the token, please update the Azure Pipelines |
9 | # variable group. | |
ff7c6d11 XL |
10 | # |
11 | # 1. Generate a new Personal access token: | |
12 | # | |
13 | # * Login to the bot account, and go to Settings -> Developer settings -> | |
14 | # Personal access tokens | |
15 | # * Click "Generate new token" | |
16 | # * Enable the "public_repo" permission, then click "Generate token" | |
17 | # * Copy the generated token (should be a 40-digit hexadecimal number). | |
18 | # Save it somewhere secure, as the token would be gone once you leave | |
19 | # the page. | |
20 | # | |
416331ca | 21 | # 2. Update the variable group in Azure Pipelines |
ff7c6d11 | 22 | # |
416331ca | 23 | # * Ping a member of the infrastructure team to do this. |
ff7c6d11 XL |
24 | # |
25 | # 4. Replace the email address below if the bot account identity is changed | |
26 | # | |
27 | # * See <https://help.github.com/articles/about-commit-email-addresses/> | |
28 | # if a private email by GitHub is wanted. | |
29 | ||
30 | commit_toolstate_change() { | |
31 | OLDFLAGS="$-" | |
32 | set -eu | |
33 | ||
94b46f34 | 34 | git config --global user.email '7378925+rust-toolstate-update@users.noreply.github.com' |
ff7c6d11 XL |
35 | git config --global user.name 'Rust Toolstate Update' |
36 | git config --global credential.helper store | |
37 | printf 'https://%s:x-oauth-basic@github.com\n' "$TOOLSTATE_REPO_ACCESS_TOKEN" \ | |
38 | > "$HOME/.git-credentials" | |
dc9dc135 | 39 | git clone --depth=1 $TOOLSTATE_REPO |
ff7c6d11 XL |
40 | |
41 | cd rust-toolstate | |
42 | FAILURE=1 | |
43 | MESSAGE_FILE="$1" | |
44 | shift | |
45 | for RETRY_COUNT in 1 2 3 4 5; do | |
416331ca XL |
46 | # Call the callback. |
47 | # - If we are in the `auto` branch (pre-landing), this is called from `checktools.sh` and | |
48 | # the callback is `change_toolstate` in that file. The purpose of this is to publish the | |
49 | # test results (the new commit-to-toolstate mapping) in the toolstate repo. | |
50 | # - If we are in the `master` branch (post-landing), this is called by the CI pipeline | |
51 | # and the callback is `src/tools/publish_toolstate.py`. The purpose is to publish | |
52 | # the new "current" toolstate in the toolstate repo. | |
ff7c6d11 XL |
53 | "$@" |
54 | # `git commit` failing means nothing to commit. | |
55 | FAILURE=0 | |
56 | git commit -a -F "$MESSAGE_FILE" || break | |
57 | # On failure randomly sleep for 0 to 3 seconds as a crude way to introduce jittering. | |
58 | git push origin master && break || sleep $(LC_ALL=C tr -cd 0-3 < /dev/urandom | head -c 1) | |
59 | FAILURE=1 | |
60 | git fetch origin master | |
61 | git reset --hard origin/master | |
62 | done | |
63 | cd .. | |
64 | ||
65 | set +eu | |
66 | set "-$OLDFLAGS" | |
67 | return $FAILURE | |
68 | } |