Skip to content

Commit

Permalink
Fix the logic to find the latest release build for the given repo (kn…
Browse files Browse the repository at this point in the history
…ative#828)

* find the nearest available tag for the given branch

* fix CR issues

* add quotes for vars

* fix PR issues

* fix CR issues

* fix CR issue
  • Loading branch information
chizhg authored and knative-prow-robot committed May 30, 2019
1 parent e318113 commit fbe5f9e
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions scripts/library.sh
Original file line number Diff line number Diff line change
Expand Up @@ -475,21 +475,32 @@ function get_canonical_path() {
echo "$(cd ${path%/*} && echo $PWD/${path##*/})"
}

# Return the base url we use to build the actual knative yaml sources.
function get_knative_base_yaml_source() {
local knative_base_yaml_source="https://storage.googleapis.com/knative-nightly/@/latest"
# Returns the URL to the latest manifest for the given Knative project.
# Parameters: $1 - repository name of the given project
# $2 - name of the yaml file, without extension
function get_latest_knative_yaml_source() {
local branch_name=""
local repo_name="$1"
local yaml_name="$2"
# Get the branch name from Prow's env var, see https://github.com/kubernetes/test-infra/blob/master/prow/jobs.md.
# Otherwise, try getting the current branch from git.
(( IS_PROW )) && branch_name="${PULL_BASE_REF:-}"
[[ -z "${branch_name}" ]] && branch_name="$(git rev-parse --abbrev-ref HEAD)"
# If it's a release branch, base URL should point to a specific version.
# If it's a release branch, the yaml source URL should point to a specific version.
if [[ ${branch_name} =~ ^release-[0-9\.]+$ ]]; then
# Get the latest tag name for the current branch, which is likely formatted as v0.5.0
local tag_name="$(git describe --tags --abbrev=0)"
knative_base_yaml_source="https://storage.googleapis.com/knative-releases/@/previous/${tag_name}"
# The given repo might not have this tag, so we need to find its latest release manifest with the same major&minor version.
local major_minor="$(echo ${tag_name} | cut -d. -f1-2)"
local yaml_source_path="$(gsutil ls gs://knative-releases/${repo_name}/previous/${major_minor}.*/${yaml_name}.yaml \
| sort \
| tail -n 1 \
| cut -b6-)"
echo "https://storage.googleapis.com/${yaml_source_path}"
# If it's not a release branch, the yaml source URL should be nightly build.
else
echo "https://storage.googleapis.com/knative-nightly/${repo_name}/latest/${yaml_name}.yaml"
fi
echo "${knative_base_yaml_source}"
}

# Initializations that depend on previous functions.
Expand All @@ -499,7 +510,6 @@ readonly _TEST_INFRA_SCRIPTS_DIR="$(dirname $(get_canonical_path ${BASH_SOURCE[0
readonly REPO_NAME_FORMATTED="Knative $(capitalize ${REPO_NAME//-/})"

# Public latest nightly or release yaml files.
readonly KNATIVE_BASE_YAML_SOURCE="$(get_knative_base_yaml_source)"
readonly KNATIVE_SERVING_RELEASE="${KNATIVE_BASE_YAML_SOURCE/@/serving}/serving.yaml"
readonly KNATIVE_BUILD_RELEASE="${KNATIVE_BASE_YAML_SOURCE/@/build}/build.yaml"
readonly KNATIVE_EVENTING_RELEASE="${KNATIVE_BASE_YAML_SOURCE/@/eventing}/release.yaml"
readonly KNATIVE_SERVING_RELEASE="$(get_latest_knative_yaml_source "serving" "serving")"
readonly KNATIVE_BUILD_RELEASE="$(get_latest_knative_yaml_source "build" "build")"
readonly KNATIVE_EVENTING_RELEASE="$(get_latest_knative_yaml_source "eventing" "release")"

0 comments on commit fbe5f9e

Please sign in to comment.