From a7f06a3dbf7c0d3394d356b490e9d490909a14df Mon Sep 17 00:00:00 2001 From: Dennis Schiese Date: Wed, 21 Aug 2024 08:45:50 +0200 Subject: [PATCH 1/4] Added script to determine releasable artifacts --- .github/workflows/maven.yml | 13 +++++++++++- .github/workflows/version_check.sh | 33 ++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100755 .github/workflows/version_check.sh diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index b8a08773..876969c3 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: Parse the modules + run: | + # Read the modules from the environment variable + IFS=',' read -r -a MODULES_ARRAY <<< "${{ env.ARTIFACTS_TO_BE_RELEASED }}" + echo "Modules: ${MODULES_ARRAY[@]}" - 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: mvn clean deploy -Dgpg.keyname=${{ secrets.MAVEN_GPG_KEYNAME }} -pl ${{ env.ARTIFACTS_TO_BE_RELEASED }} env: MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} MAVEN_CENTRAL_TOKEN: ${{ secrets.OSSRH_PASSWORD }} diff --git a/.github/workflows/version_check.sh b/.github/workflows/version_check.sh new file mode 100755 index 00000000..c5942de7 --- /dev/null +++ b/.github/workflows/version_check.sh @@ -0,0 +1,33 @@ +#!/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 + +echo "Final list of artifacts to be released: ${artifacts_to_be_released[@]}" +# Join the array elements into a string with a space as delimiter +ARTIFACTS_TO_BE_RELEASED_STR=$(IFS=" "; echo "${artifacts_to_be_released[*]}") + +# 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 From c36b40a5bc9633eedc91d77e543b1196276f5ce0 Mon Sep 17 00:00:00 2001 From: Dennis Schiese Date: Wed, 21 Aug 2024 09:12:28 +0200 Subject: [PATCH 2/4] Adjustments --- .github/workflows/maven.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 876969c3..79544e4e 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -33,15 +33,15 @@ jobs: run: | chmod +x ./version_script.sh ./version_script.sh - - - name: Parse the modules - run: | - # Read the modules from the environment variable - IFS=',' read -r -a MODULES_ARRAY <<< "${{ env.ARTIFACTS_TO_BE_RELEASED }}" - echo "Modules: ${MODULES_ARRAY[@]}" - name: Deploy and Release artifact - run: mvn clean deploy -Dgpg.keyname=${{ secrets.MAVEN_GPG_KEYNAME }} -pl ${{ env.ARTIFACTS_TO_BE_RELEASED }} + 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 }} From aa124eff74130c6f0de6bcc87d13fe3490eca2ac Mon Sep 17 00:00:00 2001 From: Dennis Schiese Date: Wed, 21 Aug 2024 09:12:52 +0200 Subject: [PATCH 3/4] Adjustments --- service_config/version_check.sh | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 service_config/version_check.sh 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 From 9811d6eb5cb0702d582fa16adb9e2d1fc0e916cb Mon Sep 17 00:00:00 2001 From: Dennis Schiese Date: Wed, 21 Aug 2024 09:13:43 +0200 Subject: [PATCH 4/4] Removed version_check.sh --- .github/workflows/version_check.sh | 33 ------------------------------ 1 file changed, 33 deletions(-) delete mode 100755 .github/workflows/version_check.sh diff --git a/.github/workflows/version_check.sh b/.github/workflows/version_check.sh deleted file mode 100755 index c5942de7..00000000 --- a/.github/workflows/version_check.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/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 - -echo "Final list of artifacts to be released: ${artifacts_to_be_released[@]}" -# Join the array elements into a string with a space as delimiter -ARTIFACTS_TO_BE_RELEASED_STR=$(IFS=" "; echo "${artifacts_to_be_released[*]}") - -# 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