Skip to content

Commit a5b57ea

Browse files
committed
ci: setup go-openapi
Signed-off-by: Frederic BIDON <[email protected]>
1 parent 331e5ee commit a5b57ea

File tree

9 files changed

+252
-126
lines changed

9 files changed

+252
-126
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 0 additions & 23 deletions
This file was deleted.

.github/ISSUE_TEMPLATE/feature_request.md

Lines changed: 0 additions & 20 deletions
This file was deleted.

.github/dependabot.yaml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directories:
5+
- "**/*"
6+
schedule:
7+
interval: "weekly"
8+
day: "friday"
9+
open-pull-requests-limit: 2 # <- default is 5
10+
allow:
11+
- dependency-type: all
12+
groups: # <- group all github actions updates in a single PR
13+
# 1. development-dependencies are auto-merged
14+
development-dependencies:
15+
patterns:
16+
- '*'
17+
18+
- package-ecosystem: "gomod"
19+
# We define 4 groups of dependencies to regroup update pull requests:
20+
# - development (e.g. test dependencies)
21+
# - go-openapi updates
22+
# - golang.org (e.g. golang.org/x/... packages)
23+
# - other dependencies (direct or indirect)
24+
#
25+
# * All groups are checked once a week and each produce at most 1 PR.
26+
# * All dependabot PRs are auto-approved
27+
#
28+
# Auto-merging policy, when requirements are met:
29+
# 1. development-dependencies are auto-merged
30+
# 2. golang.org-dependencies are auto-merged
31+
# 3. go-openapi patch updates are auto-merged. Minor/major version updates require a manual merge.
32+
# 4. other dependencies require a manual merge
33+
directory: "/"
34+
schedule:
35+
interval: "weekly"
36+
day: "friday"
37+
open-pull-requests-limit: 4
38+
groups:
39+
development-dependencies:
40+
patterns:
41+
- "github.com/stretchr/testify"
42+
43+
golang-org-dependencies:
44+
patterns:
45+
- "golang.org/*"
46+
47+
go-openapi-dependencies:
48+
patterns:
49+
- "github.com/go-openapi/*"
50+
51+
other-dependencies:
52+
exclude-patterns:
53+
- "github.com/go-openapi/*"
54+
- "github.com/stretchr/testify"
55+
- "golang.org/*"

.github/dependabot.yml

Lines changed: 0 additions & 10 deletions
This file was deleted.

.github/pull_request_template.md

Lines changed: 0 additions & 15 deletions
This file was deleted.

.github/workflows/auto-merge.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Dependabot auto-merge
2+
on: pull_request
3+
4+
permissions:
5+
contents: write
6+
pull-requests: write
7+
8+
jobs:
9+
dependabot:
10+
runs-on: ubuntu-latest
11+
if: github.event.pull_request.user.login == 'dependabot[bot]'
12+
steps:
13+
- name: Dependabot metadata
14+
id: metadata
15+
uses: dependabot/fetch-metadata@v2
16+
17+
- name: Auto-approve all dependabot PRs
18+
run: gh pr review --approve "$PR_URL"
19+
env:
20+
PR_URL: ${{github.event.pull_request.html_url}}
21+
GH_TOKEN: ${{secrets.GITHUB_TOKEN}}
22+
23+
- name: Auto-merge dependabot PRs for development dependencies
24+
if: contains(steps.metadata.outputs.dependency-group, 'development-dependencies')
25+
run: gh pr merge --auto --rebase "$PR_URL"
26+
env:
27+
PR_URL: ${{github.event.pull_request.html_url}}
28+
GH_TOKEN: ${{secrets.GITHUB_TOKEN}}
29+
30+
- name: Auto-merge dependabot PRs for go-openapi patches
31+
if: contains(steps.metadata.outputs.dependency-group, 'go-openapi-dependencies') && (steps.metadata.outputs.update-type == 'version-update:semver-minor' || steps.metadata.outputs.update-type == 'version-update:semver-patch')
32+
run: gh pr merge --auto --rebase "$PR_URL"
33+
env:
34+
PR_URL: ${{github.event.pull_request.html_url}}
35+
GH_TOKEN: ${{secrets.GITHUB_TOKEN}}
36+
37+
- name: Auto-merge dependabot PRs for golang.org updates
38+
if: contains(steps.metadata.outputs.dependency-group, 'golang-org-dependencies')
39+
run: gh pr merge --auto --rebase "$PR_URL"
40+
env:
41+
PR_URL: ${{github.event.pull_request.html_url}}
42+
GH_TOKEN: ${{secrets.GITHUB_TOKEN}}
43+

.github/workflows/go-test.yml

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
name: go test
2+
3+
on:
4+
push:
5+
tags:
6+
- v*
7+
branches:
8+
- master
9+
10+
pull_request:
11+
12+
permissions:
13+
pull_requests: read
14+
contents: read
15+
16+
jobs:
17+
module-matrix:
18+
name: Go module matrix
19+
runs-on: ubuntu-latest
20+
21+
outputs:
22+
modules: ${{ steps.modules.outputs.modules }}
23+
24+
steps:
25+
- uses: actions/checkout@v5
26+
- name: Find go modules
27+
id: modules
28+
shell: bash
29+
run: |
30+
# This script finds all go modules declared in this repo and resolves to a relative path to each of those.
31+
#
32+
# NOTES:
33+
#
34+
# > * git bash on a windows runner should support GNU find. find flags should be supported by find on macos.
35+
# > * with go.work file enabled, we may now collect all submodules with go list -m
36+
# >
37+
# > The outcome is currently only used for linting. Tests may now skip that part.
38+
set -euxo pipefail
39+
40+
root="$(git rev-parse --show-toplevel)"
41+
cd "${root}"
42+
43+
declare -i index=0
44+
declare -a all_mods
45+
printf "modules=[" >> "$GITHUB_OUTPUT"
46+
while read module_location ; do
47+
if [ $index -gt 0 ] ; then
48+
printf "," >> "$GITHUB_OUTPUT"
49+
fi
50+
relative_location=${module_location#"$root"/}
51+
module_dir=${relative_location%"/go.mod"}
52+
base_dir="${module_dir#"./"}"
53+
printf " \"${base_dir}\"" >> "$GITHUB_OUTPUT"
54+
all_mods+=("${base_dir}")
55+
((index++)) || true
56+
done < <(go list -f '{{.Dir}}' -m)
57+
printf "]" >> "$GITHUB_OUTPUT"
58+
59+
echo "::notice title=Modules found::${all_mods[@]}"
60+
61+
module-lint:
62+
name: Go module lint
63+
runs-on: ubuntu-latest
64+
needs: [ module-matrix ]
65+
66+
strategy:
67+
matrix:
68+
# all sub modules in this repo must be linted separately
69+
module: ${{ fromJSON(needs.module-matrix.outputs.modules) }}
70+
71+
steps:
72+
- uses: actions/checkout@v5
73+
- uses: actions/setup-go@v6
74+
with:
75+
go-version: stable
76+
check-latest: true
77+
cache: true
78+
cache-dependency-path: '**/go.sum'
79+
- name: golangci-lint
80+
uses: golangci/golangci-lint-action@v8
81+
with:
82+
version: latest
83+
only-new-issues: true
84+
skip-cache: true
85+
# golangci-lint doesn't support go.work to lint multiple modules in one single pass
86+
working-directory: '${{ matrix.module }}'
87+
88+
lint:
89+
needs: [ module-lint ]
90+
name: Lint
91+
runs-on: ubuntu-latest
92+
steps:
93+
- name: Linting complete
94+
run: |
95+
echo "All modules linted"
96+
97+
module-test:
98+
name: Unit tests
99+
runs-on: ${{ matrix.os }}
100+
needs: [ module-matrix ]
101+
102+
strategy:
103+
matrix:
104+
os: [ ubuntu-latest, macos-latest, windows-latest ]
105+
go_version: ['oldstable', 'stable' ]
106+
107+
steps:
108+
- uses: actions/checkout@v5
109+
- uses: actions/setup-go@v6
110+
with:
111+
go-version: '${{ matrix.go_version }}'
112+
check-latest: true
113+
cache: true
114+
cache-dependency-path: '**/go.sum'
115+
116+
- name: Run unit tests on all modules in this repo
117+
shell: bash
118+
env:
119+
# *.coverage.* pattern is automatically detected by codecov
120+
COVER_PROFILE: 'all_modules.coverage.${{ matrix.os }}.${{ matrix.go_version }}.out'
121+
run: |
122+
# when go1.25 becomes the oldstable, we may replace this bash with "go work test"
123+
declare -a ALL_MODULES
124+
BASH_MAJOR=$(echo $BASH_VERSION|cut -d'.' -f1)
125+
if [[ "${BASH_MAJOR}" -ge 4 ]] ; then
126+
mapfile ALL_MODULES < <(go list -f '{{.Dir}}/...' -m)
127+
else
128+
# for older bash versions, e.g. on macOS runner. This fallback will eventually disappear.
129+
while read line ; do
130+
ALL_MODULES+=("${line}")
131+
done < <(go list -f '{{.Dir}}/...' -m)
132+
fi
133+
echo "::notice title=Modules found::${ALL_MODULES[@]}"
134+
135+
# with go.work file enabled, go test recognizes sub-modules and collects all packages to be covered
136+
# without specifying -coverpkg.
137+
go test -v -race -coverprofile="${COVER_PROFILE}" -covermode=atomic ${ALL_MODULES[@]}
138+
139+
- name: Upload coverage to codecov
140+
uses: codecov/codecov-action@v5
141+
with:
142+
name: Multi modules aggregated coverage
143+
flags: '${{ matrix.go_version }}-${{ matrix.os }}'
144+
fail_ci_if_error: false
145+
verbose: true
146+
147+
test:
148+
needs: [ module-test ]
149+
name: Test
150+
runs-on: ubuntu-latest
151+
steps:
152+
- name: Tests complete
153+
run: |
154+
echo "All tests completed"

.github/workflows/main.yml

Lines changed: 0 additions & 37 deletions
This file was deleted.

.github/workflows/release.yml

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)