From 2323a0b9cdaa141fff57128c895bb01a3f569a95 Mon Sep 17 00:00:00 2001 From: GavinGoGaming <57292172+GavinGoGaming@users.noreply.github.com> Date: Sun, 12 Mar 2023 13:57:47 -0700 Subject: [PATCH] Update maven-publish.yml --- .github/workflows/maven-publish.yml | 88 ++++++++++++++++++++--------- 1 file changed, 60 insertions(+), 28 deletions(-) diff --git a/.github/workflows/maven-publish.yml b/.github/workflows/maven-publish.yml index e8e36db..f75475e 100644 --- a/.github/workflows/maven-publish.yml +++ b/.github/workflows/maven-publish.yml @@ -1,34 +1,66 @@ -# 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: Build and Publish Release +on: + push: + branches: + - main + pull_request: + branches: + - main +env: + RELEASE_VERSION_PREFIX: auto-v +jobs: + build-and-publish-release: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 -name: Maven Package + - name: Set up JDK 11 + uses: actions/setup-java@v2 + with: + distribution: 'temurin' + java-version: 17 -on: [push] + - name: Get latest release + id: get_latest_release + uses: actions/github-script@v4 + with: + script: | + const res = await github.repos.getLatestRelease({ + owner: context.repo.owner, + repo: context.repo.repo + }); + console.log(res.data.tag_name); + return res.data.tag_name; -jobs: - build: + - name: Generate new release tag name + id: generate_release_tag_name + run: | + LAST_RELEASE_TAG=$GITHUB_REF + LAST_RELEASE_TAG=${LAST_RELEASE_TAG##refs/tags/} + NEW_RELEASE_VERSION=$(echo $LAST_RELEASE_TAG | sed -E 's/^[^0-9]*([0-9]+\.){2}[0-9]+$/\0+0.0.1/') + echo "::set-output name=NEW_RELEASE_TAG::$RELEASE_VERSION_PREFIX$NEW_RELEASE_VERSION" - runs-on: ubuntu-latest - permissions: - contents: read - packages: write + - name: Build with Maven + run: mvn clean package - steps: - - uses: actions/checkout@v3 - - name: Set up JDK 11 - uses: actions/setup-java@v3 - with: - java-version: '17' - distribution: 'temurin' - server-id: github - settings-path: ${{ github.workspace }} + - name: Create GitHub Release + id: create_release + uses: actions/create-release@v1.0.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ steps.generate_release_tag_name.outputs.NEW_RELEASE_TAG }} + release_name: Release ${{ steps.generate_release_tag_name.outputs.NEW_RELEASE_TAG }} + draft: false + prerelease: false - - name: Build with Maven - run: mvn -B package --file pom.xml - - - name: Automatic Releases - uses: marvinpinto/action-automatic-releases@v1.2.1 - with: - repo_token: ${{github.GITHUB_TOKEN}} - title: "Automated Release" - files: target/plumcode-1.0.jar + - name: Upload JAR file to release + uses: actions/upload-release-asset@v1.0.1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: target/Project-1.0.jar + asset_name: Project-1.0.jar + asset_content_type: application/java-archive