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