]> git.lizzy.rs Git - rust.git/blob - src/ci/docker/x86_64-gnu-tools/repo.sh
Auto merge of #50710 - Zoxc:value_to_constvalue, r=oli-obk
[rust.git] / src / ci / docker / x86_64-gnu-tools / repo.sh
1 #!/bin/sh
2
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.
6 #
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.
12
13 # This file provides the function `commit_toolstate_change` for pushing a change
14 # to the `rust-toolstate` repository.
15 #
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
19 # `appveyor.yml`:
20 #
21 #   1. Generate a new Personal access token:
22 #
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
29 #           the page.
30 #
31 #   2. Encrypt the token for Travis CI
32 #
33 #       * Install the `travis` tool locally (`gem install travis`).
34 #       * Encrypt the token:
35 #           ```
36 #           travis -r rust-lang/rust encrypt \
37 #                   TOOLSTATE_REPO_ACCESS_TOKEN=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
38 #           ```
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/>
42 #
43 #   3. Encrypt the token for AppVeyor
44 #
45 #       * Login to AppVeyor using your main account, and login as the rust-lang
46 #           organization.
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
49 #           "Encrypt"
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/>
53 #
54 #   4. Replace the email address below if the bot account identity is changed
55 #
56 #       * See <https://help.github.com/articles/about-commit-email-addresses/>
57 #           if a private email by GitHub is wanted.
58
59 commit_toolstate_change() {
60     OLDFLAGS="$-"
61     set -eu
62
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
69
70     cd rust-toolstate
71     FAILURE=1
72     MESSAGE_FILE="$1"
73     shift
74     for RETRY_COUNT in 1 2 3 4 5; do
75         "$@"
76         # `git commit` failing means nothing to commit.
77         FAILURE=0
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)
81         FAILURE=1
82         git fetch origin master
83         git reset --hard origin/master
84     done
85     cd ..
86
87     set +eu
88     set "-$OLDFLAGS"
89     return $FAILURE
90 }