Skip to content
Draft
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
4 changes: 4 additions & 0 deletions .github/workflows/use_action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ jobs:
platform:
- ubuntu-latest
- macos-latest
- windows-latest

runs-on: ${{ matrix.platform }}
defaults:
run:
shell: bash

steps:
- uses: actions/setup-go@v5
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ jobs:
steps:
- uses: actions/setup-go@v5
with:
go-version: '1.20.x'
go-version: '1.22.x'

- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: mscno/setup-goose@v1

Expand All @@ -29,20 +29,20 @@ jobs:

That's it! This workflow will run your migrations using goose.

The action works on Linux and macOS runners. If you'd like support for Windows runners, let us know!
The action works on Linux, macOS, and Windows runners.

## Select goose version to install
By default, pressly/setup-goose installs the latest released version of goose.
By default, mscno/setup-goose installs the latest released version of goose.

You can select a version with the version parameter:

```yaml
- uses: mscno/setup-goose@v1
with:
version: v0.14.1
version: v3.26.0
```

To build and install goose from source using go install, specify version: `tip`.
To build and install goose from source using `go install`, specify `version: tip`.

## Running Migrations

Expand All @@ -59,6 +59,6 @@ After installing goose with this action, you can run your migrations with goose
You can also run specific migrations with goose up-to <version>, roll back migrations with goose down, and more. See the goose documentation for more information.

## A note on versioning
The @v0.X in the uses statement refers to the version of the action definition in this repo.
The `@v1` in the `uses:` statement refers to the version of the action definition in this repo.

Regardless of what version of the action definition you use, pressly/setup-goose will install the latest released version of goose unless otherwise specified with version:.
Regardless of what version of the action definition you use, mscno/setup-goose will install the latest released version of goose unless otherwise specified with `version:`.
61 changes: 43 additions & 18 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,43 @@ branding:
color: green
inputs:
version:
description: 'Version of goose to install (tip, latest-release, v0.14.1, etc.)'
description: 'Version of goose to install (tip, latest-release, v3.26.0, etc.)'
required: true
default: 'latest-release'
runs:
using: "composite"
steps:
- shell: bash
run: |
set -ex
set -euo pipefail

version="${{ inputs.version }}"

# Install goose:
# - if version is "tip", install from tip of main.
# - if version is "latest-release", look up latest release.
# - otherwise, install the specified version.

case ${{ inputs.version }} in
case "${version}" in
tip)
echo "Installing goose using go install"
go install github.com/pressly/goose/v3/cmd/goose@latest
;;
latest-release)
tag=$(curl -L -s -u "username:${{ github.token }}" https://api.github.com/repos/pressly/goose/releases/latest | jq -r '.tag_name')
;;
*)
tag="${{ inputs.version }}"
go install github.com/pressly/goose/v3/cmd/goose@main
echo "$(go env GOPATH)/bin" >> "$GITHUB_PATH"
exit 0
esac

if [[ "${version}" == "latest-release" ]]; then
tag="$(
curl -fsSL \
-H "Authorization: Bearer ${{ github.token }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/pressly/goose/releases/latest" \
| python -c 'import json,sys; print(json.load(sys.stdin)["tag_name"])'
)"
else
tag="${version}"
fi

case ${{ runner.os }} in
macOS)
os="darwin"
Expand Down Expand Up @@ -61,12 +71,27 @@ runs:
;;
esac

if [[ ! -z ${tag} ]]; then
echo "Installing goose @ ${tag} for ${os}_${arch}"
if [[ $os == "windows" ]]; then
powershell -Command "Invoke-WebRequest -Uri https://github.com/pressly/goose/releases/download/${tag}/goose_${os}_${arch}.exe -OutFile C:\goose\goose.exe"
else
curl -fsL https://github.com/pressly/goose/releases/download/${tag}/goose_${os}_${arch} > /usr/local/bin/goose
chmod +x /usr/local/bin/goose
fi
if [[ -z "${tag}" ]]; then
echo "Failed to resolve goose release tag"
exit 1
fi

install_dir="${RUNNER_TEMP:-/tmp}/goose/bin"
mkdir -p "${install_dir}"

ext=""
if [[ "${os}" == "windows" ]]; then
ext=".exe"
fi

asset="goose_${os}_${arch}${ext}"
dest="${install_dir}/goose${ext}"

echo "Installing goose @ ${tag} (${asset})"
curl -fsSL -o "${dest}" "https://github.com/pressly/goose/releases/download/${tag}/${asset}"

if [[ "${os}" != "windows" ]]; then
chmod +x "${dest}"
fi

echo "${install_dir}" >> "$GITHUB_PATH"