-
Notifications
You must be signed in to change notification settings - Fork 27
156 lines (149 loc) · 4.64 KB
/
Copy pathrelease.yml
File metadata and controls
156 lines (149 loc) · 4.64 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
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:
- uses: actions/checkout@v6
with:
ref: ${{ github.event.inputs.ref || github.ref }}
- 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
release-chart:
name: publish helm chart
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
ref: ${{ github.event.inputs.ref || github.ref }}
fetch-depth: 0
- uses: azure/setup-helm@v4
- name: Configure Git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
- name: Package chart
env:
TAG: ${{ github.event.inputs.ref || github.ref_name }}
run: |
version="${TAG#v}"
helm lint deployments/kubernetes-helm
helm template csp-collector deployments/kubernetes-helm --set image.tag="$version"
helm package deployments/kubernetes-helm \
--destination .cr-release-packages \
--version "$version" \
--app-version "$version"
- name: Publish chart
uses: helm/chart-releaser-action@v1.7.0
with:
skip_packaging: true
skip_existing: true
mark_as_latest: false
env:
CR_TOKEN: ${{ secrets.GITHUB_TOKEN }}