From 991ca6973d4274f21b0564b58238cbfb5b125182 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patryk=20Ma=C5=82ek?= Date: Thu, 25 Jul 2024 13:00:19 +0200 Subject: [PATCH] feat(ci): add basic CI --- .github/PULL_REQUEST_TEMPLATE.md | 13 ++++++ .github/dependabot.yml | 14 ++++++ .github/workflows/tests.yaml | 77 ++++++++++++++++++++++++++++++++ Makefile | 11 ++++- config/samples/.gitignore | 0 scripts/verify-diff.sh | 17 +++++++ 6 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 .github/PULL_REQUEST_TEMPLATE.md create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/tests.yaml create mode 100644 config/samples/.gitignore create mode 100755 scripts/verify-diff.sh diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..b4b571d --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,13 @@ +**What this PR does / why we need it**: + +**Which issue this PR fixes** + +Fixes # + +**Special notes for your reviewer**: + +**PR Readiness Checklist**: + +Complete these before marking the PR as `ready to review`: + +- [ ] the `CHANGELOG.md` release notes have been updated to reflect significant changes diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..e941920 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,14 @@ +version: 2 +updates: +- package-ecosystem: gomod + directory: / + schedule: + interval: daily + labels: + - dependencies +- package-ecosystem: github-actions + directory: / + schedule: + interval: daily + labels: + - github_actions diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml new file mode 100644 index 0000000..fafc489 --- /dev/null +++ b/.github/workflows/tests.yaml @@ -0,0 +1,77 @@ +name: tests +run-name: tests, branch:${{ github.ref_name }}, triggered by @${{ github.actor }} + +concurrency: + # Run only for most recent commit in PRs but for all tags and commits on main + # Ref: https://docs.github.com/en/actions/using-jobs/using-concurrency + group: ${{ github.workflow }}-${{ github.head_ref || github.sha }} + cancel-in-progress: true + +on: + pull_request: + branches: + - 'main' + push: + branches: + - 'main' + - 'release/*' + tags: + - '*' + workflow_dispatch: {} + +jobs: + generate: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + + - uses: jdx/mise-action@v2 + with: + install: false + + - name: Generate + run: make generate + + - name: Verify + run: make verify.diff + + apply: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + + - uses: jdx/mise-action@v2 + with: + install: false + + - name: Create k8s KinD Cluster + uses: helm/kind-action@v1.10.0 + + - name: Verify installing CRDs via kustomize works + run: make install + + - name: Install and delete each sample one by one + run: make test.samples + + # We need this step to fail the workflow if any of the previous steps failed or were cancelled. + # It allows to use this particular job as a required check for PRs. + # Ref: https://github.com/orgs/community/discussions/26822#discussioncomment-3305794 + passed: + runs-on: ubuntu-latest + needs: + - generate + - apply + if: always() + steps: + - if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') + run: | + echo "Some jobs failed or were cancelled." + exit 1 diff --git a/Makefile b/Makefile index 6cda9e7..fbb6f2d 100644 --- a/Makefile +++ b/Makefile @@ -106,7 +106,7 @@ verify.repo: .PHONY: verify.diff verify.diff: - ./scripts/verify-diff.sh + @$(PROJECT_DIR)/scripts/verify-diff.sh $(PROJECT_DIR) .PHONY: verify.versions verify.versions: @@ -169,3 +169,12 @@ generate.apidocs: crd-ref-docs # .PHONY: generate.cli-arguments # generate.cli-arguments-docs: # go run ./scripts/cli-arguments-docs-gen/main.go > ./docs/cli-arguments.md + +# Install CRDs into the K8s cluster specified in ~/.kube/config. +.PHONY: install +install: generate.crds kustomize + $(KUSTOMIZE) build config/crd | kubectl apply -f - + +.PHONY: test.samples +test.samples: kustomize + find ./config/samples -not -name "kustomization.*" -type f | sort | xargs -I{} bash -c "kubectl apply -f {}; kubectl delete -f {}" diff --git a/config/samples/.gitignore b/config/samples/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/scripts/verify-diff.sh b/scripts/verify-diff.sh new file mode 100755 index 0000000..409ae17 --- /dev/null +++ b/scripts/verify-diff.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +set -o errexit +set -o nounset +set -o pipefail + +DIR="${1}" + +if git diff --quiet "${DIR}" +then + echo "${DIR} up to date." +else + echo "${DIR} appears to be out of date (make sure you've run 'make manifests' and 'make generate')" + echo "Diff output:" + git --no-pager diff "${DIR}" + exit 1 +fi