-
Notifications
You must be signed in to change notification settings - Fork 0
135 lines (114 loc) · 3.75 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
name: Go CI/CD
on:
push:
branches: [ main ]
tags:
- 'v0.[1-9][0-9]*.[0-9]+' # Matches v0.1.0, v0.2.0, v0.10.0, etc.
- 'v0.[1-9][0-9]*.[0-9]+[0-9]' # Also matches v0.1.10, v0.2.23, 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: startsWith(github.ref, 'refs/tags/')
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generate changelog
id: changelog
run: |
echo "CHANGELOG<<EOF" >> $GITHUB_ENV
echo "## What's Changed" >> $GITHUB_ENV
echo "" >> $GITHUB_ENV
# Features
echo "### Features" >> $GITHUB_ENV
git log $(git describe --tags --abbrev=0 HEAD^)..HEAD --pretty=format:'%s' | grep -i '^feat' | sed 's/feat: /* /' >> $GITHUB_ENV || true
# Fixes
echo "" >> $GITHUB_ENV
echo "### Fixes" >> $GITHUB_ENV
git log $(git describe --tags --abbrev=0 HEAD^)..HEAD --pretty=format:'%s' | grep -i '^fix' | sed 's/fix: /* /' >> $GITHUB_ENV || true
# Documentation
echo "" >> $GITHUB_ENV
echo "### Documentation" >> $GITHUB_ENV
git log $(git describe --tags --abbrev=0 HEAD^)..HEAD --pretty=format:'%s' | grep -i '^docs' | sed 's/docs: /* /' >> $GITHUB_ENV || true
# Performance
echo "" >> $GITHUB_ENV
echo "### Performance Improvements" >> $GITHUB_ENV
git log $(git describe --tags --abbrev=0 HEAD^)..HEAD --pretty=format:'%s' | grep -i '^perf' | sed 's/perf: /* /' >> $GITHUB_ENV || true
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
with:
body: ${{ env.CHANGELOG }}
files: ./hapax/hapax
draft: false
prerelease: false
generate_release_notes: true