flatcar-scripts/tag_release
Flatcar Buildbot 1dad511f69 2317.0.1
2019-11-07 19:40:01 +01:00

190 lines
6.7 KiB
Bash
Executable File

#!/bin/bash
# Copyright (c) 2013 The CoreOS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
git_confirm() {
local response
if [[ ${FLAGS_force} -ne ${FLAGS_TRUE} ]]; then
echo "Executing: git $@"
while [[ "${response}" != "y" ]]; do
echo -n "Proceed? (y/n) "
read response
if [[ "${response}" == "n" ]]; then
echo "Aborting."
exit 1
fi
done
fi
git "$@"
}
SCRIPT_ROOT=$(dirname $(readlink -f "$0"))
. "${SCRIPT_ROOT}/common.sh" || exit 1
DEFAULT_MAJOR=${TODAYS_VERSION}
DEFAULT_MINOR=0
DEFAULT_BRANCH=${FLAGS_FALSE}
DEFAULT_BRANCH_PROJECTS=
CURRENT_VERSION=( ${FLATCAR_VERSION_ID//./ } )
# Detect if we are on a branch or still tracking master.
DEFAULT_MANIFEST=$(readlink "${REPO_MANIFESTS_DIR}/default.xml") \
|| die "Failed to read default manifest link"
if [[ "${DEFAULT_MANIFEST}" != master.xml ]]; then
DEFAULT_MAJOR=${CURRENT_VERSION[0]}
DEFAULT_BRANCH=${FLAGS_TRUE}
else
DEFAULT_BRANCH_PROJECTS='coreos-overlay portage-stable scripts'
fi
# Increment $MINOR if we already made a major release.
if [[ ${DEFAULT_MAJOR} -eq ${CURRENT_VERSION[0]} ]]; then
DEFAULT_MINOR=$((${CURRENT_VERSION[1]} + 1))
fi
DEFINE_integer major ${DEFAULT_MAJOR} "Branch major version (aka 'build')"
DEFINE_integer minor ${DEFAULT_MINOR} "Branch revision or minor version"
DEFINE_integer patch 0 "Branch patch id, normally 0"
DEFINE_string sdk_version "${FLATCAR_VERSION_ID}" \
"SDK version to use, or 'keep'. (current: ${FLATCAR_SDK_VERSION})"
DEFINE_boolean branch ${DEFAULT_BRANCH} "Release branch, diverge from master"
DEFINE_string branch_projects "${DEFAULT_BRANCH_PROJECTS}" \
"Branch the named projects (with a 'coreos/' prefix) in the manifest."
DEFINE_boolean push ${FLAGS_FALSE} "Push to public manifest repository."
DEFINE_boolean force ${FLAGS_FALSE} "Don't prompt before pushing."
DEFINE_string remote "origin" "Remote name or URL to push to."
DEFINE_string signer '' "Alternate GPG key ID used to sign the tag."
# Parse flags
FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
switch_to_strict_mode
# Easy to mix up versions when tagging a branch, so double check.
if [[ ${FLAGS_branch} -eq ${FLAGS_TRUE} ]]; then
if [[ ${FLAGS_major} -ne ${CURRENT_VERSION[0]} ]]; then
die_notrace "Branch major should be ${CURRENT_VERSION[0]}"
fi
if [[ ${FLAGS_minor} -lt ${CURRENT_VERSION[1]} ]]; then
die_notrace "Branch minor should be at least ${CURRENT_VERSION[1]}"
fi
if [[ ${FLAGS_minor} -eq ${CURRENT_VERSION[1]} && ${FLAGS_patch} -le ${CURRENT_VERSION[2]} ]]; then
die_notrace "With minor ${FLAGS_minor}, branch patch should be greater than ${CURRENT_VERSION[2]}"
fi
fi
BRANCH_NAME="build-${FLAGS_major}"
BRANCH_VERSION="${FLAGS_major}.${FLAGS_minor}.${FLAGS_patch}"
TAG_NAME="v${BRANCH_VERSION}"
if [[ "${FLAGS_sdk_version}" == keep || "${FLAGS_sdk_version}" == current ]]
then
FLAGS_sdk_version="${FLATCAR_SDK_VERSION}"
fi
if [[ "${FLAGS_sdk_version}" == "${BRANCH_VERSION}" ]]; then
die_notrace "SDK version must be different from the new tag's version!" \
" Conflicting version: ${BRANCH_VERSION}" \
"Try --sdk_version keep to use the existing SDK."
fi
# Verify that the specified SDK version exists
FLATCAR_SDK_VERSION="${FLAGS_sdk_version}"
. "${SCRIPT_ROOT}/sdk_lib/sdk_util.sh"
if ! curl --head --fail --silent "${FLATCAR_SDK_URL}" > /dev/null ; then
die_notrace "SDK version does not exist." \
"Try --sdk_version keep to use the existing SDK."
fi
sign_args=( -s )
if [ -n "${FLAGS_signer}" ]; then
sign_args=( -u "${FLAGS_signer}" )
fi
cd "${REPO_MANIFESTS_DIR}"
# Clean up existing branch manifest(s) excluding:
# - the current branch if the file already exists.
# - one previous branch, useful for comparing releases.
OLD_BRANCHES=$(find -maxdepth 1 -name 'build-*.xml' \
-not -name "${BRANCH_NAME}.xml" | sort -rn | tail -n -1)
if [[ -n "${OLD_BRANCHES}" ]]; then
git rm -f ${OLD_BRANCHES}
fi
# transitional, now a file but used to be a symlink.
if [[ -L release.xml ]]; then
rm release.xml
fi
# Generate a release manifest with all revisions pinned
tmp=$(mktemp --suffix repo)
trap "rm --force ${tmp}" EXIT
repo manifest -o ${tmp} -r
# double check because repo may not exit with non-zero on failure
[[ -s ${tmp} ]] || die "repo failed to generate release.xml (${tmp})"
mv ${tmp} release.xml
git add release.xml
# Generate a branch manifest, unpinning any branched projects.
# OW! Don't hit me! I'll write this for real in Go soon I swear!
sed -e "s%revision=.*upstream=\"refs/heads/${BRANCH_NAME}\"%revision=\"refs/heads/${BRANCH_NAME}\"%" release.xml > "${BRANCH_NAME}.xml"
git add "${BRANCH_NAME}.xml"
if [[ ${FLAGS_branch} -eq ${FLAGS_TRUE} ]]; then
ln -sf "${BRANCH_NAME}.xml" default.xml
git add default.xml
fi
tee version.txt <<EOF
FLATCAR_VERSION=${BRANCH_VERSION}
FLATCAR_VERSION_ID=${BRANCH_VERSION}
FLATCAR_BUILD_ID=""
FLATCAR_SDK_VERSION=${FLAGS_sdk_version}
EOF
git add version.txt
# Help various pinentry programs find the tty.
GPG_TTY=$(tty)
export GPG_TTY
info "Creating ${BRANCH_NAME} and tag ${TAG_NAME}"
git commit -m "${BRANCH_NAME}: release ${TAG_NAME}"
git branch -f "${BRANCH_NAME}"
git tag "${sign_args[@]}" -m "Flatcar ${TAG_NAME}" "${TAG_NAME}"
# Unpin and branch the important projects, if requested and they are pinned.
if [[ -n "${FLAGS_branch_projects}" ]]; then
sed -i -e "/ name=\"coreos\/\(${FLAGS_branch_projects// /\\|}\)\" /s%revision=.*upstream=.*\"%revision=\"refs/heads/${BRANCH_NAME}\"%" "${BRANCH_NAME}.xml"
ln -sf "${BRANCH_NAME}.xml" default.xml
git add default.xml "${BRANCH_NAME}.xml"
git commit -m "${BRANCH_NAME}: branch projects" -m "Branched: ${FLAGS_branch_projects}"
git branch -f "${BRANCH_NAME}"
git reset --hard HEAD^
# Create new branches in the projects' upstream repositories.
if [[ ${FLAGS_push} -eq ${FLAGS_TRUE} ]]; then
remote=$(sed -n '/<default /s/.* remote="\([^"]*\)".*/\1/p' release.xml)
for project in ${FLAGS_branch_projects}; do
info=$(sed -n 's,.* name="coreos/'${project}'".* path="\([^"]*\)".* revision="\([0-9A-Fa-f]*\)".*,\2 \1,p' release.xml)
info "Creating branch ${BRANCH_NAME} at ${info%% *} in ${project}"
git_confirm -C "${REPO_ROOT}/${info#* }" push "${remote}" "${info%% *}:refs/heads/${BRANCH_NAME}"
done
fi
fi
if [[ ${FLAGS_push} -eq ${FLAGS_TRUE} ]]; then
master="HEAD:refs/heads/master"
if [[ ${FLAGS_branch} -eq ${FLAGS_TRUE} ]]; then
master=""
fi
info 'Pushing manifest updates'
git_confirm push "${FLAGS_remote}" $master \
"refs/heads/${BRANCH_NAME}" \
"refs/tags/${TAG_NAME}"
fi