publish-snapshot.yml 2.2 KB
Newer Older
智布道's avatar
智布道 已提交
1 2 3 4 5 6 7 8
# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created
# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#apache-maven-with-a-settings-path

name: Publish Snapshot

on:
  push:
    branches: [ dev ]
9 10 11
    paths:
      - src/**
      - pom.xml
智布道's avatar
智布道 已提交
12 13

jobs:
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2.2.0

      - name: Set up Java and Maven
        uses: actions/setup-java@v2
        with:
          java-version: '8'
          distribution: 'adopt'

      - name: Cache m2 package
        uses: actions/cache@v2
        with:
          path: ~/.m2/repository
          key: ${{ runner.os }}-maven-${{ hashFiles('pom.xml') }}
          restore-keys: |
            ${{ runner.os }}-maven-

      - run: mvn test

智布道's avatar
智布道 已提交
35
  publish:
36 37
    needs: test
    if: ${{ success() }}
智布道's avatar
智布道 已提交
38 39
    runs-on: ubuntu-latest
    steps:
40
      - uses: actions/checkout@v2
41

42 43
      - name: Set up Java and Maven
        uses: actions/setup-java@v2
44
        with:
45 46
          java-version: '8'
          distribution: 'adopt'
47
          server-id: sonatype-nexus-snapshots
48 49
          server-username: MAVEN_USERNAME
          server-password: MAVEN_PASSWORD
50
          gpg-passphrase: MAVEN_GPG_PASSWORD
51 52
          gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}

53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
      - name: Cache m2 package
        uses: actions/cache@v2
        with:
          path: ~/.m2/repository
          key: ${{ runner.os }}-maven-${{ hashFiles('pom.xml') }}
          restore-keys: |
            ${{ runner.os }}-maven-

      - name: get current project version to set env.VERSION
        run: echo "VERSION=`mvn help:evaluate -Dexpression=project.version -q -DforceStdout`" >> $GITHUB_ENV

      - name: set snapshot version
        if: ${{ !endsWith( env.VERSION , '-SNAPSHOT') }}
        run: mvn versions:set -DnewVersion=${{ env.VERSION }}-SNAPSHOT

      - name: deploy snapshot to oss repository
69
        run: mvn -B deploy -P release -DskipTests
70 71 72
        env:
          MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
          MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
73
          MAVEN_GPG_PASSWORD: ${{ secrets.MAVEN_GPG_PASSWORD }}