deploy-snapshot.yml 2.0 KB
Newer Older
1
name: Deploy
2 3 4 5 6 7 8 9 10

on: 
  push:
    branches: [ dev ]
    paths:
      - src/**
      - pom.xml

jobs:
11 12 13 14 15 16 17 18
  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'
19
          distribution: 'zulu'
20 21 22 23 24 25 26 27 28 29 30 31
      - 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

  deploy-snapshot:
    needs: test
    if: ${{ success() }}
32 33 34 35 36 37 38
    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'
39
          distribution: 'zulu'
40 41 42 43 44 45 46 47 48 49
          server-id: ossrh
          server-username: MAVEN_USERNAME
          server-password: MAVEN_PASSWORD
      - name: Cache m2 package
        uses: actions/cache@v2
        with:
          path: ~/.m2/repository
          key: ${{ runner.os }}-maven-${{ hashFiles('pom.xml') }}
          restore-keys: |
            ${{ runner.os }}-maven-
50 51 52 53 54 55 56 57 58 59 60
      - name: setting snapshot version
        run: |
          import xml.etree.ElementTree as ET
          tree = ET.parse("pom.xml")
          version = tree.find("{http://maven.apache.org/POM/4.0.0}version")
          print(version.text + "-SNAPSHOT")
          if version.text.endswith("-SNAPSHOT") == False:
            tree.find("{http://maven.apache.org/POM/4.0.0}version").text = version.text + "-SNAPSHOT"
            ET.register_namespace("", "http://maven.apache.org/POM/4.0.0")
            tree.write("pom.xml", "utf-8", True)
        shell: python
61
      - name: deploy snapshot to ossrh repository
62
        run: mvn -B deploy -P snapshot -DskipTests
63 64 65
        env:
          MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
          MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }}