From a8dd8b92a231fe5e6aa60f331204cadcb19982dd Mon Sep 17 00:00:00 2001 From: BetterBox <53705390+Grzybol@users.noreply.github.com> Date: Sun, 17 Mar 2024 14:05:03 +0100 Subject: [PATCH] Update maven.yml --- .github/workflows/maven.yml | 73 +++++++++++++++++++++++++++++-------- 1 file changed, 58 insertions(+), 15 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 9e5bf12..eb78033 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -1,31 +1,74 @@ -# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven - -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. - -name: Java CI with Maven +name: Java CI with Maven, Auto-Versioning, and Release on: push: branches: [ "master" ] - pull_request: - branches: [ "master" ] + +permissions: + contents: write jobs: build: - runs-on: ubuntu-latest - + outputs: + version: ${{ steps.extract_info.outputs.version }} + artifact_name: ${{ steps.extract_info.outputs.artifact_name }} steps: - uses: actions/checkout@v3 + with: + fetch-depth: 0 + token: ${{ secrets.GITHUB_TOKEN }} - name: Set up JDK 17 uses: actions/setup-java@v3 with: java-version: '17' distribution: 'temurin' cache: maven - - name: Build with Maven - run: mvn -B package --file pom.xml + - name: Build with Maven and Auto-Versioning + run: mvn -B build-helper:parse-version versions:set versions:commit package --file pom.xml + - name: Upload Artifact + uses: actions/upload-artifact@v3 + with: + name: minecraft-plugin + path: target/*.jar + - name: Extract version and artifact name + id: extract_info + run: | + JAR_NAME=$(ls target/*.jar) + ARTIFACT_NAME=$(basename $JAR_NAME) + VERSION=$(echo $ARTIFACT_NAME | grep -oP '(?<=-)\d+\.\d+\.\d+(?=-SNAPSHOT)') + echo "VERSION=v$VERSION" >> $GITHUB_ENV + echo "ARTIFACT_NAME=$ARTIFACT_NAME" >> $GITHUB_ENV + + create-tag: + needs: build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + token: ${{ secrets.GITHUB_TOKEN }} + - name: Create and Push Tag + run: | + git config user.name "GitHub Actions" + git config user.email "github-actions@users.noreply.github.com" + git tag ${{ env.VERSION }} + git push https://x-access-token:${{ secrets.BR_ACCESS_TOKEN }}@github.com/${{ github.repository }} ${{ env.VERSION }} + + create-release: + needs: create-tag + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/download-artifact@v3 + with: + name: minecraft-plugin + - name: Create Release + uses: softprops/action-gh-release@v1 + with: + name: ${{ env.ARTIFACT_NAME }} + tag_name: ${{ env.VERSION }} + files: '*.jar' + generate_release_notes: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}