Skip to content

Commit

Permalink
refactor: extract a publish-maven-artifacts composite action (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
ndr-brt authored Aug 14, 2024
1 parent e13b5cc commit fa250d9
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 39 deletions.
57 changes: 57 additions & 0 deletions .github/actions/publish-maven-artifacts/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: "Publish Maven Artifacts"
description: "Build and publish maven artifacts to repository"

inputs:
version:
description: the version to be attached to the artifacts, if not specified, the one configured in the project will be used
required: false
ref:
description: the git ref from which the artifacts will be built and published
required: true
gpg-private-key:
description: the gpg private key used to publish
required: true
gpg-passphrase:
description: the gpg passphrase used to publish
required: true
osshr-username:
description: the OSSHR username
required: true
osshr-password:
description: the OSSHR password
required: true

runs:
using: "composite"
steps:

- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}

- uses: eclipse-edc/.github/.github/actions/setup-build@main

- uses: eclipse-edc/.github/.github/actions/import-gpg-key@main
with:
gpg-private-key: ${{ inputs.gpg-private-key }}

- if: inputs.version != null
shell: bash
run: |
sed -i 's#^version=.*#version=${{ inputs.version }}#g' $(find . -name "gradle.properties")
- name: "Publish To OSSRH/MavenCentral"
shell: bash
env:
OSSRH_USER: ${{ inputs.osshr-username }}
OSSRH_PASSWORD: ${{ inputs.osshr-password }}
run: |-
VERSION=$(grep "version" gradle.properties | awk -F= '{print $2}')
cmd=""
if [[ $VERSION != *-SNAPSHOT ]]
then
cmd="closeAndReleaseSonatypeStagingRepository";
fi
echo "Publishing Version $VERSION to Sonatype"
./gradlew publishToSonatype ${cmd} --no-parallel -Pversion=$VERSION -Psigning.gnupg.executable=gpg -Psigning.gnupg.passphrase="${{ inputs.gpg-passphrase }}"
26 changes: 5 additions & 21 deletions .github/workflows/publish-snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,10 @@ jobs:
if: |
needs.secrets-presence.outputs.HAS_OSSRH
steps:
# Set-Up
- uses: actions/checkout@v4

# Import GPG Key
- uses: eclipse-edc/.github/.github/actions/import-gpg-key@main
name: "Import GPG Key"
- uses: eclipse-edc/.github/.github/actions/publish-maven-artifacts@main
with:
ref: main
gpg-private-key: ${{ secrets.ORG_GPG_PRIVATE_KEY }}

- uses: eclipse-edc/.github/.github/actions/setup-build@main
- 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 }}"
gpg-passphrase: ${{ secrets.ORG_GPG_PASSPHRASE }}
osshr-username: ${{ secrets.ORG_OSSRH_USERNAME }}
osshr-password: ${{ secrets.ORG_OSSRH_PASSWORD }}
23 changes: 5 additions & 18 deletions .github/workflows/technology-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,14 @@ jobs:
needs: [ Determine-Version ]
if: needs.Secrets-Presence.outputs.HAS_OSSRH
steps:
- uses: actions/checkout@v4
- uses: eclipse-edc/.github/.github/actions/publish-maven-artifacts@main
with:
ref: ${{ inputs.branch }}

- uses: eclipse-edc/.github/.github/actions/setup-build@main

# Import GPG Key
- uses: eclipse-edc/.github/.github/actions/import-gpg-key@main
if: needs.Secrets-Presence.outputs.HAS_OSSRH
name: "Import GPG Key"
with:
version: ${{ needs.Determine-Version.outputs.VERSION }}
gpg-private-key: ${{ secrets.ORG_GPG_PRIVATE_KEY }}
- name: "Publish To OSSRH/MavenCentral"
if: needs.Secrets-Presence.outputs.HAS_OSSRH
env:
OSSRH_PASSWORD: ${{ secrets.ORG_OSSRH_PASSWORD }}
OSSRH_USER: ${{ secrets.ORG_OSSRH_USERNAME }}
VERSION: ${{ needs.Determine-Version.outputs.VERSION }}
run: |-
echo "Publishing Version $VERSION to Sonatype"
./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository --no-parallel -Pversion=$VERSION -Psigning.gnupg.executable=gpg -Psigning.gnupg.passphrase="${{ secrets.ORG_GPG_PASSPHRASE }}"
gpg-passphrase: ${{ secrets.ORG_GPG_PASSPHRASE }}
osshr-username: ${{ secrets.ORG_OSSRH_USERNAME }}
osshr-password: ${{ secrets.ORG_OSSRH_PASSWORD }}

Create-Tag:
needs: [ Publish-Artefacts ]
Expand Down

0 comments on commit fa250d9

Please sign in to comment.