Skip to content

Commit

Permalink
feat(ci): add basic CI
Browse files Browse the repository at this point in the history
  • Loading branch information
pmalek committed Jul 25, 2024
1 parent 8c8e17b commit 991ca69
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 1 deletion.
13 changes: 13 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -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
77 changes: 77 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -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/[email protected]

- 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
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 {}"
Empty file added config/samples/.gitignore
Empty file.
17 changes: 17 additions & 0 deletions scripts/verify-diff.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 991ca69

Please sign in to comment.