Skip to content

Commit

Permalink
Add reusable action for doing Maven release
Browse files Browse the repository at this point in the history
  • Loading branch information
markpatton committed Dec 14, 2023
1 parent 18dec18 commit 483e6b2
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions .github/actions/maven-release/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Release Maven module
description: |
Releases a Maven module and waits for it to appear in Sonatype.
inputs:
repodir:
description: 'Directory of repository to release'
required: false
default: '.'

runs:
using: composite
steps:
- name: Get the artifact from POM
shell: bash
working-directory: ${{ inputs.repodir }}
run: |
echo "ARTIFACT=`mvn help:evaluate -Dexpression=project.artifactId -q -DforceStdout`" >> $GITHUB_ENV
# 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 Maven module and push to Sonatype
shell: bash
working-directory: ${{ inputs.repodir }}
run: |
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
- name: Wait for Sonatype artifact
shell: bash
run: |
echo "Waiting for $ARTIFACT $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 "$ARTIFACT $RELEASE has been released."

0 comments on commit 483e6b2

Please sign in to comment.