clink/.github/workflows/go.yml
2025-10-15 13:06:10 +07:00

81 lines
2.1 KiB
YAML

name: release-binaries-from-bookmark
on:
push:
branches:
- "releases/v*"
permissions:
contents: write
env:
APP_NAME: clink
ENTRY_PATH: .
jobs:
build:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.ver.outputs.version }}
strategy:
matrix:
goos: [linux, darwin, windows]
goarch: [amd64, arm64]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Parse version from bookmark
id: ver
run: |
REF="${GITHUB_REF_NAME}" # e.g., releases/v1.2.3
case "$REF" in
releases/v*) ;;
*) echo "Unexpected ref: $REF" >&2; exit 1;;
esac
V="${REF#releases/}"
echo "version=$V" >> "$GITHUB_OUTPUT"
echo "Version: $V"
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.22.x"
cache: true
- name: Build and package
run: |
set -euo pipefail
V="${{ steps.ver.outputs.version }}"
mkdir -p dist
EXT=""
if [ "${{ matrix.goos }}" = "windows" ]; then EXT=".exe"; fi
BIN="dist/${APP_NAME}_${{ matrix.goos }}_${{ matrix.goarch }}${EXT}"
ARCHIVE_BASE="${APP_NAME}_${V}_${{ matrix.goos }}_${{ matrix.goarch }}"
export CGO_ENABLED=0
if [ "${{ matrix.goarm }}" != "" ]; then
export GOARM=${{ matrix.goarm }}
ARCHIVE_BASE="${APP_NAME}_${V}_${{ matrix.goos }}_armv${{ matrix.goarm }}"
fi
GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} \
go build -trimpath -ldflags="-s -w -X 'main.version=${V}'" \
-o "$BIN" "$ENTRY_PATH"
echo "Built and packaged: dist/"
echo "$(ls -lh "dist")"
- name: Create GitHub Release with binaries
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ needs.build.outputs.version }}
name: ${{ needs.build.outputs.version }}
draft: false
prerelease: false
files: dist/*
generate_release_notes: true