-
Notifications
You must be signed in to change notification settings - Fork 222
131 lines (129 loc) · 4.58 KB
/
github-actions.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
name: checks
env:
GO_VERSION: '1.23'
on:
pull_request:
branches:
- master
- stable/**
push:
branches:
- master
- stable/**
permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read
jobs:
base-ref:
name: base-ref
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.base.ref }}
- name: Check base ref
# Case-insensitive matches for:
# 1. Jira references (trid-12345)
# 2. PR numbers (#1234)
# 3. Squashed commit messages (* message)
run: |
git log --format=%B -n 1 | \
perl -ne 'die "Base ref has invalid commit message" if (/(?:trid|astractl)(?: |-)\d+/ig || /#\d+/ig || /\* \w/ig)'
golangci:
name: linters
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
check-latest: true
- uses: actions/checkout@v4
- name: golangci-lint
# Switch back to the official action after this bug is fixed: https://github.com/golangci/golangci-lint/issues/3107
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.61.0
$(go env GOPATH)/bin/golangci-lint run --out-format=github-actions --timeout=15m --verbose
go-mod-tidy:
name: go mod tidy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
check-latest: true
# This takes a little extra time on the first run but ensures later runs for new commits are fast.
- uses: actions/cache@v2
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Run go mod tidy
run: |
go mod tidy -compat=$GO_VERSION
git diff --exit-code go.mod go.sum
unit:
strategy:
matrix:
os: [ ubuntu-latest, windows-latest, macos-latest ]
runs-on: ${{matrix.os}}
name: unit tests ${{ matrix.os }}
steps:
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
check-latest: true
- uses: actions/checkout@v4
- uses: actions/cache@v4
with:
# In order:
# * Module download cache
# * Build cache (Linux)
# * Build cache (Mac)
# * Build cache (Windows)
path: |
~/go/pkg/mod
~/.cache/go-build
~/Library/Caches/go-build
~\AppData\Local\go-build
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- if: runner.os == 'Windows'
name: Run the tests (on Windows)
run: |
Set-PSDebug -Trace 2
go version
mkdir ${{ runner.temp }}\${{ runner.os }}-coverage-binary.out
go test -v ./... -covermode=count -- -test.gocoverdir=${{ runner.temp }}\${{ runner.os }}-coverage-binary.out
go tool covdata textfmt -i=${{ runner.temp }}\${{ runner.os }}-coverage-binary.out -o ${{ runner.os }}-coverage.out
- if: runner.os != 'Windows'
name: Run the tests (not on Windows)
run: |
set -x
go version
echo mkdir ${{ runner.temp }}/${{ runner.os }}-coverage-binary.out
mkdir ${{ runner.temp }}/${{ runner.os }}-coverage-binary.out
go test -v ./... -covermode=count -test.gocoverdir=${{ runner.temp }}/${{ runner.os }}-coverage-binary.out
go tool covdata textfmt -i=${{ runner.temp }}/${{ runner.os }}-coverage-binary.out -o ${{ runner.os }}-coverage.out
- if: runner.os != 'Windows'
name: Prepare the artifact
run: |
go tool cover -html=${{ runner.os }}-coverage.out -o ${{ runner.os }}-coverage.html
- name: Get run details
env:
PR_TITLE: ${{ github.event.pull_request.title }}
run: |
echo "PR_Title=$PR_TITLE"
echo "Run_Number=${{ github.run_number }}"
echo "PR_Number=${{ github.event.pull_request.number }}"
- if: runner.os != 'Windows'
name: Upload the artifact
uses: actions/upload-artifact@v4
with:
name: "coverage-report-${{ runner.os }}-${{ github.run_number }}.html"
path: ${{ runner.os }}-coverage.html