Skip to content
This repository has been archived by the owner on Nov 29, 2024. It is now read-only.

Commit

Permalink
feat: CI iteration #1 (#3)
Browse files Browse the repository at this point in the history
* CI init

* Cleanup

* Set up baseline namespace

* Fix pods check

* Add lint test

* Add lint test
  • Loading branch information
laurentluce authored Oct 4, 2024
1 parent c0da31c commit b5b0e87
Show file tree
Hide file tree
Showing 12 changed files with 534 additions and 76 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/cache-clean-up.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: cleanup caches by a branch
on:
pull_request:
types:
- closed

jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- name: Cleanup
run: |
gh extension install actions/gh-actions-cache
echo "Fetching list of cache key"
cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH | cut -f 1 )
## Setting this to not fail the workflow while deleting cache keys.
set +e
echo "Deleting caches..."
for cacheKey in $cacheKeysForPR
do
gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm
done
echo "Done"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
BRANCH: refs/pull/${{ github.event.pull_request.number }}/merge
48 changes: 48 additions & 0 deletions .github/workflows/ci-base.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Check and build Kardinal Operator

permissions:
id-token: write
contents: read

on:
push:
branches:
- main
tags:
- "v*.*.*"
pull_request:
branches:
- main

jobs:
check_go:
name: Check Go
runs-on: ubuntu-22.04
steps:
- name: Git checkout
uses: actions/checkout@v3

- name: Install Go
uses: actions/setup-go@v5
with:
go-version: '^1.22.0'

- name: Check Go formatting
run: |
if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then
exit 1
fi
build:
name: Build
needs: [check_go]
runs-on: ubuntu-22.04
steps:
- name: Git checkout
uses: actions/checkout@v3

- name: Build operator binary
run: make build

- name: Linter
run: make lint
67 changes: 67 additions & 0 deletions .github/workflows/ci-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Tests

permissions:
id-token: write
contents: read

on:
push:
branches:
- main
tags:
- "v*.*.*"
pull_request:
branches:
- main

jobs:
tests:
name: Tests
runs-on: ubuntu-22.04
steps:
- name: Git checkout
uses: actions/checkout@v3

- name: Start minikube
uses: manusa/[email protected]
id: minikube
with:
minikube version: "v1.33.0"
kubernetes version: "v1.30.0"
driver: docker
start args: --embed-certs --addons=ingress,metrics-server

- name: Install Istio
run: |
ISTIO_VERSION="1.23.0"
echo "Installing Istio ..."
mkdir istio_tmp
pushd istio_tmp >/dev/null
curl -L https://istio.io/downloadIstio | ISTIO_VERSION=${ISTIO_VERSION} sh -
cd istio-${ISTIO_VERSION}
export PATH=$PWD/bin:$PATH
istioctl install --set profile=demo -y
popd
- name: Deploy the boutique demo
run: |
kubectl create namespace baseline
kubectl apply -f ci/obd-demo.yaml -n baseline
- name: Validate that the boutique demo is up and running
run: |
# Check that the four baseline service pods are running and ready
while [ $(kubectl get pods -n baseline --no-headers -o custom-columns=NAMESPACE:metadata.namespace,POD:metadata.name,PodIP:status.podIP,READY-true:status.containerStatuses[*].ready | grep "true" | wc -l) -ne 4 ]
do
echo "Waiting for baseline pods to run..."
kubectl get pods -n baseline -o custom-columns=NAMESPACE:metadata.namespace,POD:metadata.name,PodIP:status.podIP,READY-true:status.containerStatuses[*].ready
((c++)) && ((c==12)) && exit 1
sleep 10
done
apps=$(kubectl get pods -n baseline -o custom-columns=:metadata.labels.app | tr " " "\n" | sort -g | tr "\n" " " | xargs)
echo ${apps}
if [ "${apps}" != "cartservice frontend postgres productcatalogservice" ]; then exit 1; fi
- name: Run operator tests
run: |
make test
22 changes: 22 additions & 0 deletions .github/workflows/conventional-commits.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Check PR title for conventional commits
name: Check PR title
on:
pull_request_target:
types:
- opened
- reopened
- edited
- synchronize

# cancel redundant builds
concurrency:
group: "title-checker-${{ github.head_ref }}"
cancel-in-progress: true

jobs:
title_check:
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ issues:
- path: "api/*"
linters:
- lll
- path: "kardinal/*"
linters:
- lll
- path: "internal/*"
linters:
- dupl
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ vet: ## Run go vet against code.

.PHONY: test
test: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /e2e) -coverprofile cover.out
USE_EXISTING_CLUSTER=true KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v /e2e) -coverprofile cover.out

# Utilize Kind or modify the e2e tests to load the image locally, enabling compatibility with other vendors.
.PHONY: test-e2e # Run the e2e tests against a Kind k8s instance that is spun up.
Expand Down
Loading

0 comments on commit b5b0e87

Please sign in to comment.