|
| 1 | +name: Build and Deploy Maven Central |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - master |
| 6 | + pull_request: |
| 7 | + branches: |
| 8 | + - master |
| 9 | +env: |
| 10 | + JFROG_USER: ${{ secrets.ARTIFACTORY_AUTH_USER }} |
| 11 | + JFROG_PASS: ${{ secrets.ARTIFACTORY_AUTH_TOKEN }} |
| 12 | + SONATYPE_GPG_KEY_BASE64: ${{ secrets.SONATYPE_GPG_KEY_BASE64 }} |
| 13 | + SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} |
| 14 | + SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} |
| 15 | + SONATYPE_GPG_KEY_PASSWORD: ${{ secrets.SONATYPE_GPG_KEY_PASSWORD }} |
| 16 | + NVD_API_KEY: ${{ secrets.NVD_API_KEY }} |
| 17 | +jobs: |
| 18 | + maven-package: |
| 19 | + if: "!contains(github.event.head_commit.message, 'ci skip')" |
| 20 | + runs-on: ubuntu-24.04 |
| 21 | + steps: |
| 22 | + - uses: actions/checkout@v4 |
| 23 | + with: |
| 24 | + fetch-depth: 0 |
| 25 | + - name: Copy maven settings |
| 26 | + run: | |
| 27 | + wget https://raw.githubusercontent.com/entur/ror-maven-settings/master/.m2/settings.xml -O .github/workflows/settings.xml |
| 28 | + - uses: actions/setup-java@v4 |
| 29 | + with: |
| 30 | + java-version: 17.0.13 |
| 31 | + distribution: liberica |
| 32 | + - name: Cache Maven dependencies |
| 33 | + uses: actions/cache@v4 |
| 34 | + with: |
| 35 | + path: ~/.m2/repository |
| 36 | + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} |
| 37 | + restore-keys: | |
| 38 | + ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} |
| 39 | + ${{ runner.os }}-maven- |
| 40 | + ${{ runner.os }}- |
| 41 | +
|
| 42 | + - name: Run maven build |
| 43 | + run: mvn verify -s .github/workflows/settings.xml |
| 44 | + - name: Sonar Scan |
| 45 | + env: |
| 46 | + SONAR_TOKEN: ${{ secrets.ENTUR_SONAR_PASSWORD }} |
| 47 | + SONAR_PROJECT_NAME: ${{ github.event.repository.name }} |
| 48 | + SONAR_PROJECT_KEY: entur_${{ github.event.repository.name }} |
| 49 | + run: | |
| 50 | + mvn -Psonar -s .github/workflows/settings.xml \ |
| 51 | + sonar:sonar \ |
| 52 | + -Dsonar.projectKey=${SONAR_PROJECT_KEY} \ |
| 53 | + -Dsonar.organization=enturas-github \ |
| 54 | + -Dsonar.projectName=${SONAR_PROJECT_NAME} \ |
| 55 | + -Dsonar.host.url=https://sonarcloud.io \ |
| 56 | + -Dsonar.token=${SONAR_TOKEN} |
| 57 | + - name: Upload artifact |
| 58 | + uses: actions/upload-artifact@v4.4.3 |
| 59 | + with: |
| 60 | + path: target/*.jar |
| 61 | + deploy-maven-central: |
| 62 | + if: github.repository_owner == 'entur' && github.event_name == 'push' && github.ref == 'refs/heads/master' && !contains(github.event.head_commit.message, 'ci skip') |
| 63 | + needs: [maven-package] |
| 64 | + runs-on: ubuntu-24.04 |
| 65 | + steps: |
| 66 | + - uses: actions/checkout@v4 |
| 67 | + with: |
| 68 | + fetch-depth: 0 |
| 69 | + - name: Copy maven settings |
| 70 | + run: | |
| 71 | + wget https://raw.githubusercontent.com/entur/ror-maven-settings/master/.m2/settings.xml -O .github/workflows/settings.xml |
| 72 | + - uses: actions/setup-java@v4 |
| 73 | + with: |
| 74 | + java-version: 17.0.13 |
| 75 | + distribution: liberica |
| 76 | + - name: Cache Maven dependencies |
| 77 | + uses: actions/cache@v4 |
| 78 | + with: |
| 79 | + path: ~/.m2/repository |
| 80 | + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} |
| 81 | + restore-keys: | |
| 82 | + ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} |
| 83 | + ${{ runner.os }}-maven- |
| 84 | + ${{ runner.os }}- |
| 85 | +
|
| 86 | + - name: Release to Maven Central |
| 87 | + run: | |
| 88 | + echo "Start release" |
| 89 | + echo $SONATYPE_GPG_KEY_BASE64 | base64 --decode | gpg --batch --no-tty --import --yes |
| 90 | + git config user.name github-actions[bot] |
| 91 | + git config user.email 41898282+github-actions[bot]@users.noreply.github.com |
| 92 | + git checkout master |
| 93 | + mvn gitflow:release-start gitflow:release-finish \ |
| 94 | + -DskipTests=true \ |
| 95 | + -Prelease \ |
| 96 | + -DpostReleaseGoals=deploy \ |
| 97 | + -DargLine='-Prelease -DskipTests -s .github/workflows/settings.xml' -B -s .github/workflows/settings.xml |
| 98 | +
|
0 commit comments