|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -e |
| 4 | + |
| 5 | +: ${GCLOUD_LOCATION:=us-central1} |
| 6 | +: ${GCLOUD_RPM_REPO:=rpms} |
| 7 | +: ${GCLOUD_DEB_REPO:=debs} |
| 8 | + |
| 9 | +PACKAGE="${1}" |
| 10 | +VERSION="${2}" |
| 11 | +RELEASE="1" |
| 12 | +EPOCH="0" |
| 13 | +GORELEASER_PHASE=${GORELEASER_PHASE:-release} |
| 14 | + |
| 15 | +echo "Package: ${PACKAGE}" |
| 16 | +echo "Version: ${VERSION}" |
| 17 | + |
| 18 | +check_package() { |
| 19 | + local EXITCODE=0 |
| 20 | + local REPO="${1}" |
| 21 | + local VER="${2}" |
| 22 | + if [ ! -f /tmp/version-deleted.stamp ]; then |
| 23 | + gcloud artifacts versions list \ |
| 24 | + --repository "${REPO}" \ |
| 25 | + --location "${GCLOUD_LOCATION}" \ |
| 26 | + --package "${PACKAGE}" \ |
| 27 | + --filter "VERSION:${VER}" \ |
| 28 | + --format json 2> /dev/null \ |
| 29 | + | jq -re '.[].name?' >/dev/null 2>&1 \ |
| 30 | + || EXITCODE=$? |
| 31 | + if [[ "${EXITCODE}" -eq 0 ]]; then |
| 32 | + echo "Package version already exists. Removing it..." |
| 33 | + gcloud artifacts versions delete \ |
| 34 | + --quiet "${VER}" \ |
| 35 | + --package "${PACKAGE}" \ |
| 36 | + --repository "${REPO}" \ |
| 37 | + --location "${GCLOUD_LOCATION}" |
| 38 | + touch /tmp/version-deleted.stamp |
| 39 | + fi |
| 40 | + fi |
| 41 | +} |
| 42 | + |
| 43 | +if [[ ${GORELEASER_PHASE} != "publish" ]]; then |
| 44 | + echo "Skipping artifact import; GORELEASER_PHASE is not 'publish'" |
| 45 | + exit 0; |
| 46 | +fi |
| 47 | + |
| 48 | +check_package "${GCLOUD_RPM_REPO}" "${EPOCH}:${VERSION}-${RELEASE}" |
| 49 | +gcloud artifacts yum import "${GCLOUD_RPM_REPO}" \ |
| 50 | + --location "${GCLOUD_LOCATION}" \ |
| 51 | + --gcs-source "gs://artifacts-outgoing/${PACKAGE}/rpm/${VERSION}/*" |
| 52 | + |
| 53 | +check_package ${GCLOUD_DEB_REPO} "${VERSION}-${RELEASE}"} |
| 54 | +gcloud artifacts apt import "${GCLOUD_DEB_REPO}" \ |
| 55 | + --location "${GCLOUD_LOCATION}" \ |
| 56 | + --gcs-source "gs://artifacts-outgoing/${PACKAGE}/deb/${VERSION}/*" |
0 commit comments