-
Notifications
You must be signed in to change notification settings - Fork 84
109 lines (96 loc) · 2.88 KB
/
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
name: CI
on:
push:
branches:
- main
pull_request:
workflow_dispatch:
jobs:
test:
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
flags: [""]
arch:
- amd64
runner:
- ubuntu-latest
- macos-latest
- windows-latest
include:
- arch: 386
runner: ubuntu-latest
- arch: amd64
runner: ubuntu-latest
flags: "-race"
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: "1.20"
cache: false
- name: Get Go environment
id: go-env
shell: bash
run: |
echo "cache=$(go env GOCACHE)" >> $GITHUB_ENV
echo "modcache=$(go env GOMODCACHE)" >> $GITHUB_ENV
# Build cache key prefix, using runner OS and arch.
- name: Compute cache prefix
id: cache-prefix
shell: bash
env:
RUNNER_PREFIX: ${{ runner.os }}-${{ runner.arch }}-go
ARCH_PREFIX: ${{ matrix.arch != 'amd64' && format('-{0}', matrix.arch) || '' }}
RACE_PREFIX: ${{ contains(matrix.flags, '-race') && '-race' || '' }}
run: echo "cache_prefix=$RUNNER_PREFIX$ARCH_PREFIX$RACE_PREFIX" >> $GITHUB_ENV
- name: Set up cache
uses: actions/cache@v3
with:
path: |
${{ env.cache }}
${{ env.modcache }}
key: ${{ env.cache_prefix }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ env.cache_prefix }}-
- name: Run tests
env:
GOARCH: ${{ matrix.arch }}
GOFLAGS: ${{ matrix.flags }}
run: go test --timeout 15m ./...
# Keep benchmark up to date.
- name: Run benchmarks
if: ${{ !contains(matrix.flags, '-race') }}
env:
GOARCH: ${{ matrix.arch }}
GOFLAGS: ${{ matrix.flags }}
run: go test --timeout 15m --benchtime 3x --benchmem --bench "Benchmark" --run=$^. ./...
test-examples:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: "1.20"
cache: false
- name: Get Go environment
id: go-env
run: |
echo "cache=$(go env GOCACHE)" >> $GITHUB_ENV
echo "modcache=$(go env GOMODCACHE)" >> $GITHUB_ENV
- name: Set up cache
uses: actions/cache@v3
with:
path: |
${{ env.cache }}
${{ env.modcache }}
key: test-examples-${{ runner.os }}-${{ runner.arch }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
test-examples-${{ runner.os }}-${{ runner.arch }}-go-
- name: Run tests
run: cd examples && go test ./...