Skip to content

Commit

Permalink
feat: add CI to project (#6)
Browse files Browse the repository at this point in the history
Signed-off-by: Mateus Oliveira <[email protected]>
  • Loading branch information
mateusoliveira43 authored Mar 1, 2024
1 parent d512d57 commit 1d7eac3
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 3 deletions.
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 2
updates:
# GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
day: "sunday"
commit-message:
prefix:
65 changes: 65 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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
21 changes: 21 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions internal/controller/common_velero.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 1d7eac3

Please sign in to comment.