From 00d4c870ed190b254658648ec57ee47a3730e820 Mon Sep 17 00:00:00 2001 From: Chris Frantz Date: Sat, 28 Jan 2023 01:01:41 +0000 Subject: [PATCH] Add the capability to copy release artifacts 1. Add the capability to copy release artifacts to a specified location. 2. Add the capability to skip the github release process. In order to make artifacts available from CI runs, we need to copy them to a location known to our workflow. Since we don't want to rely on bazel's internal directory hierarchy, we'll make the release process copy the release artifacts to a user-specified subdirectory. Signed-off-by: Chris Frantz --- release/release.template.bash | 69 ++++++++++++++++++++++++++++------- 1 file changed, 55 insertions(+), 14 deletions(-) diff --git a/release/release.template.bash b/release/release.template.bash index 3b03cd4..e452a6c 100644 --- a/release/release.template.bash +++ b/release/release.template.bash @@ -6,12 +6,15 @@ function usage() { echo "bazel run @@LABEL@@ -- [options] [release_tag]" echo " -R|--repo <[HOST/]OWNER/REPO> : Select another repository" echo " -d|--draft : Save the release as a draft instead of publishing it" - echo " --dry-run : Print the GitHub CLI invocation" + echo " --[no]dry-run : Print the GitHub CLI invocation" echo " -p|--prerelease : Mark the release as a prerelease" echo " -t|--title : Release title" echo " -n|--notes : Release notes" echo " -F|--notes-file : Read release notes from file" echo " --target : Target branch or git commit SHA" + echo " --[no]script : Run (or skip) the 'script' portion of process" + echo " --[no]release : Perform (or skip) the relese process on github" + echo " --copy : Copy the release artifacts to the named subdir" echo " -h|-?|--help : This message" echo echo "If a release_tag is not given, the last git tag is assumed to be the" @@ -26,6 +29,14 @@ function run() { fi } +function option_or_no() { + if [[ "$1" == "--no"* ]]; then + echo 0 + else + echo 1 + fi +} + ARTIFACTS=(@@ARTIFACTS@@) FILES=(@@FILES@@) GH=@@GH@@ @@ -43,8 +54,12 @@ TITLE=() NOTES=() GENERATE_NOTES=("--generate-notes") DRY_RUN=0 +SCRIPT=1 +RELEASE=1 +COPY="" # Parse the same set of arguments as `gh release create`. +shopt -s extglob while [[ $# -gt 0 ]]; do case "$1" in @@ -56,8 +71,9 @@ do DRAFT=("--draft") shift ;; - --dry-run|--dry_run) + --?(no)dry[-_]run) DRY_RUN=1 + DRY_RUN=$(option_or_no "$1") shift ;; -p|--prerelease) @@ -82,6 +98,18 @@ do BRANCH="$2" shift 2 ;; + --copy) + COPY="$2" + shift 2 + ;; + --?(no)release) + RELEASE=$(option_or_no "$1") + shift + ;; + --?(no)script) + SCRIPT=$(option_or_no "$1") + shift + ;; -\?|-h|--help) usage exit @@ -102,7 +130,7 @@ if [[ -z "${RELEASE_TAG}" ]]; then RELEASE_TAG=$(cd "$BUILD_WORKSPACE_DIRECTORY" && git describe --abbrev=0 --tags) fi -if $(${GH} release list | egrep -q "\s${RELEASE_TAG}\s"); then +if [[ ${RELEASE} == 1 ]] && $(${GH} release list | egrep -q "\s${RELEASE_TAG}\s"); then echo "A release with tag ${RELEASE_TAG} already exists." echo echo "To make a new release, create a new tag first or specify the tag on" @@ -119,15 +147,28 @@ done export ARTIFACTS BRANCH FILES GH REMOTE RELEASE_TAG DIGEST -# A script fragment substituted in from the `release` rule. -@@SCRIPT@@ -# End script. +if [[ ${SCRIPT} == 1 ]]; then + # Do something in case the substitution is empty. + true + # A script fragment substituted in from the `release` rule. + @@SCRIPT@@ + # End script. +fi + +if [[ ! -z "${COPY}" ]]; then + run mkdir -p "${COPY}" + # We use `--no-preserve=mode` because bazel creates files + # with mode 0444. + run cp --no-preserve=mode -t "${COPY}" "${FILES[@]}" +fi -run ${GH} release "${REPO[@]}" create \ - --target="${BRANCH}" "${RELEASE_TAG}" \ - "${DRAFT[@]}" \ - "${PRERELEASE[@]}" \ - "${TITLE[@]}" \ - "${GENERATE_NOTES[@]}" \ - "${NOTES[@]}" \ - "${ARTIFACTS[@]}" +if [[ ${RELEASE} == 1 ]]; then + run ${GH} release "${REPO[@]}" create \ + --target="${BRANCH}" "${RELEASE_TAG}" \ + "${DRAFT[@]}" \ + "${PRERELEASE[@]}" \ + "${TITLE[@]}" \ + "${GENERATE_NOTES[@]}" \ + "${NOTES[@]}" \ + "${ARTIFACTS[@]}" +fi