3 # Copyright 2017 The Rust Project Developers. See the COPYRIGHT
4 # file at the top-level directory of this distribution and at
5 # http://rust-lang.org/COPYRIGHT.
7 # Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
8 # http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
9 # <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
10 # option. This file may not be copied, modified, or distributed
11 # except according to those terms.
13 # This file provides the function `commit_toolstate_change` for pushing a change
14 # to the `rust-toolstate` repository.
16 # The function relies on a GitHub bot user, which should have a Personal access
17 # token defined in the environment variable $TOOLSTATE_REPO_ACCESS_TOKEN. If for
18 # some reason you need to change the token, please update `.travis.yml` and
21 # 1. Generate a new Personal access token:
23 # * Login to the bot account, and go to Settings -> Developer settings ->
24 # Personal access tokens
25 # * Click "Generate new token"
26 # * Enable the "public_repo" permission, then click "Generate token"
27 # * Copy the generated token (should be a 40-digit hexadecimal number).
28 # Save it somewhere secure, as the token would be gone once you leave
31 # 2. Encrypt the token for Travis CI
33 # * Install the `travis` tool locally (`gem install travis`).
34 # * Encrypt the token:
36 # travis -r rust-lang/rust encrypt \
37 # TOOLSTATE_REPO_ACCESS_TOKEN=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
39 # * Copy output to replace the existing one in `.travis.yml`.
40 # * Details of this step can be found in
41 # <https://docs.travis-ci.com/user/encryption-keys/>
43 # 3. Encrypt the token for AppVeyor
45 # * Login to AppVeyor using your main account, and login as the rust-lang
47 # * Open the ["Encrypt data" tool](https://ci.appveyor.com/tools/encrypt)
48 # * Paste the 40-digit token into the "Value to encrypt" box, then click
50 # * Copy the output to replace the existing one in `appveyor.yml`.
51 # * Details of this step can be found in
52 # <https://www.appveyor.com/docs/how-to/git-push/>
54 # 4. Replace the email address below if the bot account identity is changed
56 # * See <https://help.github.com/articles/about-commit-email-addresses/>
57 # if a private email by GitHub is wanted.
59 commit_toolstate_change() {
63 git config --global user.email '7378925+rust-toolstate-update@users.noreply.github.com'
64 git config --global user.name 'Rust Toolstate Update'
65 git config --global credential.helper store
66 printf 'https://%s:x-oauth-basic@github.com\n' "$TOOLSTATE_REPO_ACCESS_TOKEN" \
67 > "$HOME/.git-credentials"
68 git clone --depth=1 https://github.com/rust-lang-nursery/rust-toolstate.git
74 for RETRY_COUNT in 1 2 3 4 5; do
76 # `git commit` failing means nothing to commit.
78 git commit -a -F "$MESSAGE_FILE" || break
79 # On failure randomly sleep for 0 to 3 seconds as a crude way to introduce jittering.
80 git push origin master && break || sleep $(LC_ALL=C tr -cd 0-3 < /dev/urandom | head -c 1)
82 git fetch origin master
83 git reset --hard origin/master