|
| 1 | +# Based on: https://docs.github.com/en/actions/guides/publishing-java-packages-with-maven |
| 2 | + |
| 3 | +# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created |
| 4 | +# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#apache-maven-with-a-settings-path |
| 5 | + |
| 6 | +name: Maven Deploy |
| 7 | + |
| 8 | +on: |
| 9 | + release: |
| 10 | + types: [created] |
| 11 | + |
| 12 | +jobs: |
| 13 | + build: |
| 14 | + |
| 15 | + runs-on: ubuntu-latest |
| 16 | + permissions: |
| 17 | + contents: read |
| 18 | + packages: write |
| 19 | + |
| 20 | + steps: |
| 21 | + - uses: actions/checkout@v2 |
| 22 | + - name: Set up JDK 8 |
| 23 | + uses: actions/setup-java@v2 |
| 24 | + with: |
| 25 | + java-version: '8' |
| 26 | + distribution: 'adopt' |
| 27 | + server-id: github # Value of the distributionManagement/repository/id field of the pom.xml |
| 28 | + settings-path: ${{ github.workspace }} # location for the settings.xml file |
| 29 | + |
| 30 | + - name: Build with Maven |
| 31 | + run: mvn --batch-mode package --file pom.xml |
| 32 | + |
| 33 | + - name: Publish to GitHub Packages Apache Maven |
| 34 | + run: | |
| 35 | + # Need to make a dummy call to mvn help:evaluate because first time results in output like: |
| 36 | + # "Downloading from central: https://repo.maven.apache.org/..." |
| 37 | + # And later calls to `help:evaluate | grep` are only filtering out lines starting with [. |
| 38 | + mvn help:evaluate -Dexpression=project.version |
| 39 | +
|
| 40 | + artifactId=$(mvn help:evaluate -Dexpression=project.artifactId | grep -e '^[^\\[]') |
| 41 | + echo $artifactId |
| 42 | +
|
| 43 | + version=$(mvn help:evaluate -Dexpression=project.version | grep -e '^[^\\[]') |
| 44 | + echo $version |
| 45 | +
|
| 46 | + # Save the fatjar as the artifact |
| 47 | + ls -lahFtr target |
| 48 | + rm target/${artifactId}-${version}.jar |
| 49 | + mv target/${artifactId}-${version}-fatjar.jar target/${artifactId}-${version}.jar |
| 50 | + ls -lahFtr target |
| 51 | +
|
| 52 | + # deploy:deploy because only want to deploy and not rebuild |
| 53 | + # jar:jar because it will populate the build context but not recreate jars |
| 54 | + # https://stackoverflow.com/questions/6308162/ |
| 55 | + mvn jar:jar deploy:deploy -s $GITHUB_WORKSPACE/settings.xml |
| 56 | + env: |
| 57 | + GITHUB_TOKEN: ${{ github.token }} |
0 commit comments