From a3c83ab3d481fbc2dc91dd0088628817488dd1d5 Mon Sep 17 00:00:00 2001 From: Ofek Lev Date: Thu, 23 May 2024 00:09:41 -0400 Subject: [PATCH] Simplify install action (#1517) --- .github/workflows/test-install.yml | 3 +-- README.md | 4 ++-- action.yml | 3 +-- main.sh | 8 +++++++- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test-install.yml b/.github/workflows/test-install.yml index ea15a74be..d78e9fa0d 100644 --- a/.github/workflows/test-install.yml +++ b/.github/workflows/test-install.yml @@ -31,10 +31,9 @@ jobs: - name: Install # Command needs to be wrapped in single quotes so backslashes are preserved for Windows paths - run: "'${{ github.workspace }}${{ env.SEP }}main.sh'" + run: "'${{ github.workspace }}${{ runner.os == 'Windows' && '\\' || '/' }}main.sh'" shell: bash env: - SEP: ${{ runner.os == 'Windows' && '\' || '/' }} VERSION: latest - name: Verify diff --git a/README.md b/README.md index e56f6c0b6..18b45959c 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ For strict security guarantees, it's best practice to [pin](https://docs.github. ```yaml - name: Install Hatch - uses: pypa/hatch@05d55c44632b129e63a7f0515803384fbf83fe89 + uses: pypa/hatch@f4b68bbda7951a6654d3c9f9bb5e92fe9f68a14f ``` ## Options @@ -30,6 +30,7 @@ Name | Default | Description It's possible to use the [install script](https://github.com/pypa/hatch/blob/install/main.sh) outside of GitHub Actions assuming you set up your environment as follows: +- Set every [option](#options) to an environment variable with uppercasing and replacing hyphens with underscores. - Set the `RUNNER_TOOL_CACHE` environment variable to the directory where you want to install Hatch. - Set the `GITHUB_PATH` environment variable to a file that is writable which will contain the directory where Hatch is installed (usually `$RUNNER_TOOL_CACHE/.hatch`). - Set the `RUNNER_OS` environment variable to the current platform using one of the following values: @@ -39,5 +40,4 @@ It's possible to use the [install script](https://github.com/pypa/hatch/blob/ins - Set the `RUNNER_ARCH` environment variable to the current architecture using one of the following values: - `X64` - `ARM64` -- Set the `SEP` environment variable to the current platform's path separator (`/` for Linux/macOS, `\` for Windows). - Install [pipx](https://github.com/pypa/pipx) as a fallback installation method for when there is no [standalone binary](https://hatch.pypa.io/latest/install/#standalone-binaries) available. diff --git a/action.yml b/action.yml index c8dbb606c..8944bf994 100644 --- a/action.yml +++ b/action.yml @@ -14,8 +14,7 @@ runs: steps: - name: Install and configure Hatch # Command needs to be wrapped in single quotes so backslashes are preserved for Windows paths - run: "'${{ github.action_path }}${{ env.SEP }}main.sh'" + run: "'${{ github.action_path }}${{ runner.os == 'Windows' && '\\' || '/' }}main.sh'" shell: bash env: - SEP: ${{ runner.os == 'Windows' && '\' || '/' }} VERSION: ${{ inputs.version }} diff --git a/main.sh b/main.sh index cdd50e1d1..132e31f82 100755 --- a/main.sh +++ b/main.sh @@ -2,10 +2,16 @@ set -euo pipefail IFS=$'\n\t' -INSTALL_PATH="${RUNNER_TOOL_CACHE}${SEP}.hatch" PURPLE="\033[1;35m" RESET="\033[0m" +if [[ "${RUNNER_OS}" == "Windows" ]]; then + SEP="\\" +else + SEP="/" +fi +INSTALL_PATH="${RUNNER_TOOL_CACHE}${SEP}.hatch" + install_hatch() { mkdir -p "${INSTALL_PATH}" archive="${INSTALL_PATH}${SEP}$1"