Build and Release Plugin #7
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 GarlicBreeder | |
| on: | |
| workflow_dispatch: # Allows manual triggering of the workflow | |
| jobs: | |
| build: | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - name: Check out master branch | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: master | |
| - name: Set executable permissions for Gradle wrapper | |
| run: chmod +x ./gradlew | |
| - 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: Increment Plugin Version in gradle.properties | |
| run: | | |
| # Read the current plugin_version | |
| current_version=$(grep '^plugin_version' gradle.properties | cut -d'=' -f2 | tr -d ' ') | |
| # Split version into parts | |
| IFS='.' read -r major minor patch <<< "$current_version" | |
| # Increment the patch version | |
| new_patch=$((patch + 1)) | |
| # Handle patch overflow | |
| if [ "$new_patch" -gt 9 ]; then | |
| new_patch=0 | |
| new_minor=$((minor + 1)) | |
| else | |
| new_minor=$minor | |
| fi | |
| # Handle minor overflow | |
| 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 gradle.properties | |
| sed -i "s/^plugin_version.*/plugin_version=$new_version/" gradle.properties | |
| # Save the new version to a file | |
| echo "$new_version" > version.txt | |
| # Commit and push the version change | |
| git config --global user.name "GitHub Actions" | |
| git config --global user.email "[email protected]" | |
| git add gradle.properties | |
| git commit -m "Bump plugin version to $new_version" | |
| git push origin master | |
| - name: Upload version file | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: version | |
| path: version.txt | |
| - name: Build GarlicBreeder Plugin (1.20.4) | |
| run: ./gradlew build | |
| - name: Rename artifact if needed | |
| run: | | |
| VERSION=$(cat version.txt) | |
| JAR_FILE=$(ls build/libs/GarlicBreeder-*.jar | head -n 1) | |
| if [[ -z "$JAR_FILE" ]]; then | |
| echo "Error: No JAR file found!" | |
| exit 1 | |
| fi | |
| EXPECTED_NAME="build/libs/GarlicBreeder-$VERSION.jar" | |
| if [[ "$JAR_FILE" != "$EXPECTED_NAME" ]]; then | |
| mv "$JAR_FILE" "$EXPECTED_NAME" | |
| fi | |
| - name: Upload JAR artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: GarlicBreeder | |
| path: build/libs/GarlicBreeder-*.jar | |
| release: | |
| needs: build | |
| runs-on: ubuntu-24.04 | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Check out the repository | |
| uses: actions/checkout@v4 | |
| - name: Download version file | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: version | |
| - name: Read version | |
| id: read_version | |
| run: echo "NEW_VERSION=$(cat version.txt)" >> $GITHUB_ENV | |
| shell: bash | |
| - name: Download built artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: GarlicBreeder | |
| path: GarlicBreeder | |
| - name: Create GitHub Release | |
| uses: marvinpinto/action-automatic-releases@latest | |
| with: | |
| repo_token: "${{ secrets.GITHUB_TOKEN }}" | |
| automatic_release_tag: "v${{ steps.read_version.outputs.NEW_VERSION }}" | |
| prerelease: false | |
| files: | | |
| GarlicBreeder/GarlicBreeder-${{ steps.read_version.outputs.NEW_VERSION }}.jar |