#!/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_NUMBER 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_NUMBER:?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_NUMBER; then log "Error: the VERSION_NUMBER 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 if [ -z "${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)) fi 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 <