From 36f242224b2e588fa2d90539d4b8acb94f8d669f Mon Sep 17 00:00:00 2001 From: Mario Vitale Date: Mon, 11 Dec 2023 17:57:29 +0100 Subject: [PATCH] CLD-6707 Automate weekly build (#7685) * Add utility scripts for automating the build/version number bump PRs --- scripts/bump.sh | 110 +++++++++++++++++++++++++++++ scripts/get_latest_build_number.sh | 15 ++++ 2 files changed, 125 insertions(+) create mode 100755 scripts/bump.sh create mode 100755 scripts/get_latest_build_number.sh diff --git a/scripts/bump.sh b/scripts/bump.sh new file mode 100755 index 000000000..822910280 --- /dev/null +++ b/scripts/bump.sh @@ -0,0 +1,110 @@ +#!/bin/bash +set -eu -o pipefail +cd "$(dirname "$0")"/.. + +log () { echo "[$(date +%Y-%m-%dT%H:%M:%S%Z)]" "$@"; } + +: ${BRANCH_TO_BUILD:=main} +: ${PR_REVIEWERS:=mattermost/core-build-engineers} +: ${BUMP_BUILD_NUMBER:=} # You can optionally specify the BUILD_NUMBER variable for selecting the next build number + # If you don't, then the Fastlane action will pick the next build number automatically +: ${BUMP_VERSION_NUMBER:=} # If enabled, you must populate the VERSION variable as well +: ${CREATE_PR:=} # Enable CREATE_PR to push the commit to origin, and create a corresponding PR +: ${PR_EXTRA_MESSAGE:=} # Optional message to add in the PR description +: ${GIT_LOCAL_BRANCH:=chore-bump-${BRANCH_TO_BUILD}-$(date +%s)} + +log "Checking that the configuration is sane" +if [ -z "${BUMP_BUILD_NUMBER}" -a -z "${BUMP_VERSION_NUMBER}" ]; then + log "Error: you must set at least one between BUMP_BUILD_NUMBER and BUMP_VERSION_NUMBER" >&2 + exit 1 +fi +if [ -n "$BUMP_VERSION_NUMBER" ]; then + : ${VERSION:?Setting this variable is required when BUMP_VERSION_NUMBER is set.} + VERSION_REGEXP='^[0-9]+\.[0-9]+\.[0-9]+$' + if ! grep -qE $VERSION_REGEXP"" <<<$VERSION; then + log "Error: the VERSION variable value should match regexp '$VERSION_REGEXP'. Aborting." >&2 + exit 2 + fi +fi + +log "Asserting that the workdir is clean" +if ! git diff --quiet; then + log "Error: workdir is not clean. Aborting" >&2 + exit 3 +fi + +log "Saving the currently checked out branch" +CURRENT_BRANCH=$(git branch --show-current) +trap "git checkout $CURRENT_BRANCH" EXIT + +if [ -n "$BUMP_BUILD_NUMBER" ]; then + log "Selecting the next largest build number..." + LATEST_BUILD_NUMBER=$(./scripts/get_latest_build_number.sh) + BUILD_NUMBER=$(($LATEST_BUILD_NUMBER + 1)) + log "Build number to use for the beta build: $BUILD_NUMBER" +fi + +log "Creating branch '${GIT_LOCAL_BRANCH}' based on branch '$BRANCH_TO_BUILD'" +git checkout $BRANCH_TO_BUILD +git pull +git checkout -b $GIT_LOCAL_BRANCH + +log "Generating env file required by Fastlane..." +tee .env <