]> git.lizzy.rs Git - rust.git/blob - src/ci/docker/x86_64-gnu-tools/repo.sh
Simplify SaveHandler trait
[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         "$@"
46         # `git commit` failing means nothing to commit.
47         FAILURE=0
48         git commit -a -F "$MESSAGE_FILE" || break
49         # On failure randomly sleep for 0 to 3 seconds as a crude way to introduce jittering.
50         git push origin master && break || sleep $(LC_ALL=C tr -cd 0-3 < /dev/urandom | head -c 1)
51         FAILURE=1
52         git fetch origin master
53         git reset --hard origin/master
54     done
55     cd ..
56
57     set +eu
58     set "-$OLDFLAGS"
59     return $FAILURE
60 }