Skip to content

Commit 6cf741c

Browse files
committed
ci: added sample packages to exercice CI pipelines
* added local workflows that call the shared ones to test evolutions * added job summary to display in github action UI. * added sample app to run test * added future workplan to README Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
1 parent bac60e1 commit 6cf741c

13 files changed

Lines changed: 297 additions & 6 deletions

File tree

.github/workflows/go-test.yml

Lines changed: 94 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ on:
66
jobs:
77
lint:
88
name: Lint
9+
# description: |
10+
# Lint uses golangci-lint github action and lints only changes from master.
11+
#
12+
# It will run on the latest go version.
13+
#
14+
# We rely on golangci-lint to automatically disable linters that do not apply to the minimum required go version
15+
# currently defined in go.mod.
16+
#
17+
# At this moment, .golangci.yml configuration files are not shared: each repository must have its configuration.
918
runs-on: ubuntu-latest
1019
steps:
1120
- uses: actions/checkout@v5
@@ -19,11 +28,31 @@ jobs:
1928
with:
2029
version: latest
2130
only-new-issues: true
22-
skip-cache: true
31+
skip-cache: false
32+
- name: Linting complete # <- report summary when we have good news to report
33+
run: |
34+
echo "### Your changes to the go code look good. 👍" >> $GITHUB_STEP_SUMMARY
35+
echo "" >> $GITHUB_STEP_SUMMARY
36+
echo "> ℹ️ INFO: we use [golangci-lint action](https://github.com/golangci/golangci-lint-action)" >> $GITHUB_STEP_SUMMARY
37+
echo "> to lint any change to go code from master" >> $GITHUB_STEP_SUMMARY
2338
2439
unit_tests:
2540
name: Unit tests
41+
# description: |
42+
# Run go unit tests run x6: linux, mac & windows on the 2 latest go versions.
43+
#
44+
# Run tests with the -race flag.
45+
#
46+
# Captures test coverage and uploads it to codecov.com.
2647
runs-on: ${{ matrix.os }}
48+
outputs:
49+
# NOTE(fredbi): as of Aug. 2025, there is no way to have github actions declare outputs dynamically
50+
test_result_oldstable_ubuntu_latest: "${{ steps.goreport.outputs.test_result_oldstable_ubuntu_latest }}"
51+
test_result_oldstable_macos_latest: "${{ steps.goreport.outputs.test_result_oldstable_macos_latest }}"
52+
test_result_oldstable_windows_latest: "${{ steps.goreport.outputs.test_result_oldstable_windows_latest }}"
53+
test_result_stable_ubuntu_latest: "${{ steps.goreport.outputs.test_result_stable_ubuntu_latest }}"
54+
test_result_stable_macos_latest: "${{ steps.goreport.outputs.test_result_stable_macos_latest }}"
55+
test_result_stable_windows_latest: "${{ steps.goreport.outputs.test_result_stable_windows_latest }}"
2756

2857
strategy:
2958
matrix:
@@ -35,26 +64,85 @@ jobs:
3564
with:
3665
go-version: '${{ matrix.go_version }}'
3766
check-latest: true
38-
cache: true
67+
cache: true # <- cache key is go.sum
3968

4069
- uses: actions/checkout@v5
70+
4171
- name: Run unit tests
72+
# description: |
73+
# runs unit tests with test coverage assuming that this repository contains only one module,
74+
# with a go.mod located at the root.
75+
id: gotest
76+
shell: bash
77+
run: |
78+
go test -v \
79+
-race \
80+
-coverprofile="coverage-${{ matrix.os }}.${{ matrix.go_version }}.out" \
81+
-covermode=atomic \
82+
-coverpkg=$(go list ./... |paste -sd ",") \
83+
./...
84+
85+
- name: Report test
86+
if: ${{ success() || failure() }}
87+
id: goreport
4288
shell: bash
43-
run: go test -v -race -coverprofile="coverage-${{ matrix.os }}.${{ matrix.go_version }}.out" -covermode=atomic -coverpkg=$(go list)/... ./...
89+
run: |
90+
icon="✅"
91+
if [[ "${{ steps.gotest.outcome }}" != "success" ]] ; then
92+
icon="🚫"
93+
fi
94+
echo "test_result_${{ matrix.go_version }}_$(echo "${{ matrix.os }}"|tr '-' '_')='| ${{ matrix.go_version }} | ${{ matrix.os }} | ${icon} ${{ steps.gotest.outcome }} |'" >> "$GITHUB_OUTPUT"
4495
4596
- name: Upload coverage to codecov
4697
uses: codecov/codecov-action@v5
4798
with:
4899
files: './coverage-${{ matrix.os }}.${{ matrix.go_version }}.out'
49100
flags: '${{ matrix.go_version }}-${{ matrix.os }}'
50101
fail_ci_if_error: false
51-
verbose: true
102+
verbose: false
52103

53104
all_tests:
54-
needs: [ unit_tests ]
55105
name: All tests
106+
# description: |
107+
# This job regroups all tests launched as a matrix, so we may define a branch protection rule
108+
# just on that job rather than each matrix job independently.
109+
needs: [ unit_tests ] # <- requires all unit_tests jobs to be successful.
110+
env:
111+
test_result: '${{ join(needs.unit_tests.outputs.*) }}' # <- this is a comma-separated list of quoted strings
56112
runs-on: ubuntu-latest
57113
steps:
58114
- name: Tests complete
59115
run: |
60-
echo "All tests completed"
116+
echo "### All tests completed. 👍" >> $GITHUB_STEP_SUMMARY
117+
echo "" >> $GITHUB_STEP_SUMMARY
118+
echo "> ℹ️ INFO: we run unit tests in 6 different configurations of OS and go version." >> $GITHUB_STEP_SUMMARY
119+
echo "> At this moment, we don't run architecture-specific test runs" >> $GITHUB_STEP_SUMMARY
120+
echo "" >> $GITHUB_STEP_SUMMARY
121+
echo "| go version | OS | Result |" >> $GITHUB_STEP_SUMMARY
122+
echo "|------------|----|--------|" >> $GITHUB_STEP_SUMMARY
123+
declare -a lines
124+
eval "lines=($(echo $test_result|tr ',' ' '))"
125+
for line in "${lines[@]}";do echo "${line}" ; done >> $GITHUB_STEP_SUMMARY
126+
127+
some_failed_tests:
128+
name: Some tests have failed
129+
# description: |
130+
# This job is only here to report a summary of failed tests in the github actions UI.
131+
needs: [ unit_tests ] # <- requires all unit_tests jobs to be completed, but not all where successfull.
132+
if: ${{ failure() }}
133+
env:
134+
test_result: '${{ join(needs.unit_tests.outputs.*) }}'
135+
runs-on: ubuntu-latest
136+
steps:
137+
- name: Tests failed
138+
run: |
139+
echo "### Some tests have failed. 🚫" >> $GITHUB_STEP_SUMMARY
140+
echo "" >> $GITHUB_STEP_SUMMARY
141+
echo "> ℹ️ INFO: testing halted on first encountered failure." >> $GITHUB_STEP_SUMMARY
142+
echo "> Some configurations may not have been tested yet." >> $GITHUB_STEP_SUMMARY
143+
echo "" >> $GITHUB_STEP_SUMMARY
144+
echo "| go version | OS | Result |" >> $GITHUB_STEP_SUMMARY
145+
echo "|------------|----|--------|" >> $GITHUB_STEP_SUMMARY
146+
declare -a lines
147+
eval "lines=($(echo $test_result|tr ',' ' '))"
148+
for line in "${lines[@]}";do echo "${line}" ; done >> $GITHUB_STEP_SUMMARY
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Dependabot auto-merge
2+
3+
# This workflow mimics how a go-openapi repo would typically invoke the common workflow.
4+
5+
on: pull_request
6+
7+
8+
permissions:
9+
contents: write
10+
pull-requests: write
11+
12+
jobs:
13+
dependabot:
14+
uses: ./.github/workflows/auto-merge.yml
15+
secrets: inherit
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: go test
2+
3+
# This workflow mimics how a go-openapi repo would typically invoke the common workflow.
4+
5+
on:
6+
push:
7+
tags:
8+
- v*
9+
branches:
10+
- master
11+
12+
pull_request:
13+
14+
jobs:
15+
test:
16+
uses: ./.github/workflows/go-test.yml
17+
secrets: inherit

.golangci.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
version: "2"
2+
linters:
3+
default: all
4+
disable:
5+
- cyclop
6+
- depguard
7+
- errchkjson
8+
- errorlint
9+
- exhaustruct
10+
- forcetypeassert
11+
- funlen
12+
- gochecknoglobals
13+
- gochecknoinits
14+
- gocognit
15+
- godot
16+
- godox
17+
- gosmopolitan
18+
- inamedparam
19+
- intrange # disabled while < go1.22
20+
- ireturn
21+
- lll
22+
- musttag
23+
- nestif
24+
- nlreturn
25+
- nonamedreturns
26+
- noinlineerr
27+
- paralleltest
28+
- recvcheck
29+
- testpackage
30+
- thelper
31+
- tparallel
32+
- unparam
33+
- varnamelen
34+
- whitespace
35+
- wrapcheck
36+
- wsl
37+
- wsl_v5
38+
settings:
39+
dupl:
40+
threshold: 200
41+
goconst:
42+
min-len: 2
43+
min-occurrences: 3
44+
gocyclo:
45+
min-complexity: 45
46+
exclusions:
47+
generated: lax
48+
presets:
49+
- comments
50+
- common-false-positives
51+
- legacy
52+
- std-error-handling
53+
paths:
54+
- third_party$
55+
- builtin$
56+
- examples$
57+
formatters:
58+
enable:
59+
- gofmt
60+
- goimports
61+
exclusions:
62+
generated: lax
63+
paths:
64+
- third_party$
65+
- builtin$
66+
- examples$
67+
issues:
68+
# Maximum issues count per one linter.
69+
# Set to 0 to disable.
70+
# Default: 50
71+
max-issues-per-linter: 0
72+
# Maximum count of issues with the same text.
73+
# Set to 0 to disable.
74+
# Default: 3
75+
max-same-issues: 0

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,30 @@ Common CI workflows and setup for go-openapi repos.
66
* shared dependabot config
77

88
NOTE: at this moment, it is difficult to share the golangci-lint config, so that one is not shared yet.
9+
10+
## Motivation
11+
12+
It took a while, but we eventually managed to align all checks, tests and dependabot rules declared in the
13+
family of go-openapi repos.
14+
15+
Now we'd like to be able to maintain, enrich and improve these checks without worrying too much about
16+
the burden to replicate it about a dozen times.
17+
18+
## Contemplated enhancements
19+
20+
* [x] enrich github actions UI with a job summary
21+
* [] version common workflows, so we can limit the impact of a change
22+
* [] verify that go.sum cache for tests works (should be enabled)
23+
* [] share mono repo workflows (see github.com/go-openapi/swag/.github/workflows)
24+
* [] manage somehow to share golangci config (with local merge)
25+
* [] manage somehow to share / replicate dependabot config
26+
* [] add markdown linting for docs
27+
* [] golangci-lint: check valid PR comments etc
28+
* [] add spellcheck for docs (and code?)
29+
* [] use non-blocking, scheduled, proactive full linting to check for the impact of new linters, new go versions etc
30+
* [] (possibility) take over hugo & doc gen part from go-swagger
31+
* [] (possibility) take over release part from go-swagger
32+
* [] produce hugo github page with all latest tagged versions (incl. mono repo)
33+
* [] add bot to filter PRs, issues
34+
* [] check with github API that all repo settings (branch protection rules, etc) are identical
35+
* [] comment PRs and issues

audit/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Audit
2+
3+
Audit of github repos to check for inconsistencies.

doc/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# doc
2+
3+
Documentation check and generation tools.

go.mod

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module github.com/go-openapi/ci-workflows
2+
3+
go 1.24.2
4+
5+
require github.com/stretchr/testify v1.10.0
6+
7+
require (
8+
github.com/davecgh/go-spew v1.1.1 // indirect
9+
github.com/pmezard/go-difflib v1.0.0 // indirect
10+
gopkg.in/yaml.v3 v3.0.1 // indirect
11+
)

go.sum

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
4+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
5+
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
6+
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
7+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
8+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
9+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
10+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

sample/pkg/pkg.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Package pkg exercises CI pipelines.
2+
package pkg
3+
4+
func Pkg() string {
5+
return ""
6+
}

0 commit comments

Comments
 (0)