-
Notifications
You must be signed in to change notification settings - Fork 27
119 lines (113 loc) · 3.42 KB
/
Copy pathrelease.yml
File metadata and controls
119 lines (113 loc) · 3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
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