|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +BUILD_VERSION=$(./gradlew :pi4j-plugin-grpc:properties -q | grep 'version:' | awk '{print $2}') |
| 4 | +DIST_ZIP=$(find . -name "pi4j-plugin-grpc-server-${BUILD_VERSION}.zip") |
| 5 | +SHADOW_JAR=$(find . -name "pi4j-plugin-grpc-server-${BUILD_VERSION}-all.jar") |
| 6 | + |
| 7 | +# Stop if DIST_ZIP is empty |
| 8 | +if [ -z "${DIST_ZIP}" ]; then |
| 9 | + echo "ERROR: No distribution zip not found for version ${BUILD_VERSION}" |
| 10 | + exit 1 |
| 11 | +fi |
| 12 | + |
| 13 | +# Set IS_SNAPSHOT to true if BUILD_VERSION ends with `SNAPSHOT` |
| 14 | +if [[ "${BUILD_VERSION}" == *SNAPSHOT ]]; then |
| 15 | + IS_SNAPSHOT=true |
| 16 | +else |
| 17 | + IS_SNAPSHOT=false |
| 18 | +fi |
| 19 | + |
| 20 | +# Set RELEASE_EXISTS to true if gh release list contains "v${BUILD_VERSION}" |
| 21 | +if gh release list | grep -q "v${BUILD_VERSION}"; then |
| 22 | + RELEASE_EXISTS=true |
| 23 | +else |
| 24 | + RELEASE_EXISTS=false |
| 25 | +fi |
| 26 | + |
| 27 | +# If this is a non-snapshot release and the release already exists, abort to avoid overwriting it. |
| 28 | +if [ "${IS_SNAPSHOT}" = "false" ] && [ "${RELEASE_EXISTS}" = "true" ]; then |
| 29 | + echo "ERROR: Release v${BUILD_VERSION} already exists and this is not a snapshot. Aborting to avoid overwrite." |
| 30 | + exit 1 |
| 31 | +fi |
| 32 | + |
| 33 | +# If the release doesn't exist, create it |
| 34 | +if [ "${RELEASE_EXISTS}" = "false" ]; then |
| 35 | + echo "Creating release: v${BUILD_VERSION}" |
| 36 | + |
| 37 | + if [ "${IS_SNAPSHOT}" = "true" ]; then |
| 38 | + echo "Marking release as prerelease (snapshot)" |
| 39 | + gh release create "v${BUILD_VERSION}" --title "v${BUILD_VERSION}" --notes "Automated snapshot release for version ${BUILD_VERSION}" --prerelease |
| 40 | + RC=$? |
| 41 | + else |
| 42 | + gh release create "v${BUILD_VERSION}" --title "v${BUILD_VERSION}" --notes "Release for version ${BUILD_VERSION}" |
| 43 | + RC=$? |
| 44 | + fi |
| 45 | + |
| 46 | + if [ ${RC} -ne 0 ]; then |
| 47 | + echo "ERROR: Failed to create release v${BUILD_VERSION}" |
| 48 | + exit 1 |
| 49 | + fi |
| 50 | +fi |
| 51 | + |
| 52 | +echo "Uploading ${DIST_ZIP} to v${BUILD_VERSION}" |
| 53 | +gh release upload "v${BUILD_VERSION}" "${DIST_ZIP}" "${SHADOW_JAR}" --clobber |
| 54 | +RC=$? |
| 55 | +if [ ${RC} -ne 0 ]; then |
| 56 | + echo "ERROR: Failed to upload asset to existing release v${BUILD_VERSION}" |
| 57 | + exit 1 |
| 58 | +fi |
| 59 | +echo "Asset uploaded to existing snapshot release v${BUILD_VERSION}." |
0 commit comments