Skip to content

Merge pull request #89 from steffenfritz/feature/idempotent-release-job #2

Merge pull request #89 from steffenfritz/feature/idempotent-release-job

Merge pull request #89 from steffenfritz/feature/idempotent-release-job #2

name: release-packages
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
version:
description: 'Package version without v prefix (e.g. 1.8.0)'
required: true
permissions:
contents: read
jobs:
build-linux:
runs-on: ubuntu-24.04
permissions:
contents: read
strategy:
matrix:
goarch: [amd64, arm64]
steps:
- name: Checkout
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
- name: Setup Go
uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v5.4.0
with:
go-version: '1.25.x'
- name: Resolve version
id: version
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "value=${{ inputs.version }}" >> "$GITHUB_OUTPUT"
else
echo "value=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"
fi
- name: Build binary
env:
GOOS: linux
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: 0
run: go build -trimpath -ldflags="-s -w" -o mxcheck .
- name: Install nfpm
run: go install github.com/goreleaser/nfpm/v2/cmd/nfpm@v2.41.3
- name: Build .deb package
env:
VERSION: ${{ steps.version.outputs.value }}
ARCH: ${{ matrix.goarch }}
run: nfpm package --config nfpm.yaml --packager deb --target .
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: mxcheck_${{ steps.version.outputs.value }}_linux_${{ matrix.goarch }}.deb
path: "*.deb"
if-no-files-found: error
build-macos:
runs-on: macos-15
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
- name: Setup Go
uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v5.4.0
with:
go-version: '1.25.x'
- name: Resolve version
id: version
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "value=${{ inputs.version }}" >> "$GITHUB_OUTPUT"
else
echo "value=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"
fi
- name: Build binary
env:
GOOS: darwin
GOARCH: arm64
CGO_ENABLED: 0
run: go build -trimpath -ldflags="-s -w" -o mxcheck .
- name: Compress binary
run: tar -czf mxcheck_${{ steps.version.outputs.value }}_darwin_arm64.tar.gz mxcheck
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: mxcheck_${{ steps.version.outputs.value }}_darwin_arm64.tar.gz
path: "*.tar.gz"
if-no-files-found: error
release:
needs: [build-linux, build-macos]
runs-on: ubuntu-24.04
permissions:
contents: write
steps:
- name: Resolve version
id: version
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "value=${{ inputs.version }}" >> "$GITHUB_OUTPUT"
echo "tag=v${{ inputs.version }}" >> "$GITHUB_OUTPUT"
else
echo "value=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"
echo "tag=${GITHUB_REF_NAME}" >> "$GITHUB_OUTPUT"
fi
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: dist
merge-multiple: true
- name: Create GitHub release and upload assets
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ steps.version.outputs.tag }}
VERSION: ${{ steps.version.outputs.value }}
run: |
if gh release view "$TAG" --repo "$GITHUB_REPOSITORY" > /dev/null 2>&1; then
gh release upload "$TAG" \
--repo "$GITHUB_REPOSITORY" \
--clobber \
dist/*.deb \
dist/*.tar.gz
else
gh release create "$TAG" \
--repo "$GITHUB_REPOSITORY" \
--title "mxcheck $VERSION" \
--generate-notes \
dist/*.deb \
dist/*.tar.gz
fi