Skip to content

Commit

Permalink
ci: add Maven standard workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
poikilotherm committed Feb 29, 2024
1 parent 21c9a9d commit c509037
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 0 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/maven-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Release to Maven Central Repository
on:
push:
tags:
- '*'
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Java
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'adopt'
- name: Cache Maven packages
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2

- name: Build, test, verify
run: mvn -B verify
- name: Check POM metadata for release
run: mvn pomchecker:check-maven-central

# Running setup-java again overwrites the settings.xml - IT'S MANDATORY TO DO THIS SECOND SETUP!!!
- name: Set up Maven Central Repository
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'adopt'
server-id: ossrh
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
gpg-private-key: ${{ secrets.DATAVERSEBOT_GPG_KEY }}
gpg-passphrase: MAVEN_GPG_PASSPHRASE
- name: Sign + Publish release
run: mvn -Prelease deploy -DskipAnalysis -DskipUT -DskipIT
env:
MAVEN_USERNAME: ${{ secrets.DATAVERSEBOT_SONATYPE_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.DATAVERSEBOT_SONATYPE_TOKEN }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.DATAVERSEBOT_GPG_PASSWORD }}
37 changes: 37 additions & 0 deletions .github/workflows/maven-snapshot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Snapshot to Maven Central Repository
on:
push:
branches:
- main
- modernize
jobs:
publish:
runs-on: ubuntu-latest
if: ${{ !contains(github.event.head_commit.message, '[maven-release-plugin]') }}
strategy:
matrix:
java: [11]
steps:
- uses: actions/checkout@v4
- name: Set up Maven Central Repository
uses: actions/setup-java@v3
with:
java-version: ${{ matrix.java }}
distribution: 'adopt'
server-id: ossrh
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
- name: Cache Maven packages
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Build, test, verify and publish snapshot
run: mvn -B verify -Djdk.version=${{ matrix.java }}
- name: Publish snapshot
if: ${{ matrix.java == '11' }}
run: mvn deploy -DskipUT -DskipIT -Djdk.version=${{ matrix.java }}
env:
MAVEN_USERNAME: ${{ secrets.DATAVERSEBOT_SONATYPE_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.DATAVERSEBOT_SONATYPE_TOKEN }}
37 changes: 37 additions & 0 deletions .github/workflows/maven-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Build
on:
push:
branches:
- main
- modernize
pull_request:
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: 11
distribution: 'adopt'
- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Maven packages
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Build, test, analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: mvn -B -Pcoverage verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar

0 comments on commit c509037

Please sign in to comment.