Skip to content

Commit e7e802a

Browse files
authored
Merge pull request #44 from deckhouse/feature/github-actions-go-test
Add CI to GitHub Actions with go test
1 parent 32b1609 commit e7e802a

4 files changed

Lines changed: 157 additions & 4 deletions

File tree

.github/stale.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Number of days of inactivity before an issue becomes stale
2+
daysUntilStale: 366
3+
4+
# Number of days of inactivity before a stale issue is closed
5+
daysUntilClose: 30
6+
7+
# Issues with these labels will never be considered stale
8+
exemptLabels:
9+
- pinned
10+
- security
11+
- blocked
12+
- protected
13+
- triaged
14+
15+
# Label to use when marking an issue as stale
16+
staleLabel: stale
17+
18+
# Comment to post when marking an issue as stale. Set to `false` to disable
19+
markComment: >
20+
This issue has been automatically marked as stale because it has not had
21+
recent activity. It will be closed if no further activity occurs. Thank you
22+
for your contributions.
23+
24+
# Comment to post when closing a stale issue. Set to `false` to disable
25+
closeComment: false

.github/workflows/test.yml

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
name: Test
2+
3+
on:
4+
pull_request:
5+
types: [opened]
6+
push:
7+
branches-ignore: [ main ]
8+
9+
env:
10+
GO_VERSION: '1.24'
11+
GOLANGCI_LINT_VERSION: 'v2.1'
12+
13+
jobs:
14+
# Check if there is any dirty change for go mod tidy
15+
go-mod:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v4
19+
- uses: actions/setup-go@v5
20+
with:
21+
go-version: ${{ env.GO_VERSION }}
22+
- name: Check go mod
23+
run: |
24+
go mod tidy
25+
git diff --exit-code go.mod
26+
git diff --exit-code go.sum
27+
28+
go-test:
29+
needs: go-mod
30+
runs-on: ubuntu-latest
31+
steps:
32+
- uses: actions/checkout@v4
33+
- uses: actions/setup-go@v5
34+
with:
35+
go-version: ${{ env.GO_VERSION }}
36+
- run: go test ./... -race
37+
38+
golangci-lint:
39+
needs: go-test
40+
runs-on: ubuntu-latest
41+
steps:
42+
- uses: actions/checkout@v4
43+
- uses: actions/setup-go@v5
44+
with:
45+
go-version: ${{ env.GO_VERSION }}
46+
- uses: golangci/golangci-lint-action@v8
47+
with:
48+
version: ${{ env.GOLANGCI_LINT_VERSION }}
49+
50+
detect-modules: # ref: https://github.com/golangci/golangci-lint-action/tree/main
51+
needs: [golangci-lint, go-test, go-mod]
52+
runs-on: ubuntu-latest
53+
outputs:
54+
modules: ${{ steps.set-modules.outputs.modules }}
55+
steps:
56+
- uses: actions/checkout@v4
57+
- uses: actions/setup-go@v5
58+
with:
59+
go-version: ${{ env.GO_VERSION }}
60+
- name: Create go.work # Required for Go workspace mode to enable submodule checks and linting support (ref: https://go.dev/doc/tutorial/workspaces)
61+
run: go work init && find . -mindepth 2 -name go.mod|sed -r 's/(.*)(go.mod)/use \1/g' >> go.work
62+
- name: Upload go.work
63+
uses: actions/upload-artifact@v4
64+
with:
65+
name: go_work
66+
path: go.work
67+
- id: set-modules
68+
run: echo "modules=$(go list -m -json | jq -s '.' | jq -c '[.[].Dir]')" >> $GITHUB_OUTPUT
69+
70+
go-mod-examples:
71+
needs: [detect-modules]
72+
runs-on: ubuntu-latest
73+
strategy:
74+
matrix:
75+
modules: ${{ fromJSON(needs.detect-modules.outputs.modules) }}
76+
fail-fast: false
77+
steps:
78+
- uses: actions/checkout@v4
79+
- uses: actions/setup-go@v5
80+
with:
81+
go-version: ${{ env.GO_VERSION }}
82+
- name: Check go mod
83+
run: |
84+
pwd
85+
go mod tidy
86+
git diff --exit-code go.mod
87+
git diff --exit-code go.sum
88+
working-directory: ${{ matrix.modules }}
89+
90+
go-test-examples:
91+
needs: [detect-modules, go-mod-examples]
92+
runs-on: ubuntu-latest
93+
strategy:
94+
matrix:
95+
modules: ${{ fromJSON(needs.detect-modules.outputs.modules) }}
96+
fail-fast: false
97+
steps:
98+
- uses: actions/checkout@v4
99+
- uses: actions/setup-go@v5
100+
with:
101+
go-version: ${{ env.GO_VERSION }}
102+
- name: Download go.work from detect-modules
103+
uses: actions/download-artifact@v4
104+
with:
105+
name: go_work
106+
- run: go test ./...
107+
working-directory: ${{ matrix.modules }}
108+
109+
golangci-lint-examples:
110+
needs: [detect-modules, go-test-examples]
111+
runs-on: ubuntu-latest
112+
strategy:
113+
matrix:
114+
modules: ${{ fromJSON(needs.detect-modules.outputs.modules) }}
115+
fail-fast: false
116+
steps:
117+
- uses: actions/checkout@v4
118+
- uses: actions/setup-go@v5
119+
with:
120+
go-version: ${{ env.GO_VERSION }}
121+
- name: Download go.work from detect-modules
122+
uses: actions/download-artifact@v4
123+
with:
124+
name: go_work
125+
- name: golangci-lint ${{ matrix.modules }}
126+
uses: golangci/golangci-lint-action@v8
127+
with:
128+
version: ${{ env.GOLANGCI_LINT_VERSION }}
129+
working-directory: ${{ matrix.modules }}

examples/basic-example-module/hooks/go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ module basic-example-module
22

33
go 1.23.8
44

5-
65
require github.com/deckhouse/module-sdk v0.0.0
76

87
require (

examples/example-module/hooks/subfolder/patch_hook_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ var _ = Describe("patch hook", func() {
9696
Expect(name).To(Equal("my-third-pod"))
9797
})
9898

99-
// Set expectations for MergePatch
100-
patchCollector.MergePatchMock.Set(func(patch any, apiVersion, kind, namespace, name string, opts ...pkg.PatchCollectorOption) {
101-
patchMap, ok := patch.(map[string]any)
99+
// Set expectations for PatchWithMerge
100+
patchCollector.PatchWithMergeMock.Set(func(mergePatch any, apiVersion, kind, namespace, name string, opts ...pkg.PatchCollectorOption) {
101+
patchMap, ok := mergePatch.(map[string]any)
102102
Expect(ok).To(BeTrue())
103103
Expect(patchMap).To(HaveKeyWithValue("/status", "newStatus"))
104104
Expect(apiVersion).To(Equal("v1"))

0 commit comments

Comments
 (0)