diff --git a/.github/workflows/run.yml b/.github/workflows/run.yml new file mode 100644 index 0000000..928b50c --- /dev/null +++ b/.github/workflows/run.yml @@ -0,0 +1,14 @@ +name: Run + +on: workflow_dispatch + +jobs: + run: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: ./assert-version + with: + filename: fixtures/assert-version/binary.sh + expected-version: "1.2.3" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..350f754 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,60 @@ +name: CI + +on: + push: + pull_request: + +jobs: + 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 diff --git a/release-tag-to-version/action.yml b/release-tag-to-version/action.yml index 14023b5..08aad0c 100644 --- a/release-tag-to-version/action.yml +++ b/release-tag-to-version/action.yml @@ -9,8 +9,6 @@ outputs: value: ${{ steps.tag-type.outputs.tag-type }} version: value: ${{ steps.set-release-version.outputs.release-version }} - name: - value: ${{ steps.tag-message.outputs.name }} description: value: ${{ steps.tag-message.outputs.description }} @@ -56,10 +54,7 @@ runs: - name: Extract tag message id: tag-message run: | - NAME=$(git tag -l --format='%(contents:subject)' "$RELEASE_TAG") - DESCRIPTION=$(git tag -l --format='%(contents:body)' "$RELEASE_TAG") - - echo "name=${NAME}" >> $GITHUB_OUTPUT + DESCRIPTION=$(git tag -l --format='%(contents)' "$RELEASE_TAG") { echo "description<