From 1c886d8897bc1fa27a46849f029e1f01cd46e904 Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Wed, 9 Aug 2023 19:37:26 +1000 Subject: [PATCH] Fix installation script on MacOS (#1263) Fixed #1254 and also add CI for installation script and shellcheck. Signed-off-by: Jiahao XU --- .github/workflows/install-script.yml | 84 ++++++++++++++++++++++++++++ .github/workflows/shellcheck.yml | 32 +++++++++++ install-from-binstall-release.sh | 5 +- 3 files changed, 118 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/install-script.yml create mode 100644 .github/workflows/shellcheck.yml diff --git a/.github/workflows/install-script.yml b/.github/workflows/install-script.yml new file mode 100644 index 00000000..2f2cb1c7 --- /dev/null +++ b/.github/workflows/install-script.yml @@ -0,0 +1,84 @@ +name: Test install-script + +on: + merge_group: + pull_request: + types: + - opened + - reopened + - synchronize + paths: + - install-from-binstall-release.ps1 + - install-from-binstall-release.sh + push: + branches: + - main + paths: + - install-from-binstall-release.ps1 + - install-from-binstall-release.sh + +concurrency: + group: ${{ github.workflow }}-${{ github.ref || github.event.pull_request.number || github.sha }} + cancel-in-progress: true + +env: + CARGO_TERM_COLOR: always + +jobs: + unix: + strategy: + fail-fast: false + matrix: + os: [macos-latest, ubuntu-latest] + set_cargo_home: [t, f] + + runs-on: ${{ matrix.os }} + + steps: + - uses: actions/checkout@v3 + + - name: Set `CARGO_HOME` + if: matrix.set_cargo_home == 't' + run: | + CARGO_HOME="$(mktemp -d 2>/dev/null || mktemp -d -t 'cargo-home')" + mkdir -p "${CARGO_HOME}/bin" + echo "CARGO_HOME=$CARGO_HOME" >> "$GITHUB_ENV" + echo "${CARGO_HOME}/bin" >> $GITHUB_PATH + + - name: Install `cargo-binstall` using scripts + run: ./install-from-binstall-release.sh + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Verify `cargo-binstall` installation + run: | + which cargo-binstall + cargo binstall -vV + + windows: + strategy: + fail-fast: false + matrix: + set_cargo_home: [t, f] + + runs-on: windows-latest + + steps: + - uses: actions/checkout@v3 + + - name: Set `CARGO_HOME` + if: matrix.set_cargo_home == 't' + shell: bash + run: | + CARGO_HOME="$(mktemp -d 2>/dev/null || mktemp -d -t 'cargo-home')" + mkdir -p "${CARGO_HOME}/bin" + echo "CARGO_HOME=$CARGO_HOME" >> "$GITHUB_ENV" + echo "${CARGO_HOME}/bin" >> $GITHUB_PATH + + - name: Install `cargo-binstall` using scripts + run: ./install-from-binstall-release.ps1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Verify `cargo-binstall` installation + run: cargo binstall -vV diff --git a/.github/workflows/shellcheck.yml b/.github/workflows/shellcheck.yml new file mode 100644 index 00000000..6a8ba778 --- /dev/null +++ b/.github/workflows/shellcheck.yml @@ -0,0 +1,32 @@ +name: Shellcheck + +on: + merge_group: + pull_request: + types: + - opened + - reopened + - synchronize + paths: + - '**.sh' + push: + branches: + - main + paths: + - '**.sh' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref || github.event.pull_request.number || github.sha }} + cancel-in-progress: true + +jobs: + shellcheck: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - uses: taiki-e/install-action@v2 + with: + tool: fd-find + - name: shellcheck + run: fd -e sh -t f -X shellcheck diff --git a/install-from-binstall-release.sh b/install-from-binstall-release.sh index 5ebf4f3d..eacb8477 100755 --- a/install-from-binstall-release.sh +++ b/install-from-binstall-release.sh @@ -27,9 +27,8 @@ fi ./cargo-binstall -y --force cargo-binstall -if ! [[ -v CARGO_HOME ]]; then - CARGO_HOME=$HOME/.cargo -fi +CARGO_HOME="${CARGO_HOME:-$HOME/.cargo}" + if ! [[ ":$PATH:" == *":$CARGO_HOME/bin:"* ]]; then echo printf "\033[0;31mYour path is missing %s, you might want to add it.\033[0m\n" "$CARGO_HOME/bin"