3 # This file provides the function `commit_toolstate_change` for pushing a change
4 # to the `rust-toolstate` repository.
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 the Azure Pipelines
11 # 1. Generate a new Personal access token:
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
21 # 2. Update the variable group in Azure Pipelines
23 # * Ping a member of the infrastructure team to do this.
25 # 4. Replace the email address below if the bot account identity is changed
27 # * See <https://help.github.com/articles/about-commit-email-addresses/>
28 # if a private email by GitHub is wanted.
30 commit_toolstate_change() {
34 git config --global user.email '7378925+rust-toolstate-update@users.noreply.github.com'
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"
39 git clone --depth=1 $TOOLSTATE_REPO
45 for RETRY_COUNT in 1 2 3 4 5; do
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.
54 # `git commit` failing means nothing to commit.
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)
60 git fetch origin master
61 git reset --hard origin/master