Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitHub CI Tests #12

Merged
merged 3 commits into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/post-submit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Publish Container Images
on:
push:
branches:
- main
tags:
- 'v*'

jobs:
push-images:
name: Build and push images to quay.io/medik8s
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Log in to Quay.io
uses: docker/login-action@v2
with:
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASSWORD }}
registry: quay.io

- name: Build and push CSV 0.0.1 + latest images for PR merges to main
if: ${{ github.ref_type != 'tag' }}
run: export IMAGE_REGISTRY=quay.io/medik8s && make container-build-and-push

- name: Build and push versioned CSV and images for tags
if: ${{ github.ref_type == 'tag' }}
# remove leading 'v' from tag!
run: export IMAGE_REGISTRY=quay.io/medik8s && export VERSION=$(echo $GITHUB_REF_NAME | sed 's/v//') && make container-build-and-push
26 changes: 26 additions & 0 deletions .github/workflows/pre-submit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Understanding the workflow file - https://docs.github.com/en/actions/learn-github-actions/understanding-github-actions#understanding-the-workflow-file
name: Pre Submit # workflow name
on: # on events
push:
branches:
- main
- release-*
pull_request:
branches:
- main
- release-*
jobs: # jobs to run
build:
name: Test and build PRs
runs-on: ubuntu-22.04 # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#choosing-github-hosted-runners
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Run Unit Tests
run: make test

- name: Build Images
run: make container-build
23 changes: 20 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,10 @@ fix-imports: sort-imports
$(SORT_IMPORTS) . -w

.PHONY: test
test: manifests generate go-verify test-imports fmt vet envtest ## Run tests.
test: test-no-verify verify-unchanged ## Generate and format code, run tests, generate manifests and bundle, and verify no uncommitted changes

.PHONY: test-no-verify
test-no-verify: manifests generate go-verify fmt vet envtest # Generate and format code, and run tests
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out

##@ Build
Expand All @@ -185,7 +188,7 @@ run: manifests generate fmt vet ## Run a controller from your host.
go run ./main.go

.PHONY: docker-build
docker-build: test ## Build docker image with the manager.
docker-build: test-no-verify ## Build docker image with the manager.
docker build -t ${IMG} .

.PHONY: docker-push
Expand Down Expand Up @@ -323,7 +326,6 @@ endef
build-tools: ## Download & build all the tools locally if necessary.
$(MAKE) kustomize controller-gen envtest opm operator-sdk


# Set CATALOG_BASE_IMG to an existing catalog image tag to add $BUNDLE_IMGS to that image.
ifneq ($(origin CATALOG_BASE_IMG), undefined)
FROM_INDEX_OPT := --from-index $(CATALOG_BASE_IMG)
Expand All @@ -340,3 +342,18 @@ catalog-build: opm ## Build a catalog image.
.PHONY: catalog-push
catalog-push: ## Push a catalog image.
$(MAKE) docker-push IMG=$(CATALOG_IMG)

##@ Targets used by CI

.PHONY: verify-unchanged
verify-unchanged: ## Verify there are no un-committed changes
./hack/verify-unchanged.sh

.PHONY: container-build
container-build: docker-build bundle-build ## Build containers

.PHONY: container-push
container-push: docker-push bundle-push catalog-build catalog-push ## Push containers (NOTE: catalog can't be build before bundle was pushed)

.PHONY: container-build-and-push
container-build-and-push: container-build container-push ## Build and push all the four images to quay (docker, bundle, and catalog).
7 changes: 7 additions & 0 deletions hack/verify-unchanged.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

if [[ -n "$(git status --porcelain .)" ]]; then
echo "Uncommitted generated files. Run 'make check' and commit results."
echo "$(git status --porcelain .)"
exit 1
fi