|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Looks up the version of a dependent GAR artifact from |
| 4 | +# either the commit SHA or helm Chart.yaml version. |
| 5 | +# There are no inputs. |
| 6 | +# All echos happen to STDERR. |
| 7 | +# Result is the found version which can be captured with STDOUT. |
| 8 | + |
| 9 | +set -o pipefail |
| 10 | +set -eu |
| 11 | + |
| 12 | +version="" |
| 13 | +chart_ver=$(yq ".version" helm/fiftyone-teams-app/Chart.yaml) |
| 14 | + |
| 15 | +# Note: Sending echos to STDERR so that users can easily use |
| 16 | +# the STDOUT for other, more interesting automations. |
| 17 | +if [[ ${TEAMS_DEPLOYER_BRANCH} == "main" ]]; then |
| 18 | + # Get the most recent <x.x.x> version from GAR |
| 19 | + pattern="${chart_ver}" |
| 20 | + echo "Look for version \"${pattern}\" in us-central1-docker.pkg.dev/computer-vision-team/helm-internal/internal-env" >&2 |
| 21 | + version=$(gcloud artifacts docker images list \ |
| 22 | + us-central1-docker.pkg.dev/computer-vision-team/helm-internal/internal-env \ |
| 23 | + --include-tags \ |
| 24 | + --format="value(tags)" \ |
| 25 | + --filter="tags:${pattern}" \ |
| 26 | + --sort-by createTime | grep -E '[0-9]+\.[0-9]+\.[0-9]+$$' | tail -1) |
| 27 | +else |
| 28 | + # Look for the .*-<sha> in GAR. |
| 29 | + # Handles both x.x.x-sha-<sha> and x.x.x-rc-<sha> formats |
| 30 | + |
| 31 | + sha=$(git rev-parse --short HEAD) |
| 32 | + |
| 33 | + echo "Look for version \"${sha}\" in us-central1-docker.pkg.dev/computer-vision-team/helm-internal/internal-env" >&2 |
| 34 | + |
| 35 | + version=$(gcloud artifacts docker images list \ |
| 36 | + us-central1-docker.pkg.dev/computer-vision-team/helm-internal/internal-env \ |
| 37 | + --include-tags \ |
| 38 | + --filter="tags ~ .*-${sha}\$" \ |
| 39 | + --format yaml \ |
| 40 | + --limit 1 | |
| 41 | + yq ".tags[0]") |
| 42 | +fi |
| 43 | + |
| 44 | +if [[ -z ${version} ]] || [[ ! ${version} =~ [0-9]+\.[0-9]+\.[0-9]+.* ]]; then |
| 45 | + echo "[ERROR] No version found in the helm chart registry... Failing build." >&2 |
| 46 | + echo " Please submit a PR to fiftyone-teams-app-deploy if this is a " >&2 |
| 47 | + echo " non-release branch so that your chart gets published." >&2 |
| 48 | + echo " If this is a release branch, please view the " >&2 |
| 49 | + echo " 'Release Pre-release charts' action in fiftyone-teams-app-deploy" >&2 |
| 50 | + exit 1 |
| 51 | +fi |
| 52 | + |
| 53 | +echo "Found internal-env chart version ${version}" >&2 |
| 54 | +# Let caller do with it what they'd like |
| 55 | +echo "${version}" |
0 commit comments