Skip to content

Commit

Permalink
Add the capability to copy release artifacts
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
cfrantz committed Jan 30, 2023
1 parent 2d9cb67 commit 00d4c87
Showing 1 changed file with 55 additions and 14 deletions.
69 changes: 55 additions & 14 deletions release/release.template.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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 <string> : Release title"
echo " -n|--notes <string> : Release notes"
echo " -F|--notes-file <file> : Read release notes from file"
echo " --target <branch> : 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 <subdir> : 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"
Expand All @@ -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@@
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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"
Expand All @@ -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

0 comments on commit 00d4c87

Please sign in to comment.