Skip to content

Commit

Permalink
fix: Add more documenation to project (#16)
Browse files Browse the repository at this point in the history
Signed-off-by: Mateus Oliveira <[email protected]>
  • Loading branch information
mateusoliveira43 authored Apr 23, 2024
1 parent f117c5b commit 94c4be9
Show file tree
Hide file tree
Showing 20 changed files with 628 additions and 343 deletions.
36 changes: 31 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
name: Continuos Integration
name: Continuous Integration

on:
push:
branches:
- master
# add release branches
pull_request:
branches:
- master
# add release branches
schedule:
- cron: '0 0 * * 1' # Every Monday at 00:00 UTC
- cron: '0 0 * * 1' # Every Monday at 00:00 UTC

jobs:
golang-check:
Expand All @@ -25,16 +27,14 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
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
if: ${{ matrix.go-version == '1.21' }}
uses: golangci/golangci-lint-action@v4
Expand Down Expand Up @@ -68,3 +68,29 @@ jobs:

- name: Check all files format
run: make ec

- name: Check if images are the same in Makefile and config/manager/kustomization.yaml
run: make check-images

oadp-compatibility-check:
runs-on: ubuntu-latest
steps:
- name: Checkout OADP operator
uses: actions/checkout@v4
with:
repository: openshift/oadp-operator
ref: ${{ github.base_ref || github.ref_name }}

- uses: actions/setup-go@v5
with:
go-version: "1.20" # OADP Go version

- name: Checkout Non Admin Controller (NAC)
uses: actions/checkout@v4
with:
path: oadp-non-admin

- name: Check Non Admin Controller (NAC) manifests
run: |
NON_ADMIN_CONTROLLER_PATH=./oadp-non-admin make update-non-admin-manifests
test -z "$(git status --short -- ':!oadp-non-admin')" || (echo "run 'make update-non-admin-manifests' in OADP repository to update Non Admin Controller (NAC) manifests" && exit 1)
37 changes: 33 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@

# Image URL to use all building/pushing image targets
IMG ?= controller:latest
IMG ?= quay.io/konveyor/oadp-non-admin:latest
# Kubernetes version from OpenShift 4.15.x https://openshift-release.apps.ci.l2s4.p1.openshiftapps.com/#4-stable
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.29.0
ENVTEST_K8S_VERSION = 1.28

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
Expand Down Expand Up @@ -46,7 +47,7 @@ help: ## Display this help.

.PHONY: manifests
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
$(CONTROLLER_GEN) rbac:roleName=non-admin-controller-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases

.PHONY: generate
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
Expand Down Expand Up @@ -204,7 +205,11 @@ endef

##@ oadp-nac specifics

## Tool Binaries
OC_CLI ?= $(shell which oc)
EC ?= $(LOCALBIN)/ec-$(EC_VERSION)

## Tool Versions
EC_VERSION ?= 2.8.0

.PHONY: editorconfig
Expand All @@ -219,12 +224,28 @@ editorconfig: $(LOCALBIN) ## Download editorconfig locally if necessary.
mv $(LOCALBIN)/$${ec_binary} $(EC) ;\
}

# TODO increase!!!
COVERAGE_THRESHOLD=24

.PHONY: ci
ci: simulation-test lint docker-build hadolint check-generate check-manifests ec ## Run all checks run by the project continuous integration (CI) locally.
ci: simulation-test lint docker-build hadolint check-generate check-manifests ec check-images ## Run all project continuous integration (CI) checks 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
@make check-coverage

.PHONY: check-coverage
check-coverage: ## Check if test coverage threshold was reached.
@{ \
set -e ;\
current_coverage=$(shell go tool cover -func=cover.out | grep total | grep -Eo "[0-9]+\.[0-9]+") ;\
if [ "$$(echo "$$current_coverage < $(COVERAGE_THRESHOLD)" | bc -l)" -eq 1 ];then \
echo "Current coverage ($$current_coverage%) is below project threshold of $(COVERAGE_THRESHOLD)%" ;\
exit 1 ;\
fi ;\
echo "Coverage threshold of $(COVERAGE_THRESHOLD)% reached: $$current_coverage%" ;\
}

.PHONY: hadolint
hadolint: ## Run container file linter.
Expand All @@ -241,3 +262,11 @@ check-manifests: manifests ## Check if 'make manifests' was run.
.PHONY: ec
ec: editorconfig ## Run file formatter checks against all project's files.
$(EC)

.PHONY: check-images
check-images: MANAGER_IMAGE:=$(shell grep -I 'newName: ' ./config/manager/kustomization.yaml | awk -F': ' '{print $$2}')
check-images: MANAGER_TAG:=$(shell grep -I 'newTag: ' ./config/manager/kustomization.yaml | awk -F': ' '{print $$2}')
check-images: ## Check if images are the same in Makefile and config/manager/kustomization.yaml
@if [ "$(MANAGER_IMAGE)" == "" ];then echo "No manager image found" && exit 1;fi
@if [ "$(MANAGER_TAG)" == "" ];then echo "No manager tag found" && exit 1;fi
@grep -Iq "IMG ?= $(MANAGER_IMAGE):$(MANAGER_TAG)" ./Makefile || (echo "Images differ" && exit 1)
Loading

0 comments on commit 94c4be9

Please sign in to comment.