diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..9516fe3 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,30 @@ +name: Build + +on: + workflow_call: + +jobs: + build-n-test: + runs-on: ubuntu-latest + strategy: + matrix: + go-version: [ '1.20', '1.21', '1.22' ] + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 1 + - name: Setup Go ${{ matrix.go-version }} + uses: actions/setup-go@v5 + with: + go-version: ${{ matrix.go-version }} + cache-dependency-path: go.sum + + - name: Install dependencies + run: | + # Install fieldalignment for fields aligment verfication in structs + go install golang.org/x/tools/go/analysis/passes/fieldalignment/cmd/fieldalignment@latest + go install honnef.co/go/tools/cmd/staticcheck@latest + + - name: Build + run: make build diff --git a/.github/workflows/development.yaml b/.github/workflows/development.yaml new file mode 100644 index 0000000..382eb4c --- /dev/null +++ b/.github/workflows/development.yaml @@ -0,0 +1,16 @@ +name: Build and test for devices + +on: + pull_request: + branches: + - main + paths: + - "**/*.go" + - "go.mod" + - "go.sum" + - "Makefile" + - ".github/workflows/build.yaml" + - ".github/workflows/development.yaml" +jobs: + call-build-workflow: + uses: "./build.yaml" diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..9ad9721 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,26 @@ +on: + release: + types: [created] + +permissions: + contents: write + packages: write + +jobs: + releases-matrix: + name: Release Go Binary + runs-on: ubuntu-latest + strategy: + matrix: + # build and publish in parallel: linux/386, linux/amd64, linux/arm64, windows/386, windows/amd64, darwin/amd64, darwin/arm64 + goos: [linux, windows, darwin] + goarch: ["386", amd64, arm64] + steps: + - uses: actions/checkout@v4 + - uses: wangyoucao577/go-release-action@v1 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + goos: ${{ matrix.goos }} + goarch: ${{ matrix.goarch }} + goversion: "https://dl.google.com/go/go1.13.1.linux-amd64.tar.gz" + extra_files: LICENSE README.md diff --git a/Makefile b/Makefile index 03db8fa..455e312 100644 --- a/Makefile +++ b/Makefile @@ -4,8 +4,16 @@ GOBUILD=$(GOCMD) build BINARY_NAME=kubectl-envsecret MAIN_FILE=main.go +vet: + @echo "Vet the code" + $(GOCMD) vet ./... + +fieldalignment-check: + @echo "Running fieldalignment" + $(FIELDALIGNMENT_CMD) ./... + fieldalignment: - @echo "Running fieldalignment to optimize struct sizes" + @echo "Running fieldalignment fix to optimize struct sizes" $(FIELDALIGNMENT_CMD) -fix ./... test: @@ -16,14 +24,16 @@ format: @echo "Formatting code..." $(GOCMD) fmt ./... -build: +build: vet @echo "Building..." $(GOCMD) build -o $(BINARY_NAME) $(MAIN_FILE) -build-prod: test fieldalignment format build +fix: format fieldalignment + +build-prod: test fieldalignment-check build run: build ./$(BINARY_NAME) $(CMD) $(ARGS) $(FLAGS) -.PHONY: build build-prod run format +.PHONY: build build-prod run format vet fieldalignment-check fieldalignment test fix diff --git a/go.mod b/go.mod index 21103e7..c060eef 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,8 @@ module github.com/ogticrd/kubectl-envsecret go 1.22.0 +toolchain go1.22.1 + require ( github.com/joho/godotenv v1.5.1 github.com/spf13/cobra v1.8.0 @@ -47,7 +49,6 @@ require ( github.com/peterbourgon/diskv v2.0.1+incompatible // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/stretchr/objx v0.5.2 // indirect github.com/xlab/treeprint v1.2.0 // indirect go.starlark.net v0.0.0-20230525235612-a134d8f9ddca // indirect golang.org/x/net v0.23.0 // indirect diff --git a/internal/k8sapi/k8s_test.go b/internal/k8sapi/k8s_test.go index 65a8937..3cbf573 100644 --- a/internal/k8sapi/k8s_test.go +++ b/internal/k8sapi/k8s_test.go @@ -5,9 +5,7 @@ import ( "github.com/ogticrd/kubectl-envsecret/internal/k8sapi" "github.com/stretchr/testify/assert" - v1 "k8s.io/api/core/v1" kerr "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes/fake" ) @@ -36,14 +34,3 @@ func mockSecretData() map[string]string { secret["bar"] = "line" return secret } - -func mockSecret(secret map[string]string) *v1.Secret { - return &v1.Secret{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test", - Namespace: "test", - OwnerReferences: []metav1.OwnerReference{}, - }, - StringData: secret, - } -}