Deploy to Maven Central #1140
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This workflow will build a Java project with Maven and deploy snapshot | |
# artifacts to Maven Central | |
# | |
# This job is triggered by a completed run of the "CI Coherence Spring" action. | |
# The "build" job only runs if the "CI Coherence Spring" action completed successfully. | |
# The deployed artifacts will be built from the same commit that the "CI Coherence Spring" action used. | |
# | |
name: Deploy to Maven Central | |
on: | |
workflow_run: | |
workflows: [CI Coherence Spring] | |
branches: | |
- main | |
- '[1-9]+.x' | |
types: | |
- completed | |
workflow_dispatch: | |
jobs: | |
build: | |
if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }} | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set up JDK 17 | |
uses: actions/[email protected] | |
with: | |
distribution: 'adopt' | |
java-version: '17' | |
- name: Cache Maven packages | |
uses: actions/cache@v4 | |
with: | |
path: ~/.m2/repository | |
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} | |
restore-keys: | | |
${{ runner.os }}-m2- | |
- name: Build and Deploy | |
if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
env: | |
GIT_COMMIT: ${{github.event.workflow_run.head_commit.id}} | |
HEAD_BRANCH: ${{github.event.workflow_run.head_branch}} | |
MAVEN_GITHUB_TOKEN: "${{secrets.GITHUB_TOKEN}}" | |
MAVEN_SONATYPE_USERNAME: "${{secrets.MAVEN_SONATYPE_USERNAME}}" | |
MAVEN_SONATYPE_TOKEN: "${{secrets.MAVEN_SONATYPE_TOKEN}}" | |
run: | | |
echo "Checking out branch ${HEAD_BRANCH} commit ${GIT_COMMIT}" | |
git checkout "${GIT_COMMIT}" | |
git config --global user.email "[email protected]" | |
git config --global user.name "GitHub Action" | |
./mvnw clean install --no-transfer-progress -B --settings .mvn/settings.xml -DskipTests=true | |
./mvnw deploy --no-transfer-progress -B --settings .mvn/settings.xml | |
- name: Build and Deploy | |
if: ${{ github.event_name == 'workflow_dispatch' }} | |
env: | |
MAVEN_GITHUB_TOKEN: "${{secrets.GITHUB_TOKEN}}" | |
MAVEN_SONATYPE_USERNAME: "${{secrets.MAVEN_SONATYPE_USERNAME}}" | |
MAVEN_SONATYPE_TOKEN: "${{secrets.MAVEN_SONATYPE_TOKEN}}" | |
run: | | |
git config --global user.email "[email protected]" | |
git config --global user.name "GitHub Action" | |
./mvnw clean install --no-transfer-progress -B --settings .mvn/settings.xml -DskipTests=true | |
./mvnw deploy --no-transfer-progress -B --settings .mvn/settings.xml -DskipTests=true | |
- name: Clean Maven cache | |
run: | | |
find ~/.m2/repository -type d -name '*SNAPSHOT' | xargs rm -fr |