Skip to content

Commit

Permalink
MON-3173: Remove INTERACTIVE mode from hack/generate-versions.sh to s…
Browse files Browse the repository at this point in the history
…implify.

Make hack/generate-versions.sh do nothing on PR that are not against the main branch as the components versions are only updated on the main branch (on release-xx branches, components kepp their versions when fixed)

Add a 'make check-versions' target to run the versions check. CI jobs will be updated to use this.
  • Loading branch information
machine424 committed May 22, 2023
1 parent d0dad7c commit ceed7ee
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
5 changes: 5 additions & 0 deletions Makefile
Expand Up @@ -151,6 +151,11 @@ jsonnet/crds/alertrelabelconfigs-custom-resource-definition.json: vendor/github.
versions: $(GOJSONTOYAML_BIN)
./hack/generate-versions.sh

.PHONY: check-versions
check-versions: VERSION_FILE=jsonnet/versions.yaml
check-versions:
export VERSION_FILE=$(VERSION_FILE) && $(MAKE) versions && git diff --exit-code -- ${VERSION_FILE}

.PHONY: docs
docs: $(EMBEDMD_BIN) $(DOCGEN_BIN) Documentation/telemetry/telemeter_query
$(EMBEDMD_BIN) -w `find Documentation -name "*.md"`
Expand Down
28 changes: 10 additions & 18 deletions hack/generate-versions.sh
Expand Up @@ -15,20 +15,20 @@ TMP_BIN="$(pwd)/tmp/bin"
# Ensure that we use the binaries from the versions defined in hack/tools/go.mod.
PATH="${TMP_BIN}:${PATH}"

MAIN_BRANCH="master"

# Set default variable values
: "${VERSION_FILE:=jsonnet/versions.yaml}"
: "${INTERACTIVE:=true}"
# PULL_BASE_REF will also be set by CI
: "${PULL_BASE_REF:=master}"

version_from_remote() {
curl --retry 5 --silent --fail "https://raw.githubusercontent.com/${1}/master/VERSION"
}
if [ "$PULL_BASE_REF" != "$MAIN_BRANCH" ]; then
echo >&2 "Components versions are only updated on '${MAIN_BRANCH}' branch for now. Nothing to do against '${PULL_BASE_REF}'."
exit 0
fi

# Fallback mechanism when VERSION file is empty or not found
version_from_user() {
ver=""
echo >&2 -n "Cannot determine version of ${1}. Please provide version manually (without alphabetical prefixes) and press ENTER: "
read -r ver
echo "$ver"
version_from_remote() {
curl --retry 5 --silent --fail "https://raw.githubusercontent.com/${1}/${MAIN_BRANCH}/VERSION"
}

CONTENT="$(gojsontoyaml -yamltojson <"${VERSION_FILE}")"
Expand All @@ -42,14 +42,6 @@ for c in $COMPONENTS; do
REMOTE="$(version_from_remote "$SLUG")"
REMOTE="${REMOTE#v}"

if [ "$REMOTE" = "" ] && [ "$INTERACTIVE" != "true" ]; then
REMOTE="$LOCAL"
fi

if [ "$REMOTE" = "" ] && [ "$INTERACTIVE" = "true" ]; then
REMOTE="$(version_from_user "${c}")"
fi

if [ "$REMOTE" != "$LOCAL" ]; then
echo >&2 "Version upgrade of ${c} from '${LOCAL}' to '${REMOTE}'"
CONTENT=$(echo "$CONTENT" | jq --arg "COMPONENT" "${c}" --arg "VERSION" "${REMOTE}" '.versions[$COMPONENT] = $VERSION')
Expand Down

0 comments on commit ceed7ee

Please sign in to comment.