Build and Release Plugin #15
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build and Release Plugin | |
| on: | |
| workflow_dispatch: # Manually triggered workflow | |
| jobs: | |
| build-master: | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - name: Check out master branch | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: master | |
| - name: Set executable permissions for gradlew | |
| run: chmod +x ./gradlew | |
| - name: Update plugin version in gradle.properties | |
| run: | | |
| # Extract current version from gradle.properties | |
| current_version=$(grep '^plugin_version =' gradle.properties | cut -d' ' -f3) | |
| IFS='.' read -r major minor patch <<< "$current_version" | |
| # Increment patch version by 1 | |
| new_patch=$((patch + 1)) | |
| # Check if patch exceeds 9, and increment minor version if needed | |
| if [ "$new_patch" -gt 9 ]; then | |
| new_patch=0 | |
| new_minor=$((minor + 1)) | |
| else | |
| new_minor=$minor | |
| fi | |
| # Check if minor exceeds 9, and increment major version if needed | |
| if [ "$new_minor" -gt 9 ]; then | |
| new_minor=0 | |
| new_major=$((major + 1)) | |
| else | |
| new_major=$major | |
| fi | |
| new_version="$new_major.$new_minor.$new_patch" | |
| # Update the version in gradle.properties | |
| sed -i "s/^plugin_version = .*/plugin_version = $new_version/" gradle.properties | |
| # Commit and push changes | |
| git config --global user.name "GitHub Actions" | |
| git config --global user.email "actions@github.com" | |
| git add gradle.properties | |
| git commit -m "Update plugin version to $new_version" | |
| git push origin master | |
| # Export new version as an environment variable | |
| echo "NEW_VERSION=$new_version" >> $GITHUB_ENV | |
| - name: Verify Gradle Wrapper | |
| run: ./gradlew --version | |
| - name: Gradle Wrapper Verification | |
| uses: gradle/wrapper-validation-action@v1 | |
| - name: Setup JDK for Java 21 | |
| uses: actions/setup-java@v3 | |
| with: | |
| java-version: '21' | |
| distribution: 'temurin' | |
| - name: Build Plugin for Master (1.21.4) | |
| run: ./gradlew build | |
| - name: Rename and Upload artifact for master branch (1.21.4) | |
| run: mv build/libs/LightningPop-*.jar build/libs/LightningPop-1.21.4.jar | |
| - name: Upload artifact for master branch (1.21.4) | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: LightningPop-master | |
| path: build/libs/LightningPop-1.21.4.jar | |
| build-2b: | |
| needs: build-master | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - name: Check out 2b branch | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: 2b | |
| - name: Set executable permissions for gradlew | |
| run: chmod +x ./gradlew | |
| - name: Update plugin version in gradle.properties | |
| run: | | |
| # Extract current version from gradle.properties | |
| current_version=$(grep '^plugin_version =' gradle.properties | cut -d' ' -f3) | |
| IFS='.' read -r major minor patch <<< "$current_version" | |
| # Increment patch version by 1 | |
| new_patch=$((patch + 1)) | |
| # Check if patch exceeds 9, and increment minor version if needed | |
| if [ "$new_patch" -gt 9 ]; then | |
| new_patch=0 | |
| new_minor=$((minor + 1)) | |
| else | |
| new_minor=$minor | |
| fi | |
| # Check if minor exceeds 9, and increment major version if needed | |
| if [ "$new_minor" -gt 9 ]; then | |
| new_minor=0 | |
| new_major=$((major + 1)) | |
| else | |
| new_major=$major | |
| fi | |
| new_version="$new_major.$new_minor.$new_patch" | |
| # Update the version in gradle.properties | |
| sed -i "s/^plugin_version = .*/plugin_version = $new_version/" gradle.properties | |
| # Commit and push changes | |
| git config --global user.name "GitHub Actions" | |
| git config --global user.email "actions@github.com" | |
| git add gradle.properties | |
| git commit -m "Update plugin version to $new_version" | |
| git push origin 2b | |
| # Export new version as an environment variable | |
| echo "NEW_VERSION=$new_version" >> $GITHUB_ENV | |
| - name: Verify Gradle Wrapper | |
| run: ./gradlew --version | |
| - name: Gradle Wrapper Verification | |
| uses: gradle/wrapper-validation-action@v1 | |
| - name: Setup JDK for Java 17 | |
| uses: actions/setup-java@v3 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| - name: Build Plugin for 2b (1.20.4) | |
| run: ./gradlew build | |
| - name: Rename and Upload artifact for 2b branch (1.20.4) | |
| run: mv build/libs/LightningPop-*.jar build/libs/LightningPop-1.20.4.jar | |
| - name: Upload artifact for 2b branch (1.20.4) | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: LightningPop-2b | |
| path: build/libs/LightningPop-1.20.4.jar | |
| release: | |
| needs: [build-master, build-2b] | |
| runs-on: ubuntu-24.04 | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Check out the repository | |
| uses: actions/checkout@v4 | |
| - name: Download build artifact (master) | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: LightningPop-master | |
| path: LightningPop-master | |
| - name: Download build artifact (2b) | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: LightningPop-2b | |
| path: LightningPop-2b | |
| - name: Get and increment latest tag | |
| id: get_tag | |
| run: | | |
| # Fetch all tags | |
| git fetch --tags --force | |
| # Get the latest tag | |
| latest_tag=$(git describe --tags $(git rev-list --tags --max-count=1) || echo "v0.0.0") | |
| echo "Latest tag: $latest_tag" | |
| # Remove 'v' prefix and split version into parts | |
| version=${latest_tag#v} | |
| IFS='.' read -r major minor patch <<< "$version" | |
| # Increment patch version by 1 | |
| new_patch=$((patch + 1)) | |
| new_minor=$minor | |
| new_major=$major | |
| # Check if patch exceeds 9 | |
| if [ "$new_patch" -gt 9 ]; then | |
| new_patch=0 | |
| new_minor=$((minor + 1)) | |
| fi | |
| # Check if minor exceeds 9 | |
| if [ "$new_minor" -gt 9 ]; then | |
| new_minor=0 | |
| new_major=$((major + 1)) | |
| fi | |
| new_tag="v$new_major.$new_minor.$new_patch" | |
| echo "New tag: $new_tag" | |
| echo "NEW_TAG=$new_tag" >> $GITHUB_ENV | |
| - name: Create and push new tag | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| git config --global user.name "GitHub Actions" | |
| git config --global user.email "actions@github.com" | |
| git fetch --unshallow --tags | |
| git tag ${{ env.NEW_TAG }} | |
| git push https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} ${{ env.NEW_TAG }} | |
| - name: Create GitHub Release | |
| uses: marvinpinto/action-automatic-releases@latest | |
| with: | |
| repo_token: "${{ secrets.GITHUB_TOKEN }}" | |
| automatic_release_tag: "${{ env.NEW_TAG }}" | |
| prerelease: false | |
| files: | | |
| LightningPop-master/LightningPop-1.21.4.jar | |
| LightningPop-2b/LightningPop-1.20.4.jar |