Skip to content

feat(build): publish to OSSRH Snapshots and MavenCentral from GHA (#72) #2

feat(build): publish to OSSRH Snapshots and MavenCentral from GHA (#72)

feat(build): publish to OSSRH Snapshots and MavenCentral from GHA (#72) #2

name: "Publish Snapshot Build"
on:
workflow_dispatch:
workflow_call:
jobs:
secrets-presence:
name: "Check for required credentials"
runs-on: ubuntu-latest
outputs:
HAS_OSSRH: ${{ steps.secret-presence.outputs.HAS_OSSRH }}
steps:
- name: Check whether secrets exist
id: secret-presence
run: |
[ ! -z "${{ secrets.ORG_GPG_PASSPHRASE }}" ] &&
[ ! -z "${{ secrets.ORG_GPG_PRIVATE_KEY }}" ] &&
[ ! -z "${{ secrets.ORG_OSSRH_USERNAME }}" ] && echo "HAS_OSSRH=true" >> $GITHUB_OUTPUT
exit 0
Publish-Snapshot:
name: "Publish artefacts to OSSRH Snapshots / MavenCentral"
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
needs: [ secrets-presence ]
if: |
needs.secrets-presence.outputs.HAS_OSSRH
steps:
# Set-Up
- uses: actions/[email protected]
# Import GPG Key
- uses: eclipse-edc/.github/.github/actions/import-gpg-key
name: "Import GPG Key"
with:
gpg-private-key: ${{ secrets.ORG_GPG_PRIVATE_KEY }}
- uses: ./.github/actions/setup-build
- name: "Publish snapshot version"
env:
OSSRH_PASSWORD: ${{ secrets.ORG_OSSRH_PASSWORD }}
OSSRH_USER: ${{ secrets.ORG_OSSRH_USERNAME }}
run: |-
VERSION=$(./gradlew properties -q | grep "version:" | awk '{print $2}')
if [[ $VERSION != *-SNAPSHOT ]]
then
echo "::warning file=gradle.properties::$VERSION is not a snapshot version - will not publish!"
exit 0
fi
echo "Publishing Version $VERSION to Sonatype"
./gradlew publishToSonatype --no-parallel -Pversion=$VERSION -Psigning.gnupg.executable=gpg -Psigning.gnupg.passphrase="${{ secrets.ORG_GPG_PASSPHRASE }}"