]> git.lizzy.rs Git - rust.git/blob - src/ci/publish_toolstate.sh
lowering: cleanup some hofs
[rust.git] / src / ci / publish_toolstate.sh
1 #!/bin/bash
2
3 set -euo pipefail
4 IFS=$'\n\t'
5
6 source "$(cd "$(dirname "$0")" && pwd)/shared.sh"
7
8 # The following lines are also found in src/bootstrap/toolstate.rs,
9 # so if updating here, please also update that file.
10
11 export MESSAGE_FILE=$(mktemp -t msg.XXXXXX)
12
13 git config --global user.email '7378925+rust-toolstate-update@users.noreply.github.com'
14 git config --global user.name 'Rust Toolstate Update'
15 git config --global credential.helper store
16 printf 'https://%s:x-oauth-basic@github.com\n' "$TOOLSTATE_REPO_ACCESS_TOKEN" \
17     > "$HOME/.git-credentials"
18 git clone --depth=1 $TOOLSTATE_REPO
19
20 GIT_COMMIT="$(git rev-parse HEAD)"
21 GIT_COMMIT_MSG="$(git log --format=%s -n1 HEAD)"
22
23 cd rust-toolstate
24 FAILURE=1
25 for RETRY_COUNT in 1 2 3 4 5; do
26     #  The purpose is to publish the new "current" toolstate in the toolstate repo.
27     "$(ciCheckoutPath)/src/tools/publish_toolstate.py" "$GIT_COMMIT" \
28         "$GIT_COMMIT_MSG" \
29         "$MESSAGE_FILE" \
30         "$TOOLSTATE_REPO_ACCESS_TOKEN"
31     # `git commit` failing means nothing to commit.
32     FAILURE=0
33     git commit -a -F "$MESSAGE_FILE" || break
34     # On failure randomly sleep for 0 to 3 seconds as a crude way to introduce jittering.
35     git push origin master && break || sleep $(LC_ALL=C tr -cd 0-3 < /dev/urandom | head -c 1)
36     FAILURE=1
37     git fetch origin master
38     git reset --hard origin/master
39 done