Skip to content

Publish Snapshot

Publish Snapshot #73

name: Publish Snapshot
on:
workflow_run:
workflows: [Build Snapshot]
types:
- completed
branches:
- main
permissions:
contents: read # to fetch code (actions/checkout)
env:
LANG: 'en_US.UTF-8'
jobs:
check-version:
# only run in the official pmd/pmd-designer repo, where we have access to the secrets and not on forks
# and only run for _successful_ push workflow runs on branch "main".
if: ${{ github.repository == 'pmd/pmd-designer'
&& contains(fromJSON('["push", "workflow_dispatch", "schedule"]'), github.event.workflow_run.event)
&& github.event.workflow_run.head_branch == 'main'
&& github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
timeout-minutes: 10
defaults:
run:
shell: bash
outputs:
VERSION: ${{ steps.version.outputs.VERSION }}
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 #v5.0.0
with:
ref: main
- uses: actions/setup-java@dded0888837ed1f317902acf8a20df0ad188d165 #v5.0.0
with:
distribution: 'temurin'
java-version: '17'
cache: 'maven'
- name: Determine Version
id: version
run: |
VERSION=$(./mvnw --batch-mode --no-transfer-progress help:evaluate -Dexpression=project.version -q -DforceStdout)
echo "Determined VERSION=$VERSION"
if [[ "$VERSION" != *-SNAPSHOT ]]; then
echo "::error ::VERSION=$VERSION is not a snapshot version, aborting."
exit 1
fi
echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT"
- name: Add Job Summary
env:
WORKFLOW_RUN_DISPLAY_TITLE: ${{ github.event.workflow_run.display_title }}
WORKFLOW_RUN_NAME: ${{ github.event.workflow_run.name }}
WORKFLOW_RUN_NUMBER: ${{ github.event.workflow_run.run_number }}
WORKFLOW_RUN_HTML_URL: ${{ github.event.workflow_run.html_url }}
VERSION: ${{ steps.version.outputs.VERSION }}
BRANCH: ${{ github.event.workflow_run.head_branch }}
run: |
echo "### Run Info" >> "${GITHUB_STEP_SUMMARY}"
echo "Building Version: ${VERSION}" >> "${GITHUB_STEP_SUMMARY}"
echo "" >> "${GITHUB_STEP_SUMMARY}"
echo "Branch: ${BRANCH}" >> "${GITHUB_STEP_SUMMARY}"
echo "" >> "${GITHUB_STEP_SUMMARY}"
echo "Called by [${WORKFLOW_RUN_DISPLAY_TITLE} (${WORKFLOW_RUN_NAME} #${WORKFLOW_RUN_NUMBER})](${WORKFLOW_RUN_HTML_URL})" >> "${GITHUB_STEP_SUMMARY}"
echo "" >> "${GITHUB_STEP_SUMMARY}"
deploy-to-maven-central:
needs: check-version
# use environment maven-central, where secrets are configured for MAVEN_CENTRAL_PORTAL_*
environment:
name: maven-central
url: https://central.sonatype.com/service/rest/repository/browse/maven-snapshots/net/sourceforge/pmd/pmd-designer/
runs-on: ubuntu-latest
timeout-minutes: 20
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 #v5.0.0
with:
ref: main
- uses: actions/setup-java@dded0888837ed1f317902acf8a20df0ad188d165 #v5.0.0
with:
distribution: 'temurin'
java-version: '17'
cache: 'maven'
server-id: central
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
gpg-passphrase: MAVEN_GPG_PASSPHRASE
gpg-private-key: ${{ secrets.PMD_CI_GPG_PRIVATE_KEY }}
- name: Build and Publish
env:
MAVEN_USERNAME: ${{ secrets.MAVEN_CENTRAL_PORTAL_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PORTAL_PASSWORD }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.PMD_CI_GPG_PASSPHRASE }}
run: |
./mvnw --show-version --errors --batch-mode \
-Psign,shading \
deploy