|
| 1 | +name: Build and Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + push: |
| 6 | + tags: |
| 7 | + - 'v*' |
| 8 | + branches: |
| 9 | + - '**' |
| 10 | + pull_request: |
| 11 | + |
| 12 | +permissions: |
| 13 | + contents: write |
| 14 | + |
| 15 | +jobs: |
| 16 | + build-maven: |
| 17 | + runs-on: ubuntu-latest |
| 18 | + steps: |
| 19 | + - name: Checkout repository |
| 20 | + uses: actions/checkout@v4 |
| 21 | + with: |
| 22 | + fetch-depth: 0 |
| 23 | + |
| 24 | + - name: Setup Java |
| 25 | + uses: actions/setup-java@v4 |
| 26 | + with: |
| 27 | + distribution: 'temurin' |
| 28 | + java-version: '21' |
| 29 | + |
| 30 | + - name: Build with Maven |
| 31 | + run: mvn -B package -DskipTests=false -Darguments="-Dmaven.javadoc.skip=true" |
| 32 | + |
| 33 | + - name: Read project metadata |
| 34 | + id: project |
| 35 | + shell: bash |
| 36 | + run: | |
| 37 | + ARTIFACT_ID=$(mvn help:evaluate -Dexpression=project.artifactId -q -DforceStdout) |
| 38 | + VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) |
| 39 | + FINAL_NAME=$(mvn help:evaluate -Dexpression=project.build.finalName -q -DforceStdout) |
| 40 | +
|
| 41 | + echo "artifact_id=$ARTIFACT_ID" >> "$GITHUB_OUTPUT" |
| 42 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 43 | + echo "final_name=$FINAL_NAME" >> "$GITHUB_OUTPUT" |
| 44 | + echo "tag=v$VERSION" >> "$GITHUB_OUTPUT" |
| 45 | + echo "jar_path=target/$FINAL_NAME.jar" >> "$GITHUB_OUTPUT" |
| 46 | +
|
| 47 | + - name: Verify artifact |
| 48 | + shell: bash |
| 49 | + run: | |
| 50 | + if [ ! -f "${{ steps.project.outputs.jar_path }}" ]; then |
| 51 | + echo "${{ steps.project.outputs.jar_path }} was not created" |
| 52 | + exit 1 |
| 53 | + fi |
| 54 | +
|
| 55 | + - name: Upload artifacts |
| 56 | + uses: actions/upload-artifact@v4 |
| 57 | + if: success() |
| 58 | + with: |
| 59 | + name: ${{ steps.project.outputs.artifact_id }} |
| 60 | + path: ${{ steps.project.outputs.jar_path }} |
| 61 | + |
| 62 | + - name: Create GitHub release |
| 63 | + if: github.event_name == 'push' && (github.ref_type == 'tag' || github.ref_name == github.event.repository.default_branch) |
| 64 | + env: |
| 65 | + GH_TOKEN: ${{ github.token }} |
| 66 | + run: | |
| 67 | + if [ "${{ github.ref_type }}" = "tag" ]; then |
| 68 | + RELEASE_TAG="${{ github.ref_name }}" |
| 69 | + else |
| 70 | + RELEASE_TAG="${{ steps.project.outputs.tag }}" |
| 71 | + fi |
| 72 | +
|
| 73 | + if gh release view "$RELEASE_TAG" >/dev/null 2>&1; then |
| 74 | + gh release upload "$RELEASE_TAG" "${{ steps.project.outputs.jar_path }}" --clobber |
| 75 | + else |
| 76 | + gh release create "$RELEASE_TAG" "${{ steps.project.outputs.jar_path }}" --target "${{ github.sha }}" --title "$RELEASE_TAG" --notes "Automated release for $RELEASE_TAG" |
| 77 | + fi |
0 commit comments