diff --git a/.github/workflows/run.yml b/.github/workflows/run.yml new file mode 100644 index 0000000..b87e483 --- /dev/null +++ b/.github/workflows/run.yml @@ -0,0 +1,31 @@ +name: Run + +on: workflow_dispatch + +jobs: + run: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: create test tag + run: | + git config user.name "test" + git config user.email "test@test.com" + git tag -a v1.2.3 -m "Release 1.2.3" + git remote set-url origin "file://$(pwd)/.git" + + - uses: ./release-tag-to-version + id: release + with: + release-tag: v1.2.3 + + - name: print outputs + run: | + echo "type: ${{ steps.release.outputs.type }}" + echo "version: ${{ steps.release.outputs.version }}" + + - uses: ./assert-version + with: + filename: fixtures/assert-version/binary.sh + expected-version: ${{ steps.release.outputs.version }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..4eceba7 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,106 @@ +name: CI + +on: + push: + pull_request: + +jobs: + test-release-tag: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: create test tag + run: | + git config user.name "test" + git config user.email "test@test.com" + git tag -a v1.2.3 -m "Release 1.2.3" + git remote set-url origin "file://$(pwd)/.git" + + - uses: ./release-tag-to-version + id: release + with: + release-tag: v1.2.3 + + - name: assert type is RELEASE + run: test "${{ steps.release.outputs.type }}" = "RELEASE" + + - name: assert version is 1.2.3 + run: test "${{ steps.release.outputs.version }}" = "1.2.3" + + test-prerelease-tag: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: create test tag + run: | + git config user.name "test" + git config user.email "test@test.com" + git tag -a v2.0.0-rc1 -m "Pre-release 2.0.0-rc1" + git remote set-url origin "file://$(pwd)/.git" + + - uses: ./release-tag-to-version + id: prerelease + with: + release-tag: v2.0.0-rc1 + + - name: assert type is PRE_RELEASE + run: test "${{ steps.prerelease.outputs.type }}" = "PRE_RELEASE" + + - name: assert version is 2.0.0 + run: test "${{ steps.prerelease.outputs.version }}" = "2.0.0" + + test-invalid-tag: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: ./release-tag-to-version + id: invalid + continue-on-error: true + with: + release-tag: not-a-tag + + - name: assert invalid tag fails + run: test "${{ steps.invalid.outcome }}" = "failure" + + test-assert-version-match: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: ./assert-version + with: + filename: fixtures/assert-version/binary.sh + expected-version: "1.2.3" + + test-assert-version-mismatch: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: ./assert-version + id: mismatch + continue-on-error: true + with: + filename: fixtures/assert-version/binary.sh + expected-version: "3.2.1" + + - name: assert mismatch fails + run: test "${{ steps.mismatch.outcome }}" = "failure" + + test-assert-version-invalid: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: ./assert-version + id: invalid + continue-on-error: true + with: + filename: fixtures/assert-version/binary.sh + expected-version: "not-a-version" + + - name: assert invalid version fails + run: test "${{ steps.invalid.outcome }}" = "failure" diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..69ab195 --- /dev/null +++ b/Makefile @@ -0,0 +1,5 @@ +test: + act -W .github/workflows/test.yml + +run: + act -W .github/workflows/run.yml diff --git a/README.md b/README.md index 258b7d7..5e80170 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,40 @@ -Opinionated actions for GitHub releases +# release-action -- release-tag-to-version: Get the tag from commit, validates and pushes to release. -- assert-version: Validates if the tag pushed to repository is same as the one in project. +GitHub actions for validating and extracting release information from Git tags. + +### `release-tag-to-version` + +Validates a release tag (`v1.2.3` or `v1.2.3-rc1`), extracts the semantic version. Outputs `type` (RELEASE/PRE_RELEASE) and `version`. + +### Usage + +```yml +- uses: intentee/release-action/release-tag-to-version@main + id: release + with: + release-tag: ${{ github.ref_name }} +``` + +### `assert-version` + +Runs artifact with `--version` flag and asserts the output contains the expected semantic version. + +### Usage + +```yml +- uses: intentee/release-action/assert-version@main + with: + filename: target/release/myapp + expected-version: ${{ steps.release.outputs.version }} +``` + +### Commands + +#### `make run`: +- Runs both actions against `fixtures` via [`act`](https://github.com/nektos/act). +- Requires Docker. + +#### `make test`: +- Runs `.github/workflows/test.yml` locally via [`act`](https://github.com/nektos/act). +- Asserts valid tags, invalid tags, version match, mismatch, and invalid version format. +- Requires Docker. diff --git a/fixtures/assert-version/binary.sh b/fixtures/assert-version/binary.sh new file mode 100755 index 0000000..c1168ec --- /dev/null +++ b/fixtures/assert-version/binary.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +if [[ "$1" == "--version" ]]; then + echo "myapp 1.2.3" +fi