4
0

package-repo-import.sh 1.5 KB

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