Skip to content

workspace-sync: add GitHub Actions release workflow #1

workspace-sync: add GitHub Actions release workflow

workspace-sync: add GitHub Actions release workflow #1

Workflow file for this run

name: Release
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
tag:
description: "Tag to release (example: v1.0.0)"
required: true
type: string
permissions:
contents: write
jobs:
prepare-tag:
if: github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.out.outputs.tag }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Create tag if missing
id: out
env:
TAG: ${{ github.event.inputs.tag }}
run: |
set -euo pipefail
if [ -z "$TAG" ]; then
echo "tag is required"
exit 1
fi
git fetch --tags --force
if ! git rev-parse "$TAG" >/dev/null 2>&1; then
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag "$TAG"
git push origin "$TAG"
fi
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- goos: linux
goarch: amd64
ext: ""
- goos: darwin
goarch: arm64
ext: ""
- goos: windows
goarch: amd64
ext: ".exe"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Build binary
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
EXT: ${{ matrix.ext }}
run: |
set -euo pipefail
mkdir -p dist
OUT="dist/workspace-sync-${GOOS}-${GOARCH}${EXT}"
CGO_ENABLED=0 go build -trimpath -ldflags='-s -w' -o "$OUT" ./cmd/workspace-sync
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: bin-${{ matrix.goos }}-${{ matrix.goarch }}
path: dist/workspace-sync-*
release:
runs-on: ubuntu-latest
needs: [build, prepare-tag]
if: always() && needs.build.result == 'success' && (github.event_name == 'push' || needs.prepare-tag.result == 'success')
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: dist
- name: Flatten artifacts
run: |
set -euo pipefail
find dist -type f -name 'workspace-sync-*' -exec cp {} dist/ \;
- name: Generate checksums
run: |
set -euo pipefail
sha256sum dist/workspace-sync-* > dist/SHA256SUMS
- name: Publish release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.event_name == 'push' && github.ref_name || needs.prepare-tag.outputs.tag }}
files: |
dist/workspace-sync-*
dist/SHA256SUMS