-
Notifications
You must be signed in to change notification settings - Fork 0
172 lines (147 loc) · 5.72 KB
/
go-ci.yml
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
name: Go CI/CD
on:
push:
branches: [ main ]
tags:
- 'v[0-9]+.[0-9]+.[0-9]+' # Matches v0.1.0, v1.0.0, etc.
pull_request:
branches: [ main ]
permissions:
contents: write
pull-requests: write
jobs:
test:
name: Test & Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'
cache: true
- name: Install dependencies
run: |
go mod download
go install golang.org/x/tools/cmd/goimports@latest
- name: Run tests
run: go test -race -coverprofile=coverage.txt -covermode=atomic ./...
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
args: --timeout=5m --out-format=colored-line-number --issues-exit-code=1
only-new-issues: true
skip-pkg-cache: true
skip-build-cache: false
- name: Upload coverage
if: success()
uses: codecov/codecov-action@v3
with:
file: ./coverage.txt
fail_ci_if_error: false
verbose: true
build:
name: Build Binary
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'
cache: true
- name: Build
run: |
VERSION=$(git describe --tags --always --dirty)
mkdir -p hapax
go build -v -ldflags="-X main.Version=${VERSION}" -o hapax/hapax .
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: hapax-binary
path: ./hapax
retention-days: 5
release:
name: Create Release
needs: [test, build]
runs-on: ubuntu-latest
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/v')
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generate changelog
id: changelog
run: |
echo "CHANGELOG<<EOF" >> $GITHUB_ENV
# Get tag message for overview
TAG_MSG=$(git tag -l --format='%(contents)' $(git describe --tags --abbrev=0))
echo "$TAG_MSG" >> $GITHUB_ENV
echo "" >> $GITHUB_ENV
# For first release, get all commits
if ! git tag --sort=-v:refname | grep -q '^v'; then
RANGE="$(git rev-list --max-parents=0 HEAD)..HEAD"
else
RANGE="$(git describe --tags --abbrev=0 HEAD^)..HEAD"
fi
echo "## Changes" >> $GITHUB_ENV
echo "" >> $GITHUB_ENV
# Features
echo "### Features" >> $GITHUB_ENV
# First maintainer commits without attribution
git log $RANGE --pretty=format:'* %s ([%h](https://github.com/teilomillet/hapax/commit/%H))' --author="teilomillet" | grep -i '^* feat' | sed 's/feat: /* /' >> $GITHUB_ENV || true
# Then contributor commits with attribution
git log $RANGE --pretty=format:'* %s (%aN) ([%h](https://github.com/teilomillet/hapax/commit/%H))' | grep -i '^* feat' | grep -v '(teilomillet)' | sed 's/feat: /* /' >> $GITHUB_ENV || true
echo "" >> $GITHUB_ENV
# Fixes
echo "### Bug Fixes" >> $GITHUB_ENV
# Maintainer fixes without attribution
git log $RANGE --pretty=format:'* %s ([%h](https://github.com/teilomillet/hapax/commit/%H))' --author="teilomillet" | grep -i '^* fix' | sed 's/fix: /* /' >> $GITHUB_ENV || true
# Contributor fixes with attribution
git log $RANGE --pretty=format:'* %s (%aN) ([%h](https://github.com/teilomillet/hapax/commit/%H))' | grep -i '^* fix' | grep -v '(teilomillet)' | sed 's/fix: /* /' >> $GITHUB_ENV || true
echo "" >> $GITHUB_ENV
# Documentation
echo "### Documentation" >> $GITHUB_ENV
# Maintainer docs without attribution
git log $RANGE --pretty=format:'* %s ([%h](https://github.com/teilomillet/hapax/commit/%H))' --author="teilomillet" | grep -i '^* docs' | sed 's/docs: /* /' >> $GITHUB_ENV || true
# Contributor docs with attribution
git log $RANGE --pretty=format:'* %s (%aN) ([%h](https://github.com/teilomillet/hapax/commit/%H))' | grep -i '^* docs' | grep -v '(teilomillet)' | sed 's/docs: /* /' >> $GITHUB_ENV || true
echo "" >> $GITHUB_ENV
# Dependencies
echo "## Dependency Updates" >> $GITHUB_ENV
echo "" >> $GITHUB_ENV
if [ -f "go.mod" ]; then
echo '```diff' >> $GITHUB_ENV
if git rev-parse --verify HEAD^ >/dev/null 2>&1; then
git diff HEAD^ HEAD go.mod | grep '^[+-]' | grep -v '^[+-]module' >> $GITHUB_ENV || true
fi
echo '```' >> $GITHUB_ENV
fi
echo "" >> $GITHUB_ENV
# List contributors (excluding maintainer)
echo "## Contributors" >> $GITHUB_ENV
git log $RANGE --format='%aN' | sort -u | grep -v 'teilomillet' | while read name; do
echo "* @$name" >> $GITHUB_ENV
done
echo "EOF" >> $GITHUB_ENV
- name: Download binary
uses: actions/download-artifact@v4
with:
name: hapax-binary
path: ./
- name: Create Release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
body: ${{ env.CHANGELOG }}
files: ./hapax/hapax
draft: false
prerelease: false
generate_release_notes: false