From af9ca87f7757e3053e2ac53ab17b5cb6534bb863 Mon Sep 17 00:00:00 2001 From: Patryk Cholewa Date: Thu, 14 Nov 2024 22:28:06 +0100 Subject: [PATCH] Create release.yml --- .github/workflows/release.yml | 85 +++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..fdc5125 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,85 @@ +name: Release Workflow + +on: + release: + types: [published] + +jobs: + build-and-release: + runs-on: ubuntu-latest + + steps: + # 1. Checkout repository + - name: Checkout repository + uses: actions/checkout@v3 + + # 2. Set up Java environment + - name: Set up Java 21 + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '21' + + # 3. Extract version from the release tag + - name: Extract version from tag + id: extract_version + run: | + VERSION="${GITHUB_REF#refs/tags/v}" + IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION" + echo "RELEASE_VERSION=${MAJOR}.${MINOR}.${PATCH}-1.21.3" >> $GITHUB_ENV + echo "NEXT_SNAPSHOT_VERSION=${MAJOR}.${MINOR}.$((PATCH + 1))-1.21.3-SNAPSHOT" >> $GITHUB_ENV + + # 4. Update pom.xml to release version + - name: Update version in pom.xml for release + run: | + mvn versions:set -DnewVersion="${{ env.RELEASE_VERSION }}" + mvn versions:commit + + # 5. Commit the updated pom.xml for release version + - name: Commit updated pom.xml + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git commit -am "Set version to ${{ env.RELEASE_VERSION }}" + + # 6. Create a new tag for the release version + - name: Create tag for release + run: | + git tag "v${{ env.RELEASE_VERSION }}" + git push origin "v${{ env.RELEASE_VERSION }}" + + # 7. Build the project + - name: Build with Maven + run: | + mvn install + mvn package + + # 8. Upload JAR files to GitHub Release + - name: Upload JAR files to GitHub Release + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ github.event.release.upload_url }} + asset_path: target/*.jar + asset_name: "${{ github.event.release.tag_name }}-jar-files.zip" + asset_content_type: application/zip + + # 9. Update pom.xml to next SNAPSHOT version + - name: Update version in pom.xml to next SNAPSHOT + run: | + mvn versions:set -DnewVersion="${{ env.NEXT_SNAPSHOT_VERSION }}" + mvn versions:commit + + # 10. Commit updated pom.xml for next SNAPSHOT version + - name: Commit next SNAPSHOT version + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git commit -am "Set version to ${{ env.NEXT_SNAPSHOT_VERSION }}" + + # 11. Push changes back to the repository + - name: Push changes + uses: ad-m/github-push-action@v0.6.0 + with: + github_token: ${{ secrets.GITHUB_TOKEN }}