Files
laily f7fcd0e966 ci: stop running workflow on pushes to main
Only trigger builds on v* tags and pull requests targeting main.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-26 12:55:19 +08:00

110 lines
2.8 KiB
YAML

name: Release
on:
push:
tags: ["v*"]
pull_request:
branches: [main]
permissions:
contents: read
env:
GO_VERSION: "1.22.2"
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Test
run: go test ./...
build:
needs: test
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- goos: linux
goarch: amd64
- goos: linux
goarch: arm64
- goos: darwin
goarch: amd64
- goos: darwin
goarch: arm64
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Resolve version
id: meta
shell: bash
run: |
if [[ "${GITHUB_REF}" == refs/tags/v* ]]; then
VERSION="${GITHUB_REF#refs/tags/}"
else
VERSION="dev-$(git rev-parse --short HEAD)"
fi
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "Version: ${VERSION}"
- name: Build binary
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
VERSION: ${{ steps.meta.outputs.version }}
run: |
mkdir -p dist
OUT="dist/agent-notify-${VERSION}_${GOOS}_${GOARCH}"
CGO_ENABLED=0 go build -trimpath \
-ldflags "-s -w \
-X main.version=${VERSION} \
-X main.commit=${GITHUB_SHA} \
-X main.buildDate=$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
-o "${OUT}" ./cmd/agent-notify
chmod +x "${OUT}"
sha256sum "${OUT}" > "${OUT}.sha256"
tar -czf "${OUT}.tar.gz" -C dist "$(basename "${OUT}")" "$(basename "${OUT}").sha256"
rm "${OUT}" "${OUT}.sha256"
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: agent-notify-${{ steps.meta.outputs.version }}-${{ matrix.goos }}-${{ matrix.goarch }}
path: dist/agent-notify-${{ steps.meta.outputs.version }}_${{ matrix.goos }}_${{ matrix.goarch }}.tar.gz
if-no-files-found: error
release:
if: startsWith(github.ref, 'refs/tags/v')
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/download-artifact@v4
with:
pattern: agent-notify-*
merge-multiple: true
path: dist
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
files: dist/*.tar.gz
generate_release_notes: true