Skip to content

Commit

Permalink
Verify various version related assumptions during CI (#20)
Browse files Browse the repository at this point in the history
* verify version assumptions in CI
---------

Co-authored-by: Andrew <andrew.pelletier@octo.us>
  • Loading branch information
pelletier2017 and Andrew authored Aug 9, 2024
1 parent c4b19ba commit 0da7124
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 23 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/minimal-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ env:
GIT_TAG_PREFIX: minimal-app_v

jobs:
verify-versions:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: sh .github/workflows/scripts/verify_minimal_app_releasable.sh
name: Verify minimal app is in a state to be released on merge
build:
name: build image
if: github.ref != 'refs/heads/main'
Expand All @@ -38,6 +44,7 @@ jobs:

release:
if: github.ref == 'refs/heads/main'
needs: verify-versions
runs-on: ubuntu-latest
defaults:
run:
Expand All @@ -52,7 +59,6 @@ jobs:
VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
REGISTRY=$(mvn help:evaluate -Dexpression=docker.registry -q -DforceStdout)
IMAGE_NAME=$(mvn help:evaluate -Dexpression=image-name -q -DforceStdout)
echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT"
echo "REGISTRY=$REGISTRY" >> "$GITHUB_OUTPUT"
echo "TAG_NAME=${{ env.GIT_TAG_PREFIX }}$VERSION" >> "$GITHUB_OUTPUT"
echo "IMAGE_NAME=$REGISTRY/$IMAGE_NAME:$VERSION" >> "$GITHUB_OUTPUT"
Expand Down
15 changes: 11 additions & 4 deletions .github/workflows/operator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@ on:

env:
WORKING_DIR: ./operator
GIT_TAG_PREFIX: operator_v

jobs:
verify-versions:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: sh .github/workflows/scripts/verify_operator_releasable.sh
name: Verify operator is in a state to be released on merge

build:
if: github.ref != 'refs/heads/main'
runs-on: ubuntu-latest
Expand All @@ -32,6 +38,7 @@ jobs:

release:
if: github.ref == 'refs/heads/main'
needs: verify-versions
runs-on: ubuntu-latest
defaults:
run:
Expand All @@ -40,10 +47,10 @@ jobs:
steps:
- uses: actions/checkout@v4

# set variables used by multiple steps in the job
- run: |
VERSION=$(make get-version)
echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT"
echo "TAG_NAME=${{ env.GIT_TAG_PREFIX }}$VERSION" >> "$GITHUB_OUTPUT"
TAG_NAME=$(make get-tag)
echo "TAG_NAME=$TAG_NAME" >> "$GITHUB_OUTPUT"
cat $GITHUB_OUTPUT
id: naming-selector
name: generate names for artifacts
Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/scripts/verify_changes_update_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Verifies changes to directory have an updated version

if [ -z "$1" ] || [ -z "$2" ]; then
echo "Usage: sh $0 [potential_git_tag] <path_to_directory>"
exit 1
fi

set -eux

POTENTIAL_GIT_TAG=$1
DIRECTORY=$2

main() {
# github actions job does not fetch other git objects by default
git fetch origin $GITHUB_BASE_REF
git fetch --tags

changes_in_pr=$(git diff origin/$GITHUB_BASE_REF -- $DIRECTORY)
if [ -n "$changes_in_pr" ]; then
echo "Found changes between current branch and $GITHUB_BASE_REF"
if git tag | grep -x "$POTENTIAL_GIT_TAG"; then
echo "$POTENTIAL_GIT_TAG was already released. Please increment the version if changes were made to $DIRECTORY."
exit 1
fi
fi
}

main
11 changes: 11 additions & 0 deletions .github/workflows/scripts/verify_minimal_app_releasable.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
set -eux

MINIMAL_APP_DIR=minimal-app

verify_version_bump() {
version=$(mvn -f minimal-app/pom.xml help:evaluate -Dexpression=project.version -q -DforceStdout)
potential_tag="${GIT_TAG_PREFIX}${version}"
sh .github/workflows/scripts/verify_changes_update_version.sh $potential_tag $MINIMAL_APP_DIR
}

verify_version_bump
22 changes: 22 additions & 0 deletions .github/workflows/scripts/verify_operator_releasable.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
set -eux

OPERATOR_DIR=operator
OPERATOR_CONTROLLER_YAML=$OPERATOR_DIR/controller/integrationroute-controller.yaml

verify_current_webhook_img() {
current_webhook_img=$(make --no-print-directory -C operator/webhook get-image-name)
webhook_image_used=$(yq eval '.spec.template.spec.containers[].image' $OPERATOR_CONTROLLER_YAML)

test -n "$current_webhook_img"
test -n "$webhook_image_used"

test "$webhook_image_used" = "$current_webhook_img" || (echo "Operator is not using current version of webhook image" && exit 1)
}

verify_version_bump() {
potential_tag=$(make --no-print-directory -C $OPERATOR_DIR get-tag)
sh .github/workflows/scripts/verify_changes_update_version.sh $potential_tag $OPERATOR_DIR
}

verify_current_webhook_img
verify_version_bump
10 changes: 10 additions & 0 deletions .github/workflows/scripts/verify_webhook_releasable.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
set -eux

WEBHOOK_DIR=operator/webhook

verify_version_bump() {
potential_tag=$(make --no-print-directory -C $WEBHOOK_DIR get-tag)
sh .github/workflows/scripts/verify_changes_update_version.sh $potential_tag $WEBHOOK_DIR
}

verify_version_bump
16 changes: 10 additions & 6 deletions .github/workflows/webhook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ on:

env:
WORKING_DIR: ./operator/webhook
GIT_TAG_PREFIX: webhook_v

jobs:
verify-versions:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: sh .github/workflows/scripts/verify_webhook_releasable.sh
name: Verify webhook is in a state to be released on merge
test:
name: unit test
runs-on: ubuntu-latest
Expand Down Expand Up @@ -50,7 +55,7 @@ jobs:
push: false

release:
needs: test
needs: [test, verify-versions]
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
defaults:
Expand All @@ -63,13 +68,12 @@ jobs:
steps:
- uses: actions/checkout@v4
- run: |
VERSION=$(make get-version)
REGISTRY=$(make get-registry)
IMAGE_NAME=$(make get-image-name)
echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT"
GIT_TAG=$(make get-tag)
echo "REGISTRY=$REGISTRY" >> "$GITHUB_OUTPUT"
echo "TAG_NAME=${{ env.GIT_TAG_PREFIX }}$VERSION" >> "$GITHUB_OUTPUT"
echo "FULL_IMAGE_NAME=$REGISTRY/$IMAGE_NAME:$VERSION" >> "$GITHUB_OUTPUT"
echo "TAG_NAME=$GIT_TAG" >> "$GITHUB_OUTPUT"
echo "FULL_IMAGE_NAME=$IMAGE_NAME" >> "$GITHUB_OUTPUT"
cat $GITHUB_OUTPUT
id: naming-selector
name: generate names for artifacts
Expand Down
3 changes: 2 additions & 1 deletion minimal-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<groupId>com.octo.keip</groupId>
<artifactId>minimal-app</artifactId>
<version>0.0.2</version>
<version>0.0.3</version>

<properties>
<docker.registry>ghcr.io/octoconsulting</docker.registry>
Expand Down Expand Up @@ -118,6 +118,7 @@
<to>
<image>${docker.registry}/${image-name}</image>
<tags>
<tag>latest</tag>
<tag>${project.version}</tag>
</tags>
</to>
Expand Down
11 changes: 6 additions & 5 deletions operator/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
VERSION ?= 0.3.1
KEIP_INTEGRATION_IMAGE ?= ghcr.io/octoconsulting/keip/minimal-app:0.0.2
VERSION ?= 0.3.2
GIT_TAG := operator_v$(VERSION)
KEIP_INTEGRATION_IMAGE ?= ghcr.io/octoconsulting/keip/minimal-app:latest

KUBECTL := kubectl
KUBECTL_DELETE := $(KUBECTL) delete --ignore-not-found
Expand All @@ -11,9 +12,9 @@ all: metacontroller/deploy controller/deploy
.PHONY: clean
clean: controller/undeploy metacontroller/undeploy

.PHONY: get-version
get-version:
@echo $(VERSION)
.PHONY: get-tag
get-tag:
@echo $(GIT_TAG)

prep-release:
rm -rf output
Expand Down
2 changes: 1 addition & 1 deletion operator/controller/integrationroute-controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ spec:
spec:
containers:
- name: webhook
image: ghcr.io/octoconsulting/keip/route-webhook:0.6.1
image: ghcr.io/octoconsulting/keip/route-webhook:0.6.2
ports:
- containerPort: 7080
name: webhook-http
Expand Down
11 changes: 6 additions & 5 deletions operator/webhook/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
VERSION ?= 0.6.1
VERSION ?= 0.6.2
HOST_PORT ?= 7080
GIT_TAG := webhook_v$(VERSION)

IMG_REGISTRY := ghcr.io/octoconsulting
IMG_NAME := keip/route-webhook
Expand All @@ -9,17 +10,17 @@ PYTHON := python3
TEST_COVERAGE_DIR := .test_coverage
TEST_COVERAGE_FILE := $(TEST_COVERAGE_DIR)/.coverage

.PHONY: get-version
get-version:
@echo $(VERSION)
.PHONY: get-tag
get-tag:
@echo $(GIT_TAG)

.PHONY: get-registry
get-registry:
@echo $(IMG_REGISTRY)

.PHONY: get-image-name
get-image-name:
@echo $(IMG_NAME)
@echo $(FULL_IMAGE_NAME)

.PHONY: start-dev
start-dev-server:
Expand Down

0 comments on commit 0da7124

Please sign in to comment.