diff --git a/.github/workflows/version-check.yaml b/.github/workflows/version-check.yaml new file mode 100644 index 00000000..98f87e3c --- /dev/null +++ b/.github/workflows/version-check.yaml @@ -0,0 +1,21 @@ +name: version-check +on: + pull_request: + branches: + - main + paths: + - Makefile + - go.mod + +jobs: + version-check: + name: runtime version in-sync + runs-on: ubuntu-latest + steps: + - name: checkout code + uses: actions/checkout@v2 + - uses: actions/setup-go@v2 + with: + go-version: '1.15' + - name: make check-versions + run: make check-versions \ No newline at end of file diff --git a/Makefile b/Makefile index 8eaa142c..d1a43e03 100644 --- a/Makefile +++ b/Makefile @@ -40,6 +40,9 @@ local-build-controller-image: export LOCAL_MODULES = true local-build-controller-image: ## Build container image for SERVICE allowing local modules @./scripts/build-controller-image.sh $(AWS_SERVICE) +check-versions: ## Checks the code-generator version matches the runtime dependency version + @./scripts/check-versions.sh $(VERSION) + test: ## Run code tests go test ${GO_TAGS} ./... diff --git a/scripts/check-versions.sh b/scripts/check-versions.sh new file mode 100755 index 00000000..f13088c3 --- /dev/null +++ b/scripts/check-versions.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash + +# A script that ensures the code-generator binary version matches its associated +# runtime version + +set -eo pipefail + +SCRIPTS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +ROOT_DIR="$SCRIPTS_DIR/.." + +USAGE=" +Usage: + $(basename "$0") + +Checks that the code-generator version located in the Makefile matches the +runtime version pinned in go.mod +" + +if [ $# -ne 1 ]; then + echo "ERROR: $(basename "$0") only accepts a single parameter" 1>&2 + echo "$USAGE" + exit 1 +fi + +RUNTIME_DEPENDENCY_VERSION="aws-controllers-k8s/runtime" +GO_MOD_VERSION=$(go list -m -f '{{ .Version }}' github.com/aws-controllers-k8s/runtime) + +if [[ "$1" != "$GO_MOD_VERSION" ]]; then + echo "Code-generator version in Makefile $1 does not match $RUNTIME_DEPENDENCY_VERSION version $GO_MOD_VERSION" + exit 1 +fi + +exit 0 \ No newline at end of file