@@ -382,18 +382,42 @@ if [[ -z $TRAVIS ]] || [[ $ROR_TASK == "release_es6xx" ]]; then
382382 release_ror_plugins " ci/supported-es-versions/es6x.txt"
383383fi
384384
385- if [[ $ROR_TASK == " publish_maven_artifacts" ]] && [[ $TRAVIS_BRANCH == " master" ]]; then
385+ check_maven_artifacts_exist () {
386+ local CURRENT_VERSION=" $1 "
387+
388+ local ARTIFACT_URL=" https://oss.sonatype.org/service/local/repositories/releases/content/tech/beshu/ror/audit_3/$CURRENT_VERSION /"
389+ echo " >>> Checking if Maven artifacts already exist at: $ARTIFACT_URL "
390+
391+ local MVN_STATUS=$( curl -L --write-out ' %{http_code}' --silent --output /dev/null " $ARTIFACT_URL " || echo " 000" )
392+
393+ if [[ $MVN_STATUS == " 404" ]]; then
394+ echo " >>> Maven artifacts not found"
395+ return 1
396+ elif [[ $MVN_STATUS == " 200" ]]; then
397+ echo " >>> Maven artifacts for version $CURRENT_VERSION already exist."
398+ return 0
399+ else
400+ echo " >>> ERROR: Unexpected HTTP status $MVN_STATUS when checking Maven repository"
401+ echo " >>> Cannot determine if artifacts exist, failing to avoid potential issues"
402+ exit 1
403+ fi
404+ }
386405
406+ if [[ $ROR_TASK == " publish_maven_artifacts" ]] && [[ $TRAVIS_BRANCH == " master" ]]; then
387407 # .travis/secret.pgp is downloaded via Azure secret files, see azure-pipelines.yml
388-
389408 CURRENT_PLUGIN_VER=$( awk -F= ' $1=="pluginVersion" {print $2}' gradle.properties)
390409 PUBLISHED_PLUGIN_VER=$( awk -F= ' $1=="publishedPluginVersion" {print $2}' gradle.properties)
391410
392411 if [[ $CURRENT_PLUGIN_VER == $PUBLISHED_PLUGIN_VER ]]; then
393- echo " >>> Publishing audit module artifacts to sonatype repo"
394- ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository
412+ if check_maven_artifacts_exist " $CURRENT_PLUGIN_VER " ; then
413+ echo " >>> Skipping publishing audit module artifacts"
414+ else
415+ echo " >>> Publishing audit module artifacts to sonatype repo"
416+ ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository
417+ fi
395418 else
396- echo " >>> Skipping publishing audit module artifacts"
419+ echo " >>> Version mismatch: current=$CURRENT_PLUGIN_VER , published=$PUBLISHED_PLUGIN_VER "
420+ echo " >>> Skipping publishing audit module artifacts."
397421 fi
398422fi
399423
0 commit comments