Skip to content

ci: automate release artifacts #1

ci: automate release artifacts

ci: automate release artifacts #1

Workflow file for this run

name: Release
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
ref:
description: "Tag to release, for example v0.0.18"
required: true
type: string
permissions:
contents: write
jobs:
test:
name: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
ref: ${{ github.event.inputs.ref || github.ref }}
- name: Validate release tag
env:
TAG: ${{ github.event.inputs.ref || github.ref_name }}
run: |
case "$TAG" in
v*) ;;
*) echo "release tag must start with v"; exit 1 ;;
esac
- uses: actions/setup-go@v6
with:
go-version-file: "go.mod"
- name: Test
run: go test -v -race ./...
build:
name: build ${{ matrix.goos }}/${{ matrix.goarch }}
needs: test
strategy:
fail-fast: false
matrix:
include:
- goos: darwin
goarch: amd64
runs-on: macos-15-intel
- goos: darwin
goarch: arm64
runs-on: macos-15
- goos: linux
goarch: amd64
runs-on: ubuntu-latest
- goos: linux
goarch: arm64
runs-on: ubuntu-24.04-arm
- goos: windows
goarch: amd64
runs-on: windows-latest
runs-on: ${{ matrix.runs-on }}
steps:
- uses: actions/checkout@v6
with:
ref: ${{ github.event.inputs.ref || github.ref }}
- uses: actions/setup-go@v6
with:
go-version-file: "go.mod"
- name: Verify native build target
shell: bash
run: |
test "$(go env GOHOSTOS)" = "${{ matrix.goos }}"
test "$(go env GOHOSTARCH)" = "${{ matrix.goarch }}"
- name: Build archive
shell: bash
env:
CGO_ENABLED: "0"
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
run: |
tag="${{ github.event.inputs.ref || github.ref_name }}"
version="${tag#v}"
revision="${version}+$(git rev-parse --short HEAD)"
output="go-csp-collector_${version}_${GOOS}_${GOARCH}"
mkdir -p dist
if [ "$GOOS" = "windows" ]; then
go build -trimpath -ldflags "-s -w -X main.Rev=${revision}" -o "dist/${output}.exe" .
tar -czf "dist/${output}.tar.gz" -C dist "${output}.exe"
else
go build -trimpath -ldflags "-s -w -X main.Rev=${revision}" -o "dist/${output}" .
tar -czf "dist/${output}.tar.gz" -C dist "${output}"
fi
- name: Upload archive
uses: actions/upload-artifact@v7
with:
name: go-csp-collector-${{ matrix.goos }}-${{ matrix.goarch }}
path: dist/*.tar.gz
if-no-files-found: error
release:
name: publish release
needs: build
runs-on: ubuntu-latest
steps:
- name: Download archives
uses: actions/download-artifact@v8
with:
path: dist
pattern: go-csp-collector-*
merge-multiple: true
- name: Generate checksums
working-directory: dist
run: shasum -a 256 -- *.tar.gz > checksums.txt
- name: Publish GitHub release
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ github.event.inputs.ref || github.ref_name }}
run: gh release create "$TAG" dist/*.tar.gz dist/checksums.txt --title "$TAG" --generate-notes