Skip to content

Commit 188223c

Browse files
authored
Added coverage, codeclimate, test publishing and improvements (#38)
1 parent bc2b9bc commit 188223c

File tree

8 files changed

+203
-15
lines changed

8 files changed

+203
-15
lines changed

.codeclimate.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
version: "2"
2+
checks:
3+
argument-count:
4+
enabled: false
5+
complex-logic:
6+
enabled: false
7+
identical-code:
8+
enabled: true
9+
file-lines:
10+
enabled: false
11+
method-complexity:
12+
enabled: false
13+
method-count:
14+
enabled: false
15+
method-lines:
16+
enabled: false
17+
nested-control-flow:
18+
enabled: false
19+
return-statements:
20+
enabled: false
21+
similar-code:
22+
enabled: true
23+
24+
exclude_patterns:
25+
- "scripts/"
26+
- ".github/"
27+
- "test/"
28+
- "**/*_test.go"

.github/workflows/build.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
name: Build
22

3-
on: [push]
3+
on:
4+
pull_request:
5+
paths:
6+
- '.github/workflows/build.yml'
7+
- 'cmd/**'
8+
- 'test/**'
9+
- 'go.mod'
10+
- 'go.sum'
11+
- 'makefile'
12+
- '!**/*.md'
13+
push:
14+
branches: [ main ]
15+
16+
concurrency:
17+
group: ${{ github.workflow }}-${{ github.ref }}
18+
cancel-in-progress: true
419

520
permissions:
621
contents: read

.github/workflows/codeql.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,18 @@ on:
1515
push:
1616
branches: ["main"]
1717
pull_request:
18-
# The branches below must be a subset of the branches above
19-
branches: ["main"]
20-
schedule:
21-
- cron: "0 0 * * 1"
18+
paths:
19+
- '.github/workflows/codeql.yml'
20+
- 'cmd/**'
21+
- 'test/**'
22+
- 'go.mod'
23+
- 'go.sum'
24+
- 'makefile'
25+
- '!**/*.md'
26+
27+
concurrency:
28+
group: ${{ github.workflow }}-${{ github.ref }}
29+
cancel-in-progress: true
2230

2331
permissions:
2432
contents: read

.github/workflows/dependency-review.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,22 @@
77
#
88
# Source repository: https://github.com/actions/dependency-review-action
99
name: 'Dependency Review'
10-
on: [pull_request]
10+
on:
11+
pull_request:
12+
paths:
13+
- '.github/workflows/dependency-review.yml'
14+
- 'cmd/**'
15+
- 'test/**'
16+
- 'go.mod'
17+
- 'go.sum'
18+
- 'makefile'
19+
- '!**/*.md'
20+
push:
21+
branches: [ main ]
22+
23+
concurrency:
24+
group: ${{ github.workflow }}-${{ github.ref }}
25+
cancel-in-progress: true
1126

1227
permissions:
1328
contents: read

.github/workflows/scorecards.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010
# To guarantee Maintained check is occasionally updated. See
1111
# https://github.com/ossf/scorecard/blob/main/docs/checks.md#maintained
1212
schedule:
13-
- cron: '20 7 * * 2'
13+
- cron: '0 0 * * *'
1414
push:
1515
branches: ["main"]
1616

.github/workflows/test.yml

Lines changed: 125 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
name: Test
22

3-
on: [push, pull_request, workflow_call]
3+
on:
4+
pull_request:
5+
paths:
6+
- '.github/workflows/test.yml'
7+
- 'cmd/**'
8+
- 'test/**'
9+
- 'go.mod'
10+
- 'go.sum'
11+
- 'makefile'
12+
- '!**/*.md'
13+
push:
14+
branches: [ main ]
15+
workflow_call:
16+
17+
concurrency:
18+
group: ${{ github.workflow }}-${{ github.ref }}
19+
cancel-in-progress: true
420

521
permissions:
622
contents: read
@@ -86,21 +102,125 @@ jobs:
86102
strategy:
87103
matrix:
88104
platform: [ubuntu-latest, windows-latest]
89-
go: [1.22.x]
90-
name: '${{ matrix.platform }} | ${{ matrix.go }}'
105+
include:
106+
- platform: ubuntu-latest
107+
target: linux
108+
- platform: windows-latest
109+
target: windows
110+
name: 'Test (${{ matrix.target }})'
91111
runs-on: ${{ matrix.platform }}
92112
steps:
93113
- name: Harden the runner (Audit all outbound calls)
94114
uses: step-security/harden-runner@4d991eb9b905ef189e4c376166672c3f2f230481 # v2.11.0
95115
with:
96116
egress-policy: audit
97117

118+
- name: Install linux deps
119+
if: ${{ startsWith(matrix.platform, 'ubuntu') }}
120+
run: |
121+
sudo apt-get update
122+
sudo apt-get install \
123+
ninja-build
124+
125+
- name: Install windows deps
126+
if: ${{ startsWith(matrix.platform, 'windows') }}
127+
run: choco install -y ninja
128+
98129
- name: Check out repository code
99130
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
100-
- name: Install go 1.22
131+
132+
- name: Install Go
101133
uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
102134
with:
103-
go-version: ${{ matrix.go }}
135+
go-version-file: go.mod
136+
check-latest: true
137+
cache-dependency-path: |
138+
**/go.mod
139+
**/go.sum
140+
141+
- name: Install go-junit-report
142+
run: go install github.com/jstemmer/go-junit-report/v2@latest
143+
104144
- name: Unit testing
145+
run: |
146+
mkdir -p build
147+
go test -v ./... > build/vidx2pidxtests-${{ matrix.target }}-amd64.txt
148+
149+
- name: Generate JUnit test report
150+
if: always()
151+
run: |
152+
go-junit-report -set-exit-code -in build/vidx2pidxtests-${{ matrix.target }}-amd64.txt -iocopy -out build/vidx2pidx-testreport-${{ matrix.target }}-amd64.xml
153+
154+
- name: Archive unit test results
155+
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
156+
with:
157+
name: test-results-${{ matrix.target }}
158+
path: ./build/vidx2pidx-testreport-*.xml
159+
if-no-files-found: error
160+
161+
publish-test-results:
162+
if: ${{ github.workflow != 'Release' }}
163+
name: "Publish Tests Results"
164+
needs: [ test ]
165+
runs-on: ubuntu-latest
166+
permissions:
167+
checks: write
168+
pull-requests: write
169+
steps:
170+
- name: Harden Runner
171+
uses: step-security/harden-runner@cb605e52c26070c328afc4562f0b4ada7618a84e # v2.10.4
172+
with:
173+
egress-policy: audit
174+
175+
- name: Download Artifacts
176+
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
177+
with:
178+
path: artifacts
179+
180+
- name: publish test results
181+
uses: EnricoMi/publish-unit-test-result-action@170bf24d20d201b842d7a52403b73ed297e6645b # v2.18.0
182+
with:
183+
files: "artifacts/**/vidx2pidx-testreport-*.xml"
184+
report_individual_runs: true
185+
186+
coverage:
187+
if: ${{ github.workflow != 'Release' && github.repository == 'Open-CMSIS-Pack/vidx2pidx' }}
188+
needs: [ test ]
189+
name: 'Coverage check'
190+
runs-on: ubuntu-latest
191+
steps:
192+
- name: Harden Runner
193+
uses: step-security/harden-runner@cb605e52c26070c328afc4562f0b4ada7618a84e # v2.10.4
194+
with:
195+
egress-policy: audit
196+
197+
- name: Install dependencies
198+
run: |
199+
sudo apt-get update
200+
sudo apt-get install \
201+
ninja-build
202+
203+
- name: Check out repository code
204+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
205+
206+
- name: Install Go
207+
uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
208+
with:
209+
go-version-file: go.mod
210+
check-latest: true
211+
cache-dependency-path: |
212+
**/go.mod
213+
**/go.sum
214+
215+
- name: Check coverage
105216
run: |
106217
make coverage-check
218+
219+
- name: Publish coverage report to Code Climate
220+
uses: paambaati/codeclimate-action@f429536ee076d758a24705203199548125a28ca7 # v9.0.0
221+
env:
222+
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
223+
with:
224+
debug: true
225+
coverageLocations: ./build/cover.out:gocov
226+
prefix: github.com/open-cmsis-pack/vidx2pidx

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
[![Go Report Card](https://goreportcard.com/badge/github.com/open-cmsis-pack/vidx2pidx)](https://goreportcard.com/report/github.com/open-cmsis-pack/vidx2pidx)
55
[![GoDoc](https://godoc.org/github.com/open-cmsis-pack/vidx2pidx?status.svg)](https://godoc.org/github.com/open-cmsis-pack/vidx2pidx)
66

7+
[![Maintainability](https://api.codeclimate.com/v1/badges/b97b1ecaad39a763ceca/maintainability)](https://codeclimate.com/github/Open-CMSIS-Pack/vidx2pidx/maintainability)
8+
[![Test Coverage](https://api.codeclimate.com/v1/badges/b97b1ecaad39a763ceca/test_coverage)](https://codeclimate.com/github/Open-CMSIS-Pack/vidx2pidx/test_coverage)
79
[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/Open-CMSIS-Pack/vidx2pidx/badge)](https://securityscorecards.dev/viewer/?uri=github.com/Open-CMSIS-Pack/vidx2pidx)
810

911
# vidx2pidx: Open-CMSIS-Pack Package Index Generator Tool

makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ coverage-report:
7070
go tool cover -html=cover.out
7171

7272
coverage-check:
73-
TESTING=1 go test ./... $(ARGS) -coverprofile cover.out
74-
tail -n +2 cover.out | grep -v -e " 1$$" | grep -v main.go | tee coverage-check.out
75-
test ! -s coverage-check.out
73+
TESTING=1 mkdir -p build && go test ./... $(ARGS) -coverprofile build/cover.out
74+
test `go tool cover -func build/cover.out | tail -1 | awk '{print ($$3 + 0)*10}'` -gt 700
75+
7676

7777
release: test-all build/vidx2pidx
7878
@./scripts/release

0 commit comments

Comments
 (0)