Skip to content

Commit

Permalink
Make --version a standalone flag (knative#396)
Browse files Browse the repository at this point in the history
It can now be used to arbitraly tag any release. To publish a release to GitHub though, --version, --publish and --branch must specified (current behavior).

Bonus:
* rename the BRANCH_RELEASE variable for clarity.
* clearly log if release is published to GitHub and if it's being built from a branch.
  • Loading branch information
adrcunha authored and knative-prow-robot committed Jan 15, 2019
1 parent 3e33c90 commit cd1bb37
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
3 changes: 2 additions & 1 deletion scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ This is a helper script for Knative release scripts. To use it:
variable `TAG` will contain the release tag in the form `vYYYYMMDD-<commit_short_hash>`.
- `PUBLISH_RELEASE`: true if `--publish` was passed. In this case, the environment
variable `KO_FLAGS` will be updated with the `-L` option.
- `BRANCH_RELEASE`: true if both `--version` and `--publish-release` were passed.
- `PUBLISH_TO_GITHUB`: true if `--version`, `--branch` and `--publish-release`
were passed.

All boolean environment variables default to false for safety.

Expand Down
20 changes: 12 additions & 8 deletions scripts/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function publish_yaml() {
SKIP_TESTS=0
TAG_RELEASE=0
PUBLISH_RELEASE=0
BRANCH_RELEASE=0
PUBLISH_TO_GITHUB=0
TAG=""
RELEASE_VERSION=""
RELEASE_NOTES=""
Expand Down Expand Up @@ -251,12 +251,12 @@ function parse_flags() {
TAG="v${RELEASE_VERSION}"
fi

[[ -n "${RELEASE_VERSION}" ]] && (( PUBLISH_RELEASE )) && BRANCH_RELEASE=1
[[ -n "${RELEASE_VERSION}" && -n "${RELEASE_BRANCH}" ]] && (( PUBLISH_RELEASE )) && PUBLISH_TO_GITHUB=1

readonly SKIP_TESTS
readonly TAG_RELEASE
readonly PUBLISH_RELEASE
readonly BRANCH_RELEASE
readonly PUBLISH_TO_GITHUB
readonly TAG
readonly RELEASE_VERSION
readonly RELEASE_NOTES
Expand Down Expand Up @@ -295,13 +295,14 @@ function initialize() {
else
echo "- Release will not be published"
fi
if (( BRANCH_RELEASE )); then
echo "- Release WILL BE branched from '${RELEASE_BRANCH}'"
if (( PUBLISH_TO_GITHUB )); then
echo "- Release WILL BE published to GitHub"
fi
[[ -n "${RELEASE_BRANCH}" ]] && echo "- Release will be built from branch '${RELEASE_BRANCH}'"
[[ -n "${RELEASE_NOTES}" ]] && echo "- Release notes are generated from '${RELEASE_NOTES}'"

# Checkout specific branch, if necessary
if (( BRANCH_RELEASE )); then
if [[ -n "${RELEASE_BRANCH}" ]]; then
setup_upstream
setup_branch
git checkout upstream/${RELEASE_BRANCH} || abort "cannot checkout branch ${RELEASE_BRANCH}"
Expand All @@ -312,11 +313,13 @@ function initialize() {
# Parameters: $1 - Module name (e.g., "Knative Serving").
# $2 - YAML files to add to the release, space separated.
function branch_release() {
(( BRANCH_RELEASE )) || return 0
# TODO(adrcunha): rename this function to publish_to_github()
(( PUBLISH_TO_GITHUB )) || return 0
local title="$1 release ${TAG}"
local attachments=()
local description="$(mktemp)"
local attachments_dir="$(mktemp -d)"
local commitish=""
# Copy each YAML to a separate dir
for yaml in $2; do
cp ${yaml} ${attachments_dir}/
Expand All @@ -331,10 +334,11 @@ function branch_release() {
[[ -n "${GITHUB_TOKEN}}" ]] && repo_url="${repo_url/:\/\//:\/\/${GITHUB_TOKEN}@}"
hub_tool push ${repo_url} tag ${TAG}

[[ -n "${RELEASE_BRANCH}" ]] && commitish="--commitish=${RELEASE_BRANCH}"
hub_tool release create \
--prerelease \
${attachments[@]} \
--file=${description} \
--commitish=${RELEASE_BRANCH} \
${commitish} \
${TAG}
}
8 changes: 4 additions & 4 deletions test/unit/release-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ set -e

function mock_branch_release() {
set -e
BRANCH_RELEASE=1
PUBLISH_TO_GITHUB=1
TAG=sometag
function git() {
echo $@
Expand Down Expand Up @@ -79,11 +79,11 @@ test_function ${SUCCESS} "published to 'knative-nightly/test-infra'" initialize
test_function ${SUCCESS} "Destination GCR: foo" initialize --release-gcr foo --publish
test_function ${SUCCESS} "published to 'foo'" initialize --release-gcs foo --publish

echo ">> Testing release branching"
echo ">> Testing publishing to GitHub"

test_function ${SUCCESS} "" branch_release
test_function 129 "usage: git tag" call_function_pre BRANCH_RELEASE=1 branch_release
test_function ${FAILURE} "No such file" call_function_pre BRANCH_RELEASE=1 branch_release "K Foo" "a.yaml b.yaml"
test_function 129 "usage: git tag" call_function_pre PUBLISH_TO_GITHUB=1 branch_release
test_function ${FAILURE} "No such file" call_function_pre PUBLISH_TO_GITHUB=1 branch_release "K Foo" "a.yaml b.yaml"
test_function ${SUCCESS} "release create" mock_branch_release "K Foo" "$(mktemp) $(mktemp)"

echo ">> Testing validation tests"
Expand Down

0 comments on commit cd1bb37

Please sign in to comment.