Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,29 @@ jobs:
- name: Test
run: |
[ "$(just --justfile tests/Justfile)" = "Test..." ]

test-version-file:
needs: test-latest
strategy:
matrix:
include:
- file: .tool-versions
content: just 1.40.0
version: 1.40.0
- file: .just-version
content: 1.39.0
version: 1.39.0
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Create ${{ matrix.file }}
run: echo "${{ matrix.content }}" > "${{ matrix.file }}"
- name: Run self
uses: ./
with:
just-version-file: ${{ matrix.file }}
- name: Check version
run: just --version | grep -E "^just v?${{ matrix.version }}$"
- name: Test
run: |
[ "$(just --justfile tests/Justfile)" = "Test..." ]
22 changes: 18 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ If you want a specific version of `just` you can specify this by passing the
just-version: '1.46.0'
```

Alternatively you can keep the version in a file and point the action at it with
the `just-version-file` input. Both a `.tool-versions` file (the `just` entry is
read) and a plain version file like `.just-version` are supported.

```yaml
- uses: extractions/setup-just@v4
with:
just-version-file: '.tool-versions'
```

To avoid rate-limiting, the default Github token (available to all actions) is
automatically used to authenticate calls to Github. To override it, pass the
input `github-token`.
Expand All @@ -36,10 +46,14 @@ input `github-token`.

### Inputs

| Name | Required | Description | Type | Default |
| -------------- | -------- | -------------------------------------------- | ------ | --------------------- |
| `just-version` | no | A valid NPM-style semver specification. | string | * |
| `github-token` | no | A Github token to authenticate API requests. | string | `${{ github.token }}` |
| Name | Required | Description | Type | Default |
| ------------------- | -------- | ------------------------------------------------------------- | ------ | --------------------- |
| `just-version` | no | A valid NPM-style semver specification. | string | * |
| `just-version-file` | no | Path to a file (`.tool-versions` or plain) holding the version. | string | - |
| `github-token` | no | A Github token to authenticate API requests. | string | `${{ github.token }}` |

If both `just-version` and `just-version-file` are set, `just-version` takes
precedence and the file is ignored.

The semver specification is passed directly to NPM's [semver
package](https://www.npmjs.com/package/semver). This GitHub Action will install
Expand Down
42 changes: 41 additions & 1 deletion action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,55 @@ branding:
inputs:
just-version:
description: 'A valid semver specifier of the just version to install'
just-version-file:
description: >-
Path to a file that contains the just version to install, such as a
.tool-versions file (the `just <version>` entry is read) or a plain
file like .just-version (the first non-comment line is read). Ignored
when just-version is also set.
required: false
github-token:
description: 'Github token to use to authenticate downloads'
required: false
default: ${{ github.token }}
runs:
using: composite
steps:
- name: Resolve just version from file
id: resolve
if: ${{ inputs.just-version-file != '' }}
shell: bash
env:
JUST_VERSION: ${{ inputs.just-version }}
JUST_VERSION_FILE: ${{ inputs.just-version-file }}
run: |
set -euo pipefail
if [ -n "$JUST_VERSION" ]; then
echo "::warning::both just-version and just-version-file were provided; using just-version and ignoring just-version-file"
exit 0
fi
if [ ! -f "$JUST_VERSION_FILE" ]; then
echo "::error::just-version-file '$JUST_VERSION_FILE' does not exist"
exit 1
fi
case "$(basename "$JUST_VERSION_FILE")" in
.tool-versions)
# asdf/mise format, e.g. `just 1.40.0` (extra fields and comments are ignored)
version="$(grep -E '^just[[:space:]]+' "$JUST_VERSION_FILE" | head -n1 | awk '{print $2}')"
;;
*)
# Plain version file: first non-empty, non-comment line
version="$(grep -vE '^[[:space:]]*(#|$)' "$JUST_VERSION_FILE" | head -n1 | tr -d '[:space:]')"
;;
esac
if [ -z "$version" ]; then
echo "::error::could not determine a just version from '$JUST_VERSION_FILE'"
exit 1
fi
echo "Resolved just version '$version' from '$JUST_VERSION_FILE'"
echo "version=$version" >> "$GITHUB_OUTPUT"
- uses: extractions/setup-crate@0551596312d4008a6dfbc4d3c38fa20eaef46d2d # v2.0.0
with:
repo: casey/just
version: ${{ inputs.just-version }}
version: ${{ inputs.just-version || steps.resolve.outputs.version }}
github-token: ${{ inputs.github-token }}