diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index b8a08773..79544e4e 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -28,9 +28,20 @@ jobs: - name: Install dependencies run: mvn clean install -Dgpg.skip + + - name: Determine release list + run: | + chmod +x ./version_script.sh + ./version_script.sh - name: Deploy and Release artifact - run: mvn clean deploy -Dgpg.keyname=${{ secrets.MAVEN_GPG_KEYNAME }} -pl qanary_commons,qanary_pipeline-template,qanary_component-template,qanary_component-parent + run: | + if [ -z ${{ env.ARTIFACTS_TO_BE_RELEASED}} ]; then + echo "No artifacts to be released." + else + echo "Releasing artifacts: ${{ env.ARTIFACTS_TO_BE_RELEASED }}" + mvn clean deploy -Dgpg.keyname=${{ secrets.MAVEN_GPG_KEYNAME }} -pl ${{ env.ARTIFACTS_TO_BE_RELEASED }} + fi env: MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} MAVEN_CENTRAL_TOKEN: ${{ secrets.OSSRH_PASSWORD }} diff --git a/service_config/version_check.sh b/service_config/version_check.sh new file mode 100755 index 00000000..28688871 --- /dev/null +++ b/service_config/version_check.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +GROUP_ID="eu.wdaqua.qanary" +GROUP_PATH=$(echo "$GROUP_ID" | tr '.' '/') + +artifacts=(qanary_commons qanary_pipeline-template qanary_component-template qanary_component-parent) +artifacts_to_be_released=() + +for artifact in "${artifacts[@]}"; do + echo "Checking version in: $artifact" + while read -r file; do + echo "Found pom.xml in: $file" + ARTIFACT_ID=$(xmllint --xpath "/*[local-name()='project']/*[local-name()='artifactId']/text()" "$file") + VERSION=$(xmllint --xpath "/*[local-name()='project']/*[local-name()='version']/text()" "$file") + echo "Artifact ID: $ARTIFACT_ID, Version: $VERSION" + URL="https://repo1.maven.org/maven2/$GROUP_PATH/$ARTIFACT_ID/$VERSION/$ARTIFACT_ID-$VERSION.pom" + HTTP_STATUS=$(curl --head --silent --output /dev/null --write-out "%{http_code}" "$URL") + # Check the HTTP status code + if [ "$HTTP_STATUS" -eq 200 ]; then + echo "Artifact $ARTIFACT_ID version $VERSION exists in Maven Central." + else + echo "Artifact $ARTIFACT_ID version $VERSION does not exist in Maven Central." + artifacts_to_be_released+=("$artifact") + fi + done < <(find "../$artifact" -name "pom.xml") +done + +# Join the array elements into a string with a comma as delimiter +ARTIFACTS_TO_BE_RELEASED_STR=$(IFS=","; echo "${artifacts_to_be_released[*]}") +echo "Final list of artifacts to be released: ${ARTIFACTS_TO_BE_RELEASED_STR[@]}" +# Use GitHub Actions command to set an environment variable +echo "ARTIFACTS_TO_BE_RELEASED=$ARTIFACTS_TO_BE_RELEASED_STR" >> $GITHUB_ENV \ No newline at end of file