diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..5557017 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,10 @@ +version: 2 +updates: + # GitHub Actions + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + day: "sunday" + commit-message: + prefix: ⬆ diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..48cacd7 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,65 @@ +name: Continuos Integration + +on: + push: + branches: + - master + pull_request: + branches: + - master + schedule: + - cron: '0 0 * * 1' # Every Monday at 00:00 UTC + +jobs: + golang-check: + runs-on: ubuntu-latest + strategy: + matrix: + go-version: [ + "1.20", + "1.21", + "1.22", + ] + + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v4 + with: + go-version: ${{ matrix.go-version }} + + - name: Install Go dependencies + run: go mod download + + - name: Go unit and integration tests + run: make simulation-test + + # TODO coverage report + + - name: Go linters + run: make lint + + container-check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Build container image + run: make docker-build + + - name: Container file linter + uses: hadolint/hadolint-action@v3.1.0 + with: + dockerfile: Dockerfile + + project-check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Check if 'make generate' was run + run: make check-generate + + - name: Check if 'make manifests' was run + run: make check-manifests + + # TODO editorconfig diff --git a/Makefile b/Makefile index 39aea44..ce7b4e0 100644 --- a/Makefile +++ b/Makefile @@ -201,3 +201,24 @@ GOBIN=$(LOCALBIN) go install $${package} ;\ mv "$$(echo "$(1)" | sed "s/-$(3)$$//")" $(1) ;\ } endef + +##@ oadp-nac specifics + +.PHONY: ci +ci: simulation-test lint docker-build hadolint check-generate check-manifests ## Run all checks run by the project continuous integration (CI) locally. + +.PHONY: simulation-test +simulation-test: envtest ## Run unit and integration tests. + KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /e2e) -coverprofile cover.out + +.PHONY: hadolint +hadolint: ## Run container file linter. + $(CONTAINER_TOOL) run --rm --interactive ghcr.io/hadolint/hadolint < ./Dockerfile + +.PHONY: check-generate +check-generate: generate ## Check if 'make generate' was run. + test -z "$(shell git status --short)" || (echo "run 'make generate' to generate code" && exit 1) + +.PHONY: check-manifests +check-manifests: manifests ## Check if 'make manifests' was run. + test -z "$(shell git status --short)" || (echo "run 'make manifests' to generate code" && exit 1) diff --git a/README.md b/README.md index 7d7d15f..d7f50a4 100644 --- a/README.md +++ b/README.md @@ -238,6 +238,57 @@ make manifests To upgrade kubebuilder version, create kubebuilder structure using the current kubebuilder version and the upgrade version, using the same commands presented earlier, in two different folders. Then generate a `diff` file from the two folders and apply changes to project code. +## Quality + +The quality checks of the project are reproduced by the continuos integration (CI) pipeline of the project. CI configuration in [`.github/workflows/ci.yml`](.github/workflows/ci.yml) file. + +To run all checks locally, run `make ci`. + +### Tests + +To run unit and integration tests, run +```sh +make simulation-test +``` + +TODO report, coverage and tests information + +### Linters and code formatters + +To run Go linters and check Go code format, run +```sh +make lint +``` + +To fix Go linters issues and format Go code, run +```sh +make lint-fix +``` + +Go linters and Go code formatters configuration in [`.golangci.yml`](.golangci.yml) file. + +To check all files format, run +```sh +make ec +``` + +Files format configuration in [`.editorconfig`](.editorconfig) file. + +### Container file linter + +To run container file linter, run +```sh +make hadolint +``` + +### Code generation + +To check if project code was generated, run +```sh +make check-generate +make check-manifests +``` + ## License Copyright 2024. diff --git a/internal/controller/common_velero.go b/internal/controller/common_velero.go index f51a655..38f1cce 100644 --- a/internal/controller/common_velero.go +++ b/internal/controller/common_velero.go @@ -2,10 +2,9 @@ package controller import ( "context" - "fmt" - "k8s.io/apimachinery/pkg/types" + "k8s.io/apimachinery/pkg/types" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/log" diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index 4c7e55e..a5508eb 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -73,7 +73,7 @@ var _ = Describe("controller", Ordered, func() { By("installing CRDs") cmd = exec.Command("make", "install") - _, err = utils.Run(cmd) + _, _ = utils.Run(cmd) By("deploying the controller-manager") cmd = exec.Command("make", "deploy", fmt.Sprintf("IMG=%s", projectimage))