Repository navigation
116 lines (100 loc) · 3.23 KB
/
Copy pathci.yml
File metadata and controls
116 lines (100 loc) · 3.23 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
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
name: CI
# An unfiltered `push` matches tags too, so a release tag would re-run this against a commit
# already tested on main. `**` and not `*`, which does not match a branch name with a slash.
on:
push:
tags-ignore: ['**']
pull_request:
permissions:
contents: read
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Clone the code
uses: actions/checkout@v5
- name: Setup Go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
- name: Run linter
uses: golangci/golangci-lint-action@v9
with:
version: v2.4.0
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Clone the code
uses: actions/checkout@v5
- name: Setup Go
uses: actions/setup-go@v6
with:
go-version-file: go.mod
- name: Running Tests
run: |
go mod tidy
make test
# The matrix is DISCOVERED, so a new component is picked up by existing here rather than by
# someone remembering to add a line below. A component added without CI would never be built or
# tested by anything -- root `./...` stops at a nested go.mod. See components/README.md.
#
# Lint and test share this one job, which is why they live in one workflow: `needs` cannot reach a
# job in another file, so splitting them would mean two copies of the discovery rule -- and a rule
# changed in only one copy would lint a set of components and test a different set, silently.
discover:
name: Discover components
runs-on: ubuntu-latest
outputs:
components: ${{ steps.list.outputs.components }}
steps:
- name: Clone the code
uses: actions/checkout@v5
# Keyed on the Makefile, matching the root Makefile's own discovery.
- id: list
run: |
names=$(ls -d components/*/Makefile | xargs -n1 dirname | xargs -n1 basename | jq -R . | jq -sc .)
echo "components=$names" >> "$GITHUB_OUTPUT"
lint-components:
name: Lint components
runs-on: ubuntu-latest
needs: discover
strategy:
fail-fast: false
matrix:
component: ${{ fromJSON(needs.discover.outputs.components) }}
steps:
- name: Clone the code
uses: actions/checkout@v5
- name: Setup Go
uses: actions/setup-go@v6
with:
go-version-file: components/${{ matrix.component }}/go.mod
- name: Run linter
uses: golangci/golangci-lint-action@v9
with:
version: v2.4.0
working-directory: components/${{ matrix.component }}
args: --config ${{ github.workspace }}/.golangci.yml
test-components:
name: Test components
runs-on: ubuntu-latest
needs: discover
strategy:
fail-fast: false
matrix:
component: ${{ fromJSON(needs.discover.outputs.components) }}
steps:
- name: Clone the code
uses: actions/checkout@v5
- name: Setup Go
uses: actions/setup-go@v6
with:
go-version-file: components/${{ matrix.component }}/go.mod
- name: Running Tests
working-directory: components/${{ matrix.component }}
run: |
go mod tidy
git diff --exit-code go.mod go.sum
make test