-
Notifications
You must be signed in to change notification settings - Fork 1
141 lines (122 loc) · 3.58 KB
/
ci.yaml
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
name: CI
on:
push:
tags:
- 'v*.*.*'
branches:
- '**'
pull_request:
types: [ opened, synchronize, reopened ]
permissions:
contents: write
jobs:
qa:
name: qa
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.21'
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.58
- name: test
run: go test -race ./...
build:
name: Build
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
strategy:
matrix:
target:
# - 'windows/amd64'
# - 'windows/386'
# - 'windows/arm64'
- 'linux/amd64'
- 'linux/386'
- 'linux/arm64'
- 'linux/arm'
- 'darwin/amd64'
- 'darwin/arm64'
- 'freebsd/386'
- 'freebsd/amd64'
- 'freebsd/arm'
- 'openbsd/amd64'
- 'openbsd/arm64'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'
- name: Set up GOOS and GOARCH
id: setup_env
run: |
echo "goos=$(echo ${{ matrix.target }} | cut -d'/' -f1)" >> $GITHUB_OUTPUT
echo "goarch=$(echo ${{ matrix.target }} | cut -d'/' -f2)" >> $GITHUB_OUTPUT
- name: Build
env:
GOOS: ${{ steps.setup_env.outputs.goos }}
GOARCH: ${{ steps.setup_env.outputs.goarch }}
run: |
set -euo pipefail
VERSION=${GITHUB_REF#refs/tags/v}
COMMIT=$(git rev-parse HEAD)
DATE=$(date +'%FT%TZ%z')
NAME="snip_${VERSION}_${GOOS}_${GOARCH}"
CGO_ENABLED=0 go build -v \
-ldflags "-X main.Version=$VERSION -X main.Commit=$COMMIT -X main.Date=$DATE" .
if [[ "$GOOS" != "windows" ]]; then
tar -czf "$NAME.tar.gz" snip
else
zip "$NAME.zip" snip.exe
fi
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: snip_${{ steps.setup_env.outputs.goos }}_${{ steps.setup_env.outputs.goarch }}
path: |
*.zip
*.tar.gz
release:
name: Release
if: startsWith(github.ref, 'refs/tags/v')
needs: [ qa, build ]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download Artifacts
uses: actions/download-artifact@v4
- name: Create checksums
id: checksums
run: |
set -euo pipefail
mkdir dist
mv snip*/* dist/
cd dist
VERSION=${GITHUB_REF#refs/tags/v}
CHECKSUMS=snip_${VERSION}_checksums.txt
sha256sum * > $CHECKSUMS
- name: Generate release notes
id: release_notes
run: |
set -x
set -euo pipefail
CURRENT_VERSION=${GITHUB_REF#refs/tags/}
PREV_VERSION=$(git describe --tags --abbrev=0 $CURRENT_VERSION^)
RELEASE_NOTES=${{ github.workspace }}/release-notes.txt
printf "## Changelog\n\n" > $RELEASE_NOTES
git log ${PREV_VERSION}..${CURRENT_VERSION} --oneline --abbrev-commit >> $RELEASE_NOTES
cat $RELEASE_NOTES
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
body_path: ${{ github.workspace }}/release-notes.txt
files: |
dist/*