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"