From 987fbf36ca5272deb2d4aefd99ed63af91a6aac6 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Mon, 23 Sep 2024 01:56:49 +0900 Subject: [PATCH] tools: Update scripts --- tools/publish.sh | 2 +- tools/tidy.sh | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/tools/publish.sh b/tools/publish.sh index 3d5a72c..d68525a 100755 --- a/tools/publish.sh +++ b/tools/publish.sh @@ -58,7 +58,7 @@ fi 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 +if ! git remote -v | grep -F origin | grep -Eq 'github\.com[:/]taiki-e/'; then bail "cannot publish a new release from fork repository" fi diff --git a/tools/tidy.sh b/tools/tidy.sh index f1ce9cb..a3f77c4 100755 --- a/tools/tidy.sh +++ b/tools/tidy.sh @@ -53,6 +53,16 @@ check_install() { fi done } +retry() { + for i in {1..10}; do + if "$@"; then + return 0 + else + sleep "${i}" + fi + done + "$@" +} error() { if [[ -n "${GITHUB_ACTIONS:-}" ]]; then printf '::error::%s\n' "$*" @@ -184,21 +194,21 @@ ls_files() { if [[ -n "$(ls_files '*.rs')" ]]; then info "checking Rust code style" check_config .rustfmt.toml - if [[ "${ostype}" == "solaris" ]] && [[ -n "${CI:-}" ]] && ! type -P cargo >/dev/null; then - warn "this check is skipped on Solaris due to installing cargo from upstream package manager is broken" - elif check_install cargo jq python3; then + if check_install cargo jq python3; then # `cargo fmt` cannot recognize files not included in the current workspace and modules # defined inside macros, so run rustfmt directly. # We need to use nightly rustfmt because we use the unstable formatting options of rustfmt. rustc_version=$(rustc -vV | grep -E '^release:' | cut -d' ' -f2) if [[ "${rustc_version}" =~ nightly|dev ]] || ! type -P rustup >/dev/null; then if type -P rustup >/dev/null; then - rustup component add rustfmt &>/dev/null + retry rustup component add rustfmt &>/dev/null fi info "running \`rustfmt \$(git ls-files '*.rs')\`" rustfmt $(ls_files '*.rs') else - rustup component add rustfmt --toolchain nightly &>/dev/null || true + if type -P rustup >/dev/null; then + retry rustup component add rustfmt --toolchain nightly &>/dev/null + fi info "running \`rustfmt +nightly \$(git ls-files '*.rs')\`" rustfmt +nightly $(ls_files '*.rs') fi