From f7891d7191f4ac8096adff5aff5a3b99e58c2c0a Mon Sep 17 00:00:00 2001 From: Chaminda Divitotawela Date: Thu, 15 Aug 2024 15:38:06 +1000 Subject: [PATCH] Prevent publishing same version Workflow checks whether the configured non snapshot version has been published already to prevent re-publish same version Signed-off-by: Chaminda Divitotawela --- .github/workflows/build.yml | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ba39edce..33b04522 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -36,6 +36,37 @@ jobs: uses: actions/checkout@v4 with: submodules: recursive + # Check whether gradle.properties version has been released already + # This prevents accidently publish same version + # Only check binary for arithmetic as all published together and arithmetic is the first + - name: Check release published + run: | + # Skip if version contain SNAPSHOT + grep "^version" gradle.properties | grep -q SNAPSHOT || { + # Extract version from gradle.properties + VERSION=$(grep "^version" gradle.properties | sed 's|^version=\(.*\)$|\1|g') + echo "Query for version [$VERSION]" + RESPONSE_CODE=$(curl --head -L --silent --output /dev/null --write-out %{http_code} "$ART_URL/$VERSION") + echo "DEBUG: Response code from curl command [$RESPONSE_CODE]" + if [[ $RESPONSE_CODE == "404" ]] + then + echo "Version [$VERSION] has not yet been published" + else + if [[ $RESPONSE_CODE == "200" ]] + then + echo "ERROR: Binary arithmetic already exists for version [$VERSION]" + echo "ERROR: Blocking republishing same version to the Besu Artifactory" + echo "url $ART_URL/$VERSION" + exit 1 + else + echo "WARN: Unable to check whether version has been published previously" + echo "WARN: Failing job due to unknown status" + exit 1 + fi + fi + } + env: + ART_URL: 'https://hyperledger.jfrog.io/artifactory/besu-maven/org/hyperledger/besu/arithmetic' - name: Build run: ./build.sh - uses: actions/upload-artifact@v3.1.0