Utilise composite workflows.

This commit is contained in:
2025-12-14 19:40:55 +00:00
parent c489e4506c
commit f01c18353f
8 changed files with 548 additions and 61 deletions
+164
View File
@@ -0,0 +1,164 @@
name: Go Release (CGO)
on:
workflow_call:
inputs:
go-version:
description: "Go version to use"
required: false
type: string
default: ">=1.24"
semver-config:
description: "Path to semver config file"
required: false
type: string
default: "semver.yaml"
rolling-release-tag:
description: "Create a rolling release tag (e.g., 'v1')"
required: false
type: string
default: ""
# Node.js support (optional)
node-enabled:
description: "Enable Node.js for frontend builds"
required: false
type: boolean
default: false
node-version:
description: "Node.js version to use"
required: false
type: string
default: "20"
node-build-script:
description: "Shell script to build frontend"
required: false
type: string
default: ""
# Platform configuration
platforms:
description: "JSON array of platforms"
required: false
type: string
default: '[{"os":"macos-13","goos":"darwin","goarch":"amd64","platform":"darwin_amd64"},{"os":"macos-latest","goos":"darwin","goarch":"arm64","platform":"darwin_arm64"},{"os":"ubuntu-latest","goos":"linux","goarch":"amd64","platform":"linux_amd64"},{"os":"windows-latest","goos":"windows","goarch":"amd64","platform":"windows_amd64"}]'
outputs:
version:
description: "The calculated version (without v prefix)"
value: ${{ jobs.version.outputs.version }}
version_tag:
description: "The version tag (with v prefix)"
value: ${{ jobs.version.outputs.version_tag }}
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Run tests
uses: lukaszraczylo/shared-actions/.github/actions/go-test@main
with:
go-version: ${{ inputs.go-version }}
version:
name: Calculate Version
needs: test
runs-on: ubuntu-latest
outputs:
version: ${{ steps.semver.outputs.version }}
version_tag: ${{ steps.semver.outputs.version_tag }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Calculate version
id: semver
uses: lukaszraczylo/shared-actions/.github/actions/semver@main
with:
config-file: ${{ inputs.semver-config }}
build:
name: Build (${{ matrix.platform }})
needs: version
if: needs.version.outputs.version_tag != ''
strategy:
fail-fast: false
matrix:
include: ${{ fromJson(inputs.platforms) }}
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ${{ inputs.go-version }}
cache: true
- name: Build frontend
if: inputs.node-enabled && inputs.node-build-script != ''
uses: lukaszraczylo/shared-actions/.github/actions/node-build@main
with:
node-version: ${{ inputs.node-version }}
build-script: ${{ inputs.node-build-script }}
- name: Run GoReleaser (split)
uses: lukaszraczylo/shared-actions/.github/actions/goreleaser@main
with:
version-tag: ${{ needs.version.outputs.version_tag }}
mode: split
cgo-enabled: "1"
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: release-${{ matrix.platform }}
path: dist/*.*
retention-days: 1
release:
name: Release
needs: [version, build]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ${{ inputs.go-version }}
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: dist
pattern: release-*
merge-multiple: true
- name: List artifacts
run: ls -la dist/
- name: Run GoReleaser (merge)
uses: lukaszraczylo/shared-actions/.github/actions/goreleaser@main
with:
version-tag: ${{ needs.version.outputs.version_tag }}
mode: merge
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Rolling release
if: inputs.rolling-release-tag != ''
uses: lukaszraczylo/shared-actions/.github/actions/rolling-release@main
with:
tag: ${{ inputs.rolling-release-tag }}
version-tag: ${{ needs.version.outputs.version_tag }}
github-token: ${{ secrets.GITHUB_TOKEN }}
+25 -60
View File
@@ -7,14 +7,14 @@ on:
description: "Go version to use"
required: false
type: string
default: ">=1.21"
default: ">=1.24"
semver-config:
description: "Path to semver config file"
required: false
type: string
default: "semver.yaml"
docker-enabled:
description: "Enable Docker builds (requires QEMU, Buildx, GHCR login)"
description: "Enable Docker builds"
required: false
type: boolean
default: false
@@ -24,13 +24,17 @@ on:
type: string
default: "ghcr.io"
rolling-release-tag:
description: "Create a rolling release tag (e.g., 'v1') that always points to latest"
description: "Create a rolling release tag (e.g., 'v1')"
required: false
type: string
default: ""
# Permissions are inherited from the caller workflow via secrets: inherit
# Caller must declare: contents: write (required), packages: write (if docker-enabled)
outputs:
version:
description: "The calculated version (without v prefix)"
value: ${{ jobs.version.outputs.version }}
version_tag:
description: "The version tag (with v prefix)"
value: ${{ jobs.version.outputs.version_tag }}
jobs:
test:
@@ -40,21 +44,18 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
- name: Run tests
uses: lukaszraczylo/shared-actions/.github/actions/go-test@main
with:
go-version: ${{ inputs.go-version }}
- name: Run tests
run: go test -race -v ./...
version:
name: Calculate Version
needs: test
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version_formatted.outputs.version }}
version_tag: ${{ steps.version_formatted.outputs.version_tag }}
version: ${{ steps.semver.outputs.version }}
version_tag: ${{ steps.semver.outputs.version_tag }}
steps:
- name: Checkout
uses: actions/checkout@v4
@@ -63,22 +64,9 @@ jobs:
- name: Calculate version
id: semver
uses: lukaszraczylo/semver-generator@v1
uses: lukaszraczylo/shared-actions/.github/actions/semver@main
with:
config_file: ${{ inputs.semver-config }}
repository_local: true
- name: Format version
id: version_formatted
run: |
VERSION="${{ steps.semver.outputs.semantic_version }}"
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "version_tag=v${VERSION}" >> $GITHUB_OUTPUT
- name: Print version
run: |
echo "Version: ${{ steps.version_formatted.outputs.version }}"
echo "Version tag: ${{ steps.version_formatted.outputs.version_tag }}"
config-file: ${{ inputs.semver-config }}
release:
name: Release
@@ -113,41 +101,18 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create and push tag
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a ${{ needs.version.outputs.version_tag }} -m "Release ${{ needs.version.outputs.version_tag }}" || true
git push origin ${{ needs.version.outputs.version_tag }} || true
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v6
uses: lukaszraczylo/shared-actions/.github/actions/goreleaser@main
with:
distribution: goreleaser
version: "~> v2"
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
HOMEBREW_TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
version-tag: ${{ needs.version.outputs.version_tag }}
mode: full
github-token: ${{ secrets.GITHUB_TOKEN }}
homebrew-tap-token: ${{ secrets.HOMEBREW_TAP_TOKEN }}
# Rolling release (optional, e.g., v1 for GitHub Actions)
- name: Update rolling release tag
- name: Rolling release
if: inputs.rolling-release-tag != ''
run: |
git tag -f ${{ inputs.rolling-release-tag }}
git push origin ${{ inputs.rolling-release-tag }} --force
- name: Update or create rolling release
if: inputs.rolling-release-tag != ''
uses: ncipollo/release-action@v1
uses: lukaszraczylo/shared-actions/.github/actions/rolling-release@main
with:
name: ${{ inputs.rolling-release-tag }} - ${{ needs.version.outputs.version_tag }}
token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ inputs.rolling-release-tag }}
prerelease: false
allowUpdates: true
makeLatest: false
body: |
Rolling release pointing to version ${{ needs.version.outputs.version_tag }}.
Use `@${{ inputs.rolling-release-tag }}` in your GitHub Actions workflows for automatic updates.
version-tag: ${{ needs.version.outputs.version_tag }}
github-token: ${{ secrets.GITHUB_TOKEN }}