diff --git a/.github/workflows/golang_integration_test.yml b/.github/workflows/golang_integration_test.yml new file mode 100644 index 0000000..a33e9be --- /dev/null +++ b/.github/workflows/golang_integration_test.yml @@ -0,0 +1,68 @@ +name: Go Integration Test + +on: + push: + branches-ignore: + - main + - master + pull_request: + branches: + - main + - master + release: + +jobs: + integration-test: + name: integration-test + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Setup go + uses: actions/setup-go@v4 + with: + go-version-file: './go.mod' + + # - name: Download envtest setup script + # run: curl -sSLo setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/master/hack/setup-envtest.sh + + # - name: Make the script executable + # run: chmod +x setup-envtest.sh + + # - name: Setup envtest + # run: ./setup-envtest.sh + + # - name: Install Controller-gen + # run: GO111MODULE=on go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.13.0 + + # - name: Install Kustomize + # run: curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash + + - name: Create k8s Kind Cluster + uses: helm/kind-action@v1.8.0 + with: + config: test/kind/config.yml + cluster_name: test-cluster + + - name: run integration tests + run: make integration-test + - uses: actions/upload-artifact@v3 + with: + name: integration_coverage_report + path: integration-test-cover.out + + # coverage: + # name: Coverage report + # runs-on: ubuntu-latest + # needs: integration-test + # steps: + # - uses: actions/download-artifact@v3 + # with: + # name: integration_coverage_report + # - uses: codecov/codecov-action@v3 + # env: + # CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + # with: + # files: integration-test-cover.out + # flags: integrationtests + # fail_ci_if_error: true \ No newline at end of file diff --git a/.github/workflows/golang_linter.yml b/.github/workflows/golang_linter.yml new file mode 100644 index 0000000..a6c2a1d --- /dev/null +++ b/.github/workflows/golang_linter.yml @@ -0,0 +1,52 @@ +name: Go Linter + +on: + push: + branches-ignore: + - main + - master + pull_request: + branches: + - main + - master + release: + +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version-file: './go.mod' + + - name: Lint + uses: golangci/golangci-lint-action@v3 + # continue-on-error: true + with: + # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version + version: v1.54.2 + + # Optional: working directory, useful for monorepos + # TODO: remove before release + working-directory: internal + + # Optional: golangci-lint command line arguments. + args: --timeout=5m + + # Optional: show only new issues if it's a pull request. The default value is `false`. + # only-new-issues: true + + # Optional: if set to true then the all caching functionality will be complete disabled, + # takes precedence over all other caching options. + # skip-cache: true + + # Optional: if set to true then the action don't cache or restore ~/go/pkg. + # skip-pkg-cache: true + + # Optional: if set to true then the action don't cache or restore ~/.cache/go-build. + # skip-build-cache: true diff --git a/.github/workflows/golang_unit_test.yml b/.github/workflows/golang_unit_test.yml new file mode 100644 index 0000000..5bd66c6 --- /dev/null +++ b/.github/workflows/golang_unit_test.yml @@ -0,0 +1,91 @@ +name: Go Unit Test + +on: + push: + branches-ignore: + - main + - master + pull_request: + branches: + - main + - master + release: + +jobs: + vet: + name: vet + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Setup go + uses: actions/setup-go@v4 + with: + go-version-file: './go.mod' + - name: Vet + run: | + go vet ./... + + fmt: + name: fmt + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Setup go + uses: actions/setup-go@v4 + with: + go-version-file: './go.mod' + - name: fmt + run: | + go fmt ./... + + unit-test: + name: unit-test + needs: ["fmt", "vet"] + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Setup go + uses: actions/setup-go@v4 + with: + go-version-file: './go.mod' + + # - name: Download envtest setup script + # run: curl -sSLo setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/master/hack/setup-envtest.sh + + # - name: Make the script executable + # run: chmod +x setup-envtest.sh + + # - name: Setup envtest + # run: ./setup-envtest.sh + + # - name: Install Controller-gen + # run: GO111MODULE=on go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.13.0 + + # - name: Install Kustomize + # run: curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash + + - name: run unit tests + run: make unit-test + - uses: actions/upload-artifact@v3 + with: + name: unit_coverage_report + path: unit-test-cover.out + + # coverage: + # name: Coverage report + # runs-on: ubuntu-latest + # needs: unit-test + # steps: + # - uses: actions/download-artifact@v3 + # with: + # name: unit_coverage_report + # - uses: codecov/codecov-action@v3 + # env: + # CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + # with: + # files: unit-test-cover.out + # flags: unittests + # fail_ci_if_error: true \ No newline at end of file diff --git a/.github/workflows/helm_release.yml b/.github/workflows/helm_release.yml new file mode 100644 index 0000000..4e3e694 --- /dev/null +++ b/.github/workflows/helm_release.yml @@ -0,0 +1,34 @@ +name: Release-Helm +on: + push: + branches: + - main + - master + +jobs: + helm-release: + permissions: + contents: write + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Configure Git + run: | + git config user.name "$GITHUB_ACTOR" + git config user.email "$GITHUB_ACTOR@users.noreply.github.com" + + - name: Install Helm + uses: azure/setup-helm@v3 + + - name: Run chart-releaser + uses: helm/chart-releaser-action@v1.5.0 + with: + packages_with_index: true + mark_as_latest: false + env: + CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..48dbe40 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,44 @@ +name: Release +on: + release: + types: [created, published] + +jobs: + docker-buildx: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: appsflyer/local-pvc-releaser + tags: | + type=ref,event=tag + type=semver,pattern={{version}} + type=raw,value=latest,enable={{is_default_branch}} + + - name: Validate Docker meta + run: echo "Output is empty, failing!" && exit 1 + if: steps.meta.outputs.tags == '' + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v5 + with: + context: . + platforms: linux/arm64,linux/amd64 + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file diff --git a/Makefile b/Makefile index 85c265c..300094f 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ # Image URL to use all building/pushing image targets TAG ?= $(shell if [ -z "${CI_COMMIT_TAG}" ]; then echo "latest"; else echo ${CI_COMMIT_TAG}; fi) -IMG ?= "local-pvc-releaser" +IMG ?= "appsflyer/local-pvc-releaser" IMAGE = "${IMG}:${TAG}" #GIT GIT_URL ?= "github.com/appsflyer/local-pvc-releaser" @@ -74,12 +74,11 @@ lint: $(GOLINT) .PHONY: integration-test integration-test: generate fmt vet envtest ## Run tests. - KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./test/... -coverprofile cover.out + KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./test/... -coverprofile $@-cover.out -covermode atomic; go tool cover -func $@-cover.out .PHONY: unit-test unit-test: generate fmt vet envtest ## Run tests. - KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./internal/... -coverprofile cover.out - + KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./internal/... -coverprofile $@-cover.out -covermode atomic; go tool cover -func $@-cover.out ##@ Build .PHONY: build diff --git a/main.go b/cmd/main.go similarity index 100% rename from main.go rename to cmd/main.go