Skip to content

Commit

Permalink
Simplify install action (#1517)
Browse files Browse the repository at this point in the history
  • Loading branch information
ofek committed May 23, 2024
1 parent f4b68bb commit a3c83ab
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/test-install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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.
3 changes: 1 addition & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
8 changes: 7 additions & 1 deletion main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit a3c83ab

Please sign in to comment.