Skip to content
Closed
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
31 changes: 31 additions & 0 deletions .github/workflows/run.yml
Original file line number Diff line number Diff line change
@@ -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 }}
106 changes: 106 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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"
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
test:
act -W .github/workflows/test.yml

run:
act -W .github/workflows/run.yml
42 changes: 39 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 4 additions & 0 deletions fixtures/assert-version/binary.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
if [[ "$1" == "--version" ]]; then
echo "myapp 1.2.3"
fi
Loading