-
Notifications
You must be signed in to change notification settings - Fork 587
109 lines (95 loc) · 3.31 KB
/
unit-tests.yaml
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
on:
workflow_call:
inputs:
runs-on:
description: 'A tag to indicate which runner to use'
required: true
type: string
gochannel:
description: 'The snap store channel to use to install the go snap'
required: true
type: string
skip-coverage:
description: 'If true, will not generate test coverage files'
type: boolean
default: false
required: false
go-build-tags:
description: 'Tag to add to go test'
type: string
required: false
go-test-race:
description: 'If true, will add race tag to go test'
type: boolean
default: false
required: false
snapd-debug:
description: 'If true, will set SNAPD_DEBUG=1'
type: boolean
default: false
required: false
jobs:
unit-tests:
name: "unit-tests (${{ inputs.gochannel }} ${{ inputs.go-build-tags }}
${{ inputs.go-test-race && ' test-race' || ''}}
${{ inputs.snapd-debug && ' snapd-debug' || ''}})"
runs-on: ${{ inputs.runs-on }}
env:
# Set PATH to ignore the load of magic binaries from /usr/local/bin And
# to use the go snap automatically. Note that we install go from the
# snap in a step below. Without this we get the GitHub-controlled latest
# version of go.
PATH: /snap/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:${{ github.workspace }}/bin
GOROOT: ""
GO_BUILD_TAGS: ${{ inputs.go-build-tags }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download and install Debian dependencies
# Github does not allow variables in "uses"; this has to be a hard-coded path
uses: ./.github/actions/download-install-debian-deps
with:
snapd-src-dir: "${{ github.workspace }}"
# golang latest ensures things work on the edge
- name: Install the go snap
run: |
sudo snap install --classic --channel=${{ inputs.gochannel }} go
- name: Get deps
run: |
./get-deps.sh
- name: Build C
run: |
cd cmd/
./autogen.sh
make -j$(nproc)
- name: Build Go
run: |
go build ./...
- name: Test C
run: |
cd cmd/ && make distcheck
- name: Set SNAPD_DEBUG=1
if: ${{ inputs.snapd-debug }}
run: echo "SNAPD_DEBUG=1" >> $GITHUB_ENV
- name: Set GO_TEST_RACE=1
if: ${{ inputs.go-test-race }}
run: echo "GO_TEST_RACE=1" >> $GITHUB_ENV
- name: Set SKIP_COVERAGE=1
if: ${{ inputs.skip-coverage }}
run: echo "SKIP_COVERAGE=1" >> $GITHUB_ENV
- name: Test Go
run: |
./run-checks --unit
- name: Create coverage results name
if: ${{ ! inputs.skip-coverage }}
run: |
converted=$(tr '/' '-' <<<${{ inputs.gochannel }})
name="coverage-files-${converted}-${{ inputs.go-build-tags || 'notags' }}${{ inputs.go-test-race && '-race' || ''}}${{ inputs.snapd-debug && '-snapddebug' || ''}}"
echo "COVERAGE_NAME=$name" >> $GITHUB_ENV
- name: Upload the coverage results
if: ${{ ! inputs.skip-coverage }}
uses: actions/upload-artifact@v4
with:
include-hidden-files: true
name: "${{ env.COVERAGE_NAME }}"
path: "${{ github.workspace }}/.coverage/coverage*.cov"