From 5a2b94ad19dd3ed6cbd22a34204044fda0d76569 Mon Sep 17 00:00:00 2001 From: Jerry Belmonte Date: Thu, 12 Oct 2023 21:46:30 -0700 Subject: [PATCH 1/3] Add script to bump the release version --- Makefile | 27 +++++++++++-- release/VERSION | 1 + scripts/update_release_version.sh | 67 +++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 release/VERSION create mode 100755 scripts/update_release_version.sh diff --git a/Makefile b/Makefile index 3c34114..6f93b33 100644 --- a/Makefile +++ b/Makefile @@ -26,10 +26,11 @@ OVERRIDE_IMAGE_NAME?=$(ADAPTER_TEST_IMAGE) LDFLAGS=-w -X main.version=$(VERSION) -X main.commit=$(GIT_COMMIT) -.PHONY: all test verify-gofmt gofmt verify +.PHONY: all all: build +.PHONY: fmt fmt: find . -type f -name "*.go" | grep -v "./vendor*" | xargs gofmt -s -w @@ -37,14 +38,14 @@ fmt: build: CGO_ENABLED=0 GOARCH=$(GOARCH) go build -ldflags "$(LDFLAGS)" -a -tags netgo -o build/$(GOOS)/$(GOARCH)/$(BINARY_NAME) ./cmd/wavefront-adapter/ - +.PHONY: test test: CGO_ENABLED=0 go test ./pkg/... +.PHONY: lint lint: go vet -composites=false ./... - BUILDER_SUFFIX=$(shell echo $(PREFIX) | cut -d '/' -f1) .PHONY: publish @@ -53,5 +54,23 @@ publish: CGO_ENABLED=0 GOOS=linux GOARCH=arm64 make build -o fmt -o vet docker buildx create --use --node wavefront_k8s_adapter_builder_$(BUILDER_SUFFIX) docker buildx build --platform linux/amd64,linux/arm64 --push --pull -t $(DOCKER_REPO)/$(DOCKER_IMAGE):$(VERSION) -t $(DOCKER_REPO)/$(DOCKER_IMAGE):latest -f Dockerfile build + +.PHONY: clean clean: - rm -rf $(OUT_DIR) \ No newline at end of file + rm -rf $(OUT_DIR) + +# create a new bump version branch +.PHONY: branch +branch: + git stash + git checkout master + git pull + git checkout -b bump-version-$(VERSION) + +.PHONY: update-version +update-version: + @if [ -z "$(NEW_VERSION)" ]; then echo "Need to set NEW_VERSION" && exit 1; fi + git add Makefile + git add deploy/manifests/05-custom-metrics-apiserver-deployment.yaml + git commit -m "Bump Wavefront HPA Adapter version to $(NEW_VERSION)" + git push --set-upstream origin bump-version-$(NEW_VERSION) diff --git a/release/VERSION b/release/VERSION new file mode 100644 index 0000000..583b27a --- /dev/null +++ b/release/VERSION @@ -0,0 +1 @@ +0.9.12 diff --git a/scripts/update_release_version.sh b/scripts/update_release_version.sh new file mode 100755 index 0000000..05a143f --- /dev/null +++ b/scripts/update_release_version.sh @@ -0,0 +1,67 @@ +#!/usr/bin/env bash +set -e + +REPO_ROOT=$(git rev-parse --show-toplevel) +cd "${REPO_ROOT}" + +function get_bumped_version() { + local version="$1" + local bump_component="$2" + + semver-cli inc "${bump_component}" "${version}" +} + +function check_required_argument() { + local required_arg="$1" + local failure_msg="$2" + + if [[ -z "${required_arg}" ]]; then + print_usage_and_exit "${failure_msg}" + fi +} + +function print_usage_and_exit() { + echo "Failure: $1" + echo "Usage: $0 [flags] [options]" + echo -e "\t-v version to bump (required)" + echo -e "\t-s semver component to bump (required, ex: major, minor, patch)" + exit 1 +} + +function main() { + local VERSION='' + local BUMP_COMPONENT='' + local NEXT_RELEASE_VERSION='' + local FUTURE_RELEASE_VERSION='' + + while getopts ":v:s:" opt; do + case $opt in + v) VERSION="$OPTARG";; + s) BUMP_COMPONENT="$OPTARG";; + \?) print_usage_and_exit "Invalid option: -$OPTARG";; + esac + done + + check_required_argument "${VERSION}" "-v is required" + check_required_argument "${BUMP_COMPONENT}" "-s is required" + + echo "Current release version: ${VERSION}" + + NEXT_RELEASE_VERSION="$(get_bumped_version "${VERSION}" "${BUMP_COMPONENT}")" + echo "Next release version: ${NEXT_RELEASE_VERSION}" + + # update the version in the image tag + sed -i.bak "s/wavefront-hpa-adapter:${VERSION}/wavefront-hpa-adapter:${NEXT_RELEASE_VERSION}/g" "${REPO_ROOT}"/deploy/manifests/05-custom-metrics-apiserver-deployment.yaml + rm -f "${REPO_ROOT}"/deploy/manifests/05-custom-metrics-apiserver-deployment.yaml.bak + + echo "${NEXT_RELEASE_VERSION}" >"${REPO_ROOT}"/release/VERSION + + FUTURE_RELEASE_VERSION="$(get_bumped_version "${NEXT_RELEASE_VERSION}" "patch")" + echo "Future release version: ${FUTURE_RELEASE_VERSION}" + + # update the version in the Makefile + sed -i.bak "s/VERSION?=[0-9.]*/VERSION?=${FUTURE_RELEASE_VERSION}/g" "${REPO_ROOT}"/Makefile + rm -f "${REPO_ROOT}"/Makefile.bak +} + +main "$@" From e0db3fd88d5135c33541fc19a614a7c13d27e8b6 Mon Sep 17 00:00:00 2001 From: Jerry Belmonte Date: Fri, 13 Oct 2023 00:11:01 -0700 Subject: [PATCH 2/3] Add bump version Jenkinsfile --- Makefile | 3 +- bump-version.Jenkinsfile | 74 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 bump-version.Jenkinsfile diff --git a/Makefile b/Makefile index 6f93b33..e0c29ec 100644 --- a/Makefile +++ b/Makefile @@ -71,6 +71,7 @@ branch: update-version: @if [ -z "$(NEW_VERSION)" ]; then echo "Need to set NEW_VERSION" && exit 1; fi git add Makefile + git add release/VERSION git add deploy/manifests/05-custom-metrics-apiserver-deployment.yaml - git commit -m "Bump Wavefront HPA Adapter version to $(NEW_VERSION)" + git commit -m "Bump version to $(NEW_VERSION)" git push --set-upstream origin bump-version-$(NEW_VERSION) diff --git a/bump-version.Jenkinsfile b/bump-version.Jenkinsfile new file mode 100644 index 0000000..e465e14 --- /dev/null +++ b/bump-version.Jenkinsfile @@ -0,0 +1,74 @@ +pipeline { + agent any + + tools { go 'Go 1.18' } + + environment { + PATH = "${env.WORKSPACE}/bin:${env.HOME}/go/bin:${env.PATH}" + GIT_CREDENTIAL_ID = 'wf-jenkins-github' + GITHUB_TOKEN = credentials('GITHUB_TOKEN') + REPO_NAME = 'wavefront-kubernetes-adapter' + } + + parameters { + choice(name: 'BUMP_COMPONENT', choices: ['patch', 'minor', 'major'], description: 'Specify a semver component to bump.') + } + + stages { + // stage('Build and Run Tests') { + // steps { + // sh 'make fmt lint build test' + // } + // } + + stage('Create Bump Version PR') { + environment { + BUMP_COMPONENT = "${params.BUMP_COMPONENT}" + } + + steps { + sh 'git config --global user.email "svc.wf-jenkins@vmware.com"' + sh 'git config --global user.name "svc.wf-jenkins"' + sh 'git remote set-url origin https://${GITHUB_TOKEN}@github.com/wavefronthq/${REPO_NAME}.git' + sh 'CGO_ENABLED=0 go install github.com/davidrjonas/semver-cli@latest' + sh './scripts/update_release_version.sh -v $(cat release/VERSION) -s ${BUMP_COMPONENT}' + script { + env.NEW_VERSION_NUMBER = sh(script: 'cat release/VERSION', returnStdout: true).trim() + } + sh 'echo "New version number: ${NEW_VERSION_NUMBER}"' + sh 'git branch -D bump-version-$(cat release/VERSION) &>/dev/null || true' + sh 'git checkout -b bump-version-$(cat release/VERSION)' + sh 'make update-version NEW_VERSION=$(cat release/VERSION)' + sh ''' + VERSION_NUMBER=$(cat release/VERSION) + curl -X POST \ + -H 'Accept: application/vnd.github+json' \ + -H "Authorization: Bearer ${GITHUB_TOKEN}" \ + -H 'X-GitHub-Api-Version: 2022-11-28' \ + -d "\"{\"head\":\"bump-version-${VERSION_NUMBER}\",\"base\":\"master\",\"title\":\"Bump version to ${VERSION_NUMBER}\"}\"" \ + https://api.github.com/repos/wavefrontHQ/${REPO_NAME}/pulls + ''' + } + } + } + + // Notify only on null->failure or success->failure or failure->success + // post { + // failure { + // script { + // if(currentBuild.previousBuild == null) { + // slackSend (channel: '#tobs-k8po-team', color: '#FF0000', message: "Bump version failed: <${env.BUILD_URL}|${env.JOB_NAME} [${env.BUILD_NUMBER}]>") + // } + // } + // } + // regression { + // slackSend (channel: '#tobs-k8po-team', color: '#FF0000', message: "Bump version failed: <${env.BUILD_URL}|${env.JOB_NAME} [${env.BUILD_NUMBER}]>") + // } + // fixed { + // slackSend (channel: '#tobs-k8po-team', color: '#008000', message: "Bump version fixed: <${env.BUILD_URL}|${env.JOB_NAME} [${env.BUILD_NUMBER}]>") + // } + // always { + // cleanWs() + // } + // } +} From a0c4ceb8a529fca3d3018f7166b711e1401d862c Mon Sep 17 00:00:00 2001 From: Jerry Belmonte Date: Fri, 13 Oct 2023 02:32:10 -0700 Subject: [PATCH 3/3] Add script to create bump version pr --- bump-version.Jenkinsfile | 63 ++++++++++++------------------- scripts/create_bump_version_pr.sh | 62 ++++++++++++++++++++++++++++++ scripts/update_release_version.sh | 3 +- 3 files changed, 88 insertions(+), 40 deletions(-) create mode 100755 scripts/create_bump_version_pr.sh diff --git a/bump-version.Jenkinsfile b/bump-version.Jenkinsfile index e465e14..859615e 100644 --- a/bump-version.Jenkinsfile +++ b/bump-version.Jenkinsfile @@ -15,11 +15,11 @@ pipeline { } stages { - // stage('Build and Run Tests') { - // steps { - // sh 'make fmt lint build test' - // } - // } + stage('Build and Run Tests') { + steps { + sh 'make fmt lint build test' + } + } stage('Create Bump Version PR') { environment { @@ -32,43 +32,28 @@ pipeline { sh 'git remote set-url origin https://${GITHUB_TOKEN}@github.com/wavefronthq/${REPO_NAME}.git' sh 'CGO_ENABLED=0 go install github.com/davidrjonas/semver-cli@latest' sh './scripts/update_release_version.sh -v $(cat release/VERSION) -s ${BUMP_COMPONENT}' - script { - env.NEW_VERSION_NUMBER = sh(script: 'cat release/VERSION', returnStdout: true).trim() - } - sh 'echo "New version number: ${NEW_VERSION_NUMBER}"' - sh 'git branch -D bump-version-$(cat release/VERSION) &>/dev/null || true' - sh 'git checkout -b bump-version-$(cat release/VERSION)' - sh 'make update-version NEW_VERSION=$(cat release/VERSION)' - sh ''' - VERSION_NUMBER=$(cat release/VERSION) - curl -X POST \ - -H 'Accept: application/vnd.github+json' \ - -H "Authorization: Bearer ${GITHUB_TOKEN}" \ - -H 'X-GitHub-Api-Version: 2022-11-28' \ - -d "\"{\"head\":\"bump-version-${VERSION_NUMBER}\",\"base\":\"master\",\"title\":\"Bump version to ${VERSION_NUMBER}\"}\"" \ - https://api.github.com/repos/wavefrontHQ/${REPO_NAME}/pulls - ''' + sh './scripts/create_bump_version_pr.sh -v $(cat release/VERSION) -t ${GITHUB_TOKEN}' } } } // Notify only on null->failure or success->failure or failure->success - // post { - // failure { - // script { - // if(currentBuild.previousBuild == null) { - // slackSend (channel: '#tobs-k8po-team', color: '#FF0000', message: "Bump version failed: <${env.BUILD_URL}|${env.JOB_NAME} [${env.BUILD_NUMBER}]>") - // } - // } - // } - // regression { - // slackSend (channel: '#tobs-k8po-team', color: '#FF0000', message: "Bump version failed: <${env.BUILD_URL}|${env.JOB_NAME} [${env.BUILD_NUMBER}]>") - // } - // fixed { - // slackSend (channel: '#tobs-k8po-team', color: '#008000', message: "Bump version fixed: <${env.BUILD_URL}|${env.JOB_NAME} [${env.BUILD_NUMBER}]>") - // } - // always { - // cleanWs() - // } - // } + post { + failure { + script { + if(currentBuild.previousBuild == null) { + slackSend (channel: '#tobs-k8po-team', color: '#FF0000', message: "Bump version failed: <${env.BUILD_URL}|${env.JOB_NAME} [${env.BUILD_NUMBER}]>") + } + } + } + regression { + slackSend (channel: '#tobs-k8po-team', color: '#FF0000', message: "Bump version failed: <${env.BUILD_URL}|${env.JOB_NAME} [${env.BUILD_NUMBER}]>") + } + fixed { + slackSend (channel: '#tobs-k8po-team', color: '#008000', message: "Bump version fixed: <${env.BUILD_URL}|${env.JOB_NAME} [${env.BUILD_NUMBER}]>") + } + always { + cleanWs() + } + } } diff --git a/scripts/create_bump_version_pr.sh b/scripts/create_bump_version_pr.sh new file mode 100755 index 0000000..3ddfb96 --- /dev/null +++ b/scripts/create_bump_version_pr.sh @@ -0,0 +1,62 @@ +#!/usr/bin/env bash +set -eou pipefail + +REPO_ROOT="$(git rev-parse --show-toplevel)" + +function create_pull_request() { + local version="$1" + local token="$2" + local branch_name="$3" + + curl -fsSL -X 'POST' \ + -H 'Accept: application/vnd.github+json' \ + -H "Authorization: Bearer ${token}" \ + -H 'X-GitHub-Api-Version: 2022-11-28' \ + -d "{\"head\":\"${branch_name}\",\"base\":\"master\",\"title\":\"Bump version to ${version}\"}" \ + https://api.github.com/repos/wavefrontHQ/wavefront-kubernetes-adapter/pulls +} + +function check_required_argument() { + local required_arg="$1" + local failure_msg="$2" + + if [[ -z "${required_arg}" ]]; then + print_usage_and_exit "${failure_msg}" + fi +} + +function print_usage_and_exit() { + echo "Failure: $1" + echo "Usage: $0 [flags] [options]" + echo -e "\t-v bump version (required)" + echo -e "\t-t github token (required)" + exit 1 +} + +function main() { + cd "${REPO_ROOT}" + + local VERSION='' + local GITHUB_TOKEN='' + + while getopts ":v:t:" opt; do + case $opt in + v) VERSION="$OPTARG";; + t) GITHUB_TOKEN="$OPTARG";; + \?) print_usage_and_exit "Invalid option: -$OPTARG";; + esac + done + + check_required_argument "${VERSION}" "-v is required" + check_required_argument "${GITHUB_TOKEN}" "-t is required" + + local GIT_BUMP_BRANCH_NAME="bump-version-${VERSION}" + git branch -D "$GIT_BUMP_BRANCH_NAME" &>/dev/null || true + git checkout -b "$GIT_BUMP_BRANCH_NAME" + + make update-version NEW_VERSION="${VERSION}" + + create_pull_request "${VERSION}" "${GITHUB_TOKEN}" "${GIT_BUMP_BRANCH_NAME}" +} + +main "$@" diff --git a/scripts/update_release_version.sh b/scripts/update_release_version.sh index 05a143f..716000f 100755 --- a/scripts/update_release_version.sh +++ b/scripts/update_release_version.sh @@ -2,7 +2,6 @@ set -e REPO_ROOT=$(git rev-parse --show-toplevel) -cd "${REPO_ROOT}" function get_bumped_version() { local version="$1" @@ -29,6 +28,8 @@ function print_usage_and_exit() { } function main() { + cd "${REPO_ROOT}" + local VERSION='' local BUMP_COMPONENT='' local NEXT_RELEASE_VERSION=''