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

add make targets for building release candidates #42

Merged
merged 1 commit into from
Aug 19, 2022
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
61 changes: 61 additions & 0 deletions Makefile.release
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
####################################################################################################
# CORE COMMANDS

.PHONY: __tag-release-candidate
__tag-release-candidate:
@echo "+++ Tagging release candidate"
@./scripts/fail-if-dirty-repo.sh # Fail if the repo is dirty
@echo "+++ Tagging commit $(shell git rev-parse HEAD) with CS_VERSION=$(CS_VERSION)"
CS_VERSION="$(CS_VERSION)" ./scripts/tag-release-candidate.sh

.PHONY: __build-release-candidate
__build-release-candidate: __tag-release-candidate
@echo "+++ Building release candidate"
@$(eval GCR_PREFIX := "config-management-release")
@test -n "$(CS_VERSION)" || (echo "CS_VERSION unset" ; exit 1)
$(eval RC_TAG != git tag --points-at "HEAD" --list "$(CS_VERSION)-rc.*" | sort -V | tail -n 1)
@test -n "$(RC_TAG)" || (echo "RC_TAG unset" ; exit 1)

$(MAKE) config-sync-manifest \
VERSION=$(RC_TAG) \
GCR_PREFIX=$(GCR_PREFIX) \
IMAGE_TAG=$(RC_TAG)
$(MAKE) build-cli VERSION=$(RC_TAG)

$(eval RELEASE_PATH = "gs://config-management-release/config-sync/tag/$(RC_TAG)")
$(MAKE) __upload-manifest RELEASE_PATH=$(RELEASE_PATH)
$(MAKE) __upload-cli RELEASE_PATH=$(RELEASE_PATH)


####################################################################################################
# SUPPORTING COMMANDS

PHONY: __upload-manifest
__upload-manifest:
@test -n "$(RELEASE_PATH)" || (echo "RELEASE_PATH unset" ; exit 1)
@$(eval MANIFEST_DESTINATION = "$(RELEASE_PATH)/config-sync-manifest.yaml")
@echo "+++ Uploading config-sync-manifest.yaml to $(MANIFEST_DESTINATION)"
@echo "${NOMOS_MANIFEST_STAGING_DIR}"
gsutil cp \
"${NOMOS_MANIFEST_STAGING_DIR}/config-sync-manifest.yaml" \
$(MANIFEST_DESTINATION)

.PHONY: __upload-cli
__upload-cli:
@test -n "$(RELEASE_PATH)" || (echo "RELEASE_PATH unset" ; exit 1)
@echo "+++ Uploading CLI Binaries to $(RELEASE_PATH)"
gsutil cp \
"$(BIN_DIR)/linux_amd64/nomos" \
"$(RELEASE_PATH)/linux_amd64/nomos"
gsutil cp \
"$(BIN_DIR)/linux_arm64/nomos" \
"$(RELEASE_PATH)/linux_arm64/nomos"
gsutil cp \
"$(BIN_DIR)/darwin_amd64/nomos" \
"$(RELEASE_PATH)/darwin_amd64/nomos"
gsutil cp \
"$(BIN_DIR)/darwin_arm64/nomos" \
"$(RELEASE_PATH)/darwin_arm64/nomos"
gsutil cp \
"$(BIN_DIR)/windows_amd64/nomos.exe" \
"$(RELEASE_PATH)/windows_amd64/nomos.exe"
36 changes: 20 additions & 16 deletions scripts/tag-version.sh → scripts/tag-release-candidate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,27 @@ set -eo pipefail
# It's crucial that error messages in these functions be sent to stderr with 1>&2.
# Otherwise, they will not bubble up to the make target that calls this script.

err () {
local msg="$1"
echo "${msg}" 1>&2
exit 1
}

latest_rc_of_version () {
local version="$1"
if [ -z "$version" ]; then
echo "Error: function expects version argument" 1>&2
exit 1
err "Error: function expects version argument"
fi


# 1. Get all the versions with the right prefix,
# 2. order them by their "rc.X" values
# 3. Take the last/highest one
rc=$(git tag --list "$version*" | sort -V | tail -n 1)
rc=$(git tag --list "${version}-rc.*" | sort -V | tail -n 1)
if [ -z "$rc" ]; then
echo "Error: no RC found with prefix: ${version}" 1>&2
exit 1
# Return contrived initial zero tag. It will get incremented to 1.
rc="${version}-rc.0"
echo "no RC found for ${version} - Creating initial RC" 1>&2
fi
echo "$rc"
}
Expand All @@ -55,8 +61,7 @@ increment_rc_of_semver () {
local semver="${1}"

if [ -z "$semver" ]; then
echo "Error: must pass an argument in SEMVER style. Looks like vMAJOR.MINOR.PATCH-rc.X" 1>&2
exit 1
err "Error: must pass an argument in SEMVER style. Looks like vMAJOR.MINOR.PATCH-rc.X"
fi

# Split the semver string on "."
Expand All @@ -74,14 +79,9 @@ increment_rc_of_semver () {

####################################################################################################

if [ -z "$CS_VERSION" ]; then
echo "Error: must specify enviroment variable CS_VERSION in style vMAJOR.MINOR.PATCH" 1>&2
exit 1
fi

# If a user omits the leading "v" (enters 1.2.3 instead of v1.2.3), handle it.
if ! [[ "${CS_VERSION}" = v* ]]; then
CS_VERSION="v${CS_VERSION}"
janetkuo marked this conversation as resolved.
Show resolved Hide resolved
# If a user omits the leading "v" (enters 1.2.3 instead of v1.2.3), throw an error.
if ! [[ "${CS_VERSION}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
err "Error: CS_VERSION must be in the form v1.2.3 - got ${CS_VERSION}"
fi

# Fetch all existing tags
Expand All @@ -95,4 +95,8 @@ NEXT_RC=$(increment_rc_of_semver "$RC")
echo "+++ Incremented RC. NEXT_RC: $NEXT_RC"

git tag -a "$NEXT_RC" -m "Release candidate $NEXT_RC"
echo "+++ Succesfully tagged commit $(git rev-parse HEAD) as $NEXT_RC"
echo "+++ Successfully tagged commit $(git rev-parse HEAD) as ${NEXT_RC}"

echo "+++ Pushing RC tag"
REMOTE="git@github.com:GoogleContainerTools/kpt-config-sync.git"
git push "${REMOTE}" "${NEXT_RC}"