From 5fb9e8f708d039623159670254ce186421789427 Mon Sep 17 00:00:00 2001 From: Mark Patton Date: Tue, 12 Dec 2023 08:44:32 -0500 Subject: [PATCH] Split out snapshot workflow from release workflow and make them reusable --- .github/workflows/release.yml | 137 ++++++++++++++++++--------------- .github/workflows/snapshot.yml | 46 +++++++++++ 2 files changed, 122 insertions(+), 61 deletions(-) create mode 100644 .github/workflows/snapshot.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 580c728c..23d46939 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,4 +1,4 @@ -name: "Publish: manual full release OR automatic snapshot" +name: "Publish: manual full release" on: workflow_dispatch: @@ -9,9 +9,16 @@ on: nextversion: description: 'Next dev version' required: true - push: - branches: - - 'main' + workflow_call: + inputs: + releaseversion: + description: 'Release version' + required: true + type: string + nextversion: + description: 'Next dev version' + required: true + type: string jobs: setup: @@ -19,26 +26,6 @@ jobs: outputs: # Output project version from the POM to conditionally run dependent steps project-version: ${{ steps.project_version.outputs.version }} - steps: - - name: Checkout latest code - uses: actions/checkout@v3 - - - name: Setup Java & Maven - uses: actions/setup-java@v3 - with: - java-version: 17 - distribution: 'temurin' - cache: 'maven' - - - name: Get project version from POM - id: project_version - run: echo "VERSION=`mvn help:evaluate -Dexpression=project.version -q -DforceStdout`" >> $GITHUB_OUTPUT - - # Run only if project POM has version ending in "-SNAPSHOT" - snapshot: - needs: setup - if: github.event_name == 'push' && endsWith(needs.setup.outputs.project-version, '-SNAPSHOT') - runs-on: ubuntu-latest steps: - name: Checkout latest code uses: actions/checkout@v3 @@ -55,64 +42,92 @@ jobs: gpg-private-key: ${{ secrets.MAVEN_GPG_KEY }} gpg-passphrase: MAVEN_GPG_PASSPHRASE - - name: Publish SNAPSHOT - run: mvn -B --no-transfer-progress clean deploy - env: - MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} - MAVEN_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} - MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }} + - name: Get the artifact from POM + id: project_version + run: | + echo "ARTIFACT=`mvn help:evaluate -Dexpression=project.artifactId -q -DforceStdout`" >> $GITHUB_OUTPUT - # Run for manual trigger (workflow dispatch), since you'll have release and next dev versions specified - # All commits will have a -SNAPSHOT project version anyway, since the releases will be handled here release: needs: setup - if: github.event_name == 'workflow_dispatch' runs-on: ubuntu-latest env: RELEASE: ${{ inputs.releaseversion }} NEXT: ${{ inputs.nextversion }} steps: - - name: Checkout latest code - uses: actions/checkout@v3 - - name: Config git user run: | git config user.name ${{ github.actor }} git config user.email "${{ github.actor }}@users.noreply.github.com" - - name: Setup Java & Maven - uses: actions/setup-java@v3 - with: - java-version: 17 - distribution: 'temurin' - cache: 'maven' - server-id: ossrh - server-username: MAVEN_USERNAME - server-password: MAVEN_PASSWORD - gpg-private-key: ${{ secrets.MAVEN_GPG_KEY }} - gpg-passphrase: MAVEN_GPG_PASSPHRASE - # ============================================================================= - # Start the release - # ============================================================================= - - name: Release main POM + - name: Set the release version, commit the change, and tag it + run: | + mvn versions:set -B -ntp -DnewVersion=$RELEASE + git commit -am "Update version to $RELEASE" + git tag $RELEASE + + # Build and deploy to sonatype if the release does not already exist. + # Attempt to handle case of Sonatype failing to close the repository, but still succeeding + - name: Release Java modules + working-directory: combined run: | - mvn -B -U -V -ntp release:prepare -DreleaseVersion=$RELEASE -Dtag=$RELEASE -DdevelopmentVersion=$NEXT -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn - mvn -B -U -V -ntp release:perform -P release -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn + goal="deploy" + + if curl -f -s https://oss.sonatype.org/service/local/repositories/releases/content/org/eclipse/pass/$ARTIFACT/$RELEASE/ > /dev/null; then + echo "Release $RELEASE already exists" + goal="install" + fi + + mvn -B -U -V -ntp -P release -DstagingProgressTimeoutMinutes=15 clean $goal | tee release.log + code=${PIPESTATUS[0]} + + marker1="Remote staging repositories are being released" + marker2="Failed to execute goal org.sonatype.plugins:nexus-staging-maven-plugin" + + if [ "$code" -ne "0" ]; then + if grep -q "$marker1" release.log && grep -q "$marker2" release.log; then + echo "Failed cleaning up after pushing to Sonatype, but it may have succeeded anyway." + else + exit "$code" + fi + fi env: MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} MAVEN_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }} - - name: Build and publish new dev version - run: mvn -B -U -V -ntp deploy -P release + - name: Wait for Sonatype artifacts + run: | + echo "Waiting for artifacts of $RELEASE to be released." + + counter=0 + until curl -f -s https://oss.sonatype.org/service/local/repositories/releases/content/org/eclipse/pass/$ARTIFACT/$RELEASE/ > /dev/null + do + sleep 60 + echo "." + counter=$((counter+1)) + + if [ "$counter" -gt 20 ]; then + echo "Timed out waiting for release" + exit 1 + fi + done + echo "Artifacts for $RELEASE have been released." + + - name: Set the next dev version and commit the change + run: | + mvn versions:set -B -ntp -DnewVersion=$NEXT + git commit -am "Update version to $NEXT" + + - name: Release dev Java modules + working-directory: combined + run: | + mvn -B -V -ntp clean deploy -DskipTests -DskipITs env: MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} MAVEN_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }} - - name: Push release plugin commits - if: github.ref_type == 'branch' && github.ref_protected == false - run: git push origin ${{ github.ref_name }} - - - name: Push new release tag GH - run: git push origin --tags + - name: Push the commits and tags + run: | + git push origin + git push origin --tags diff --git a/.github/workflows/snapshot.yml b/.github/workflows/snapshot.yml new file mode 100644 index 00000000..acbb3a38 --- /dev/null +++ b/.github/workflows/snapshot.yml @@ -0,0 +1,46 @@ +name: "Publish: manual OR automatic snapshot" + +on: + workflow_call: + push: + branches: + - 'main' + +jobs: + setup: + runs-on: ubuntu-latest + outputs: + # Output project version from the POM to conditionally run dependent steps + project-version: ${{ steps.project_version.outputs.version }} + steps: + - name: Checkout latest code + uses: actions/checkout@v3 + + - name: Setup Java & Maven + uses: actions/setup-java@v3 + with: + java-version: 17 + distribution: 'temurin' + cache: 'maven' + server-id: ossrh + server-username: MAVEN_USERNAME + server-password: MAVEN_PASSWORD + gpg-private-key: ${{ secrets.MAVEN_GPG_KEY }} + gpg-passphrase: MAVEN_GPG_PASSPHRASE + + - name: Get project version from POM + id: project_version + run: echo "VERSION=`mvn help:evaluate -Dexpression=project.version -q -DforceStdout`" >> $GITHUB_OUTPUT + + # Run only if project POM has version ending in "-SNAPSHOT" + snapshot: + needs: setup + if: endsWith(needs.setup.outputs.project-version, '-SNAPSHOT') + runs-on: ubuntu-latest + steps: + - name: Publish SNAPSHOT + run: mvn -B -ntp clean deploy + env: + MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} + MAVEN_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} + MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}