Repository navigation
89 lines (77 loc) · 2.98 KB
/
Copy pathtest.yml
File metadata and controls
89 lines (77 loc) · 2.98 KB
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
name: Tests
on:
workflow_call:
secrets:
# Declared so callers can pass this one secret explicitly instead of
# `secrets: inherit`. Optional: pull requests from forks receive no
# secrets at all, and codecov accepts tokenless uploads for public
# repositories, so an empty value degrades rather than fails.
CODECOV_TOKEN:
required: false
permissions:
contents: read
jobs:
test-go-code:
name: Test Go Code (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-8cores-32gb]
fail-fast: false
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
- name: Set up Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7
with:
go-version: 'stable'
cache: true # This caches go modules based on go.sum
cache-dependency-path: go.sum
# Download all dependencies upfront (will be cached)
- name: Download Go dependencies
run: |
go mod download
go mod verify
# Cache Go build cache for faster compilation
# Note: ~/go/pkg/mod is already cached by actions/setup-go with cache: true
- name: Cache Go build cache
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6
with:
path: ~/.cache/go-build
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-build-
# Cache Go tools (gotestfmt only for tests)
- name: Cache Go tools
id: cache-go-tools
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6
with:
path: ~/go/bin
key: ${{ runner.os }}-go-tools-${{ hashFiles('go.mod') }}-gotestfmt-v2
restore-keys: |
${{ runner.os }}-go-tools-
# Only install gotestfmt if not cached
- name: Install gotestfmt (if not cached)
if: steps.cache-go-tools.outputs.cache-hit != 'true'
run: go install github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@latest
- name: Install Task
uses: arduino/setup-task@c0bc642852239c2689f73f4ea6459c29405f3c52 # v3.0.0
with:
version: 3.44.1
repo-token: ${{ secrets.GITHUB_TOKEN }}
# Run tests with all dependencies already cached
- name: Run tests with coverage
run: task test-coverage
- name: Upload coverage reports to Codecov with GitHub Action
if: startsWith(matrix.os, 'ubuntu')
uses: codecov/codecov-action@303a32d7a59b442fa8d48b6a1cc6825c09c847a5 # v7.1.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: stacklok/toolhive
- name: Upload coverage to Coveralls
if: startsWith(matrix.os, 'ubuntu')
uses: coverallsapp/github-action@8d6379e14d29928660c4ba802d8e85393440b329 # v2
with:
file: coverage/coverage.out
fail-on-error: false