diff --git a/.github/stale.yml b/.github/stale.yml new file mode 100644 index 00000000..ebaad440 --- /dev/null +++ b/.github/stale.yml @@ -0,0 +1,25 @@ +# Number of days of inactivity before an issue becomes stale +daysUntilStale: 366 + +# Number of days of inactivity before a stale issue is closed +daysUntilClose: 30 + +# Issues with these labels will never be considered stale +exemptLabels: + - pinned + - security + - blocked + - protected + - triaged + +# Label to use when marking an issue as stale +staleLabel: stale + +# Comment to post when marking an issue as stale. Set to `false` to disable +markComment: > + This issue has been automatically marked as stale because it has not had + recent activity. It will be closed if no further activity occurs. Thank you + for your contributions. + +# Comment to post when closing a stale issue. Set to `false` to disable +closeComment: false \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..a5ebe49c --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,129 @@ +name: Test + +on: + pull_request: + types: [opened] + push: + branches-ignore: [ main ] + +env: + GO_VERSION: '1.24' + GOLANGCI_LINT_VERSION: 'v2.1' + +jobs: + # Check if there is any dirty change for go mod tidy + go-mod: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + - name: Check go mod + run: | + go mod tidy + git diff --exit-code go.mod + git diff --exit-code go.sum + + go-test: + needs: go-mod + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + - run: go test ./... -race + + golangci-lint: + needs: go-test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + - uses: golangci/golangci-lint-action@v8 + with: + version: ${{ env.GOLANGCI_LINT_VERSION }} + + detect-modules: # ref: https://github.com/golangci/golangci-lint-action/tree/main + needs: [golangci-lint, go-test, go-mod] + runs-on: ubuntu-latest + outputs: + modules: ${{ steps.set-modules.outputs.modules }} + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + - name: Create go.work # Required for Go workspace mode to enable submodule checks and linting support (ref: https://go.dev/doc/tutorial/workspaces) + run: go work init && find . -mindepth 2 -name go.mod|sed -r 's/(.*)(go.mod)/use \1/g' >> go.work + - name: Upload go.work + uses: actions/upload-artifact@v4 + with: + name: go_work + path: go.work + - id: set-modules + run: echo "modules=$(go list -m -json | jq -s '.' | jq -c '[.[].Dir]')" >> $GITHUB_OUTPUT + + go-mod-examples: + needs: [detect-modules] + runs-on: ubuntu-latest + strategy: + matrix: + modules: ${{ fromJSON(needs.detect-modules.outputs.modules) }} + fail-fast: false + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + - name: Check go mod + run: | + pwd + go mod tidy + git diff --exit-code go.mod + git diff --exit-code go.sum + working-directory: ${{ matrix.modules }} + + go-test-examples: + needs: [detect-modules, go-mod-examples] + runs-on: ubuntu-latest + strategy: + matrix: + modules: ${{ fromJSON(needs.detect-modules.outputs.modules) }} + fail-fast: false + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + - name: Download go.work from detect-modules + uses: actions/download-artifact@v4 + with: + name: go_work + - run: go test ./... + working-directory: ${{ matrix.modules }} + + golangci-lint-examples: + needs: [detect-modules, go-test-examples] + runs-on: ubuntu-latest + strategy: + matrix: + modules: ${{ fromJSON(needs.detect-modules.outputs.modules) }} + fail-fast: false + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + - name: Download go.work from detect-modules + uses: actions/download-artifact@v4 + with: + name: go_work + - name: golangci-lint ${{ matrix.modules }} + uses: golangci/golangci-lint-action@v8 + with: + version: ${{ env.GOLANGCI_LINT_VERSION }} + working-directory: ${{ matrix.modules }} diff --git a/examples/basic-example-module/hooks/go.mod b/examples/basic-example-module/hooks/go.mod index 5e4caed7..6cc050d9 100644 --- a/examples/basic-example-module/hooks/go.mod +++ b/examples/basic-example-module/hooks/go.mod @@ -2,7 +2,6 @@ module basic-example-module go 1.23.8 - require github.com/deckhouse/module-sdk v0.0.0 require ( diff --git a/examples/example-module/hooks/subfolder/patch_hook_test.go b/examples/example-module/hooks/subfolder/patch_hook_test.go index 6ac25c99..022a199c 100644 --- a/examples/example-module/hooks/subfolder/patch_hook_test.go +++ b/examples/example-module/hooks/subfolder/patch_hook_test.go @@ -96,9 +96,9 @@ var _ = Describe("patch hook", func() { Expect(name).To(Equal("my-third-pod")) }) - // Set expectations for MergePatch - patchCollector.MergePatchMock.Set(func(patch any, apiVersion, kind, namespace, name string, opts ...pkg.PatchCollectorOption) { - patchMap, ok := patch.(map[string]any) + // Set expectations for PatchWithMerge + patchCollector.PatchWithMergeMock.Set(func(mergePatch any, apiVersion, kind, namespace, name string, opts ...pkg.PatchCollectorOption) { + patchMap, ok := mergePatch.(map[string]any) Expect(ok).To(BeTrue()) Expect(patchMap).To(HaveKeyWithValue("/status", "newStatus")) Expect(apiVersion).To(Equal("v1"))