GitHub Actions
Platform: GitHub Actions
Get Version
Capture the current version as an output:
- name: Get version
id: version
run: echo "version=$(versionator version)" >> $GITHUB_OUTPUT
- name: Use version
run: echo "Building version ${{ steps.version.outputs.version }}"
Build with Version
Inject version at build time:
- name: Build with version
run: |
VERSION=$(versionator version)
go build -ldflags "-X main.VERSION=$VERSION" -o app
Full Version Info
Get extended version information:
- name: Get full version info
id: version
run: |
echo "version=$(versionator version)" >> $GITHUB_OUTPUT
echo "full=$(versionator output version -t '{{Prefix}}{{MajorMinorPatch}}{{PreReleaseWithDash}}{{MetadataWithPlus}}' --prefix --metadata='{{ShortHash}}')" >> $GITHUB_OUTPUT
Release Workflow
name: Release
on:
push:
tags:
- 'v*'
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Get version from tag
id: version
run: echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
- name: Build
run: |
VERSION=${{ steps.version.outputs.version }}
go build -ldflags "-X main.VERSION=$VERSION" -o app
- name: Create Release
uses: softprops/action-gh-release@v1
with:
files: app
body: "Release ${{ steps.version.outputs.version }}"
Install Versionator
- name: Install versionator
run: go install github.com/benjaminabbitt/versionator@latest
Or cache it for faster builds:
- name: Cache versionator
uses: actions/cache@v4
with:
path: ~/go/bin/versionator
key: versionator-${{ runner.os }}
- name: Install versionator
run: |
if [ ! -f ~/go/bin/versionator ]; then
go install github.com/benjaminabbitt/versionator@latest
fi