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 `.azure-pipelines/*`.
10 # 1. Generate a new Personal access token:
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
20 # 2. Update the variable group in Azure Pipelines
22 # * Ping a member of the infrastructure team to do this.
24 # 4. Replace the email address below if the bot account identity is changed
26 # * See <https://help.github.com/articles/about-commit-email-addresses/>
27 # if a private email by GitHub is wanted.
29 commit_toolstate_change() {
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
44 for RETRY_COUNT in 1 2 3 4 5; do
46 # `git commit` failing means nothing to commit.
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)
52 git fetch origin master
53 git reset --hard origin/master