-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This re-adds install-rust action removed in a91c37d. rustup sometimes fails due to temporary network problems even when RUSTUP_MAX_RETRIES is set, so an action with retry is needed.
- Loading branch information
Showing
6 changed files
with
174 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# install-rust | ||
|
||
GitHub Action for installing Rust toolchain. | ||
There is no stability guarantee for this action, since it's supposed to only be | ||
used in infra managed by us. | ||
|
||
## Usage | ||
|
||
See [action.yml](action.yml) | ||
|
||
```yaml | ||
- uses: taiki-e/github-actions/install-rust@main | ||
with: | ||
# Default toolchain to install. | ||
toolchain: stable | ||
# Components to add (comma-separated), default is empty. | ||
component: rustfmt,clippy | ||
# Targets to add (comma-separated), default is empty. | ||
target: x86_64-unknown-linux-musl | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: install-rust | ||
description: GitHub Action for installing Rust toolchain | ||
|
||
inputs: | ||
toolchain: | ||
description: Default toolchain to install | ||
required: true | ||
# default: #publish:toolchain | ||
component: | ||
description: Components to add (comma-separated) | ||
required: false | ||
target: | ||
description: Targets to add (comma-separated) | ||
required: false | ||
|
||
# Note: | ||
# - inputs.* should be manually mapped to INPUT_* due to https://github.com/actions/runner/issues/665 | ||
# - Use GITHUB_*/RUNNER_* instead of github.*/runner.* due to https://github.com/actions/runner/issues/2185 | ||
runs: | ||
using: composite | ||
steps: | ||
- run: bash --noprofile --norc "${GITHUB_ACTION_PATH:?}/main.sh" | ||
shell: bash | ||
env: | ||
INPUT_TOOLCHAIN: ${{ inputs.toolchain }} | ||
INPUT_COMPONENT: ${{ inputs.component }} | ||
INPUT_TARGET: ${{ inputs.target }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/env bash | ||
# SPDX-License-Identifier: Apache-2.0 OR MIT | ||
set -CeEuo pipefail | ||
IFS=$'\n\t' | ||
trap -- 's=$?; printf >&2 "%s\n" "${0##*/}:${LINENO}: \`${BASH_COMMAND}\` exit with ${s}"; exit ${s}' ERR | ||
|
||
g() { | ||
IFS=' ' | ||
local cmd="$*" | ||
IFS=$'\n\t' | ||
printf '::group::%s\n' "${cmd#retry }" | ||
"$@" | ||
printf '::endgroup::\n' | ||
} | ||
retry() { | ||
for i in {1..10}; do | ||
if "$@"; then | ||
return 0 | ||
else | ||
sleep "${i}" | ||
fi | ||
done | ||
"$@" | ||
} | ||
|
||
export RUSTUP_MAX_RETRIES="${RUSTUP_MAX_RETRIES:-10}" | ||
|
||
# --no-self-update is necessary because the windows environment cannot self-update rustup.exe. | ||
rustup_args=(--no-self-update --profile minimal) | ||
toolchain="${INPUT_TOOLCHAIN:?}" | ||
if [[ -n "${INPUT_COMPONENT:-}" ]]; then | ||
rustup_args+=("--component=${INPUT_COMPONENT}") | ||
fi | ||
if [[ -n "${INPUT_TARGET:-}" ]]; then | ||
rustup_args+=("--target=${INPUT_TARGET}") | ||
fi | ||
|
||
g retry rustup toolchain add "${toolchain}" "${rustup_args[@]}" | ||
|
||
g rustup default "${toolchain}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#!/usr/bin/env bash | ||
# SPDX-License-Identifier: Apache-2.0 OR MIT | ||
set -CeEuo pipefail | ||
IFS=$'\n\t' | ||
trap -- 's=$?; printf >&2 "%s\n" "${0##*/}:${LINENO}: \`${BASH_COMMAND}\` exit with ${s}"; exit ${s}' ERR | ||
cd -- "$(dirname -- "$0")"/.. | ||
|
||
# Update stable/beta/nightly branches. | ||
# | ||
# USAGE: | ||
# ./install-rust/update-branch.sh | ||
|
||
retry() { | ||
for i in {1..10}; do | ||
if "$@"; then | ||
return 0 | ||
else | ||
sleep "${i}" | ||
fi | ||
done | ||
"$@" | ||
} | ||
bail() { | ||
printf >&2 'error: %s\n' "$*" | ||
exit 1 | ||
} | ||
|
||
if [[ $# -gt 1 ]]; then | ||
bail "invalid argument '$2'" | ||
fi | ||
if { sed --help 2>&1 || true; } | grep -Eq -e '-i extension'; then | ||
in_place=(-i '') | ||
else | ||
in_place=(-i) | ||
fi | ||
|
||
# Make sure there is no uncommitted change. | ||
git diff --exit-code | ||
git diff --exit-code --staged | ||
|
||
# Make sure that the release was created from an allowed branch. | ||
if ! git branch | grep -Eq '\* main$'; then | ||
bail "current branch is not 'main'" | ||
fi | ||
if ! git remote -v | grep -F origin | grep -Eq 'github\.com[:/]taiki-e/'; then | ||
bail "cannot publish a new release from fork repository" | ||
fi | ||
|
||
set -x | ||
|
||
retry git push origin main | ||
|
||
toolchains=( | ||
stable | ||
beta | ||
nightly | ||
) | ||
|
||
for toolchain in "${toolchains[@]}"; do | ||
git checkout -b "${toolchain}" | ||
sed -E "${in_place[@]}" "s/required: true/required: false/g" install-rust/action.yml | ||
sed -E "${in_place[@]}" "s/# default: #publish:toolchain/default: ${toolchain}/g" install-rust/action.yml | ||
git add install-rust/action.yml | ||
git commit -m "${toolchain}" | ||
retry git push origin -f refs/heads/"${toolchain}" | ||
git checkout main | ||
git branch -D "${toolchain}" | ||
done |