|
| 1 | +name: Build and Release Plugin |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: # Manually triggered workflow |
| 5 | + |
| 6 | +jobs: |
| 7 | + build-master: |
| 8 | + runs-on: ubuntu-24.04 |
| 9 | + |
| 10 | + steps: |
| 11 | + - name: Check out master branch |
| 12 | + uses: actions/checkout@v4 |
| 13 | + with: |
| 14 | + ref: master |
| 15 | + |
| 16 | + - name: Set executable permissions for gradlew |
| 17 | + run: chmod +x ./gradlew |
| 18 | + |
| 19 | + - name: Update plugin version in gradle.properties |
| 20 | + run: | |
| 21 | + git fetch --tags --force |
| 22 | + latest_tag=$(git describe --tags $(git rev-list --tags --max-count=1) || echo "v0.0.0") |
| 23 | + version=${latest_tag#v} |
| 24 | + IFS='.' read -r major minor patch <<< "$version" |
| 25 | + new_patch=$((patch + 1)) |
| 26 | + new_version="$major.$minor.$new_patch" |
| 27 | + sed -i "s/^plugin_version = .*/plugin_version = $new_version/" gradle.properties |
| 28 | + git config --global user.name "GitHub Actions" |
| 29 | + git config --global user.email "actions@github.com" |
| 30 | + git add gradle.properties |
| 31 | + git commit -m "Update plugin version to $new_version" |
| 32 | + git push origin master |
| 33 | + echo "NEW_VERSION=$new_version" >> $GITHUB_ENV |
| 34 | +
|
| 35 | + - name: Verify Gradle Wrapper |
| 36 | + run: ./gradlew --version |
| 37 | + |
| 38 | + - name: Gradle Wrapper Verification |
| 39 | + uses: gradle/wrapper-validation-action@v1 |
| 40 | + |
| 41 | + - name: Setup JDK for Java 21 |
| 42 | + uses: actions/setup-java@v3 |
| 43 | + with: |
| 44 | + java-version: '21' |
| 45 | + distribution: 'temurin' |
| 46 | + |
| 47 | + - name: Build Plugin for Master (1.21.4) |
| 48 | + run: ./gradlew build |
| 49 | + |
| 50 | + - name: Rename and Upload artifact for master branch (1.21.4) |
| 51 | + run: mv build/libs/AutoBucket-*.jar build/libs/AutoBucket-1.21.4.jar |
| 52 | + |
| 53 | + - name: Upload artifact for master branch (1.21.4) |
| 54 | + uses: actions/upload-artifact@v4 |
| 55 | + with: |
| 56 | + name: AutoBucket-master |
| 57 | + path: build/libs/AutoBucket-1.21.4.jar |
| 58 | + |
| 59 | + build-2b: |
| 60 | + needs: build-master |
| 61 | + runs-on: ubuntu-24.04 |
| 62 | + |
| 63 | + steps: |
| 64 | + - name: Check out 2b branch |
| 65 | + uses: actions/checkout@v4 |
| 66 | + with: |
| 67 | + ref: 2b |
| 68 | + |
| 69 | + - name: Set executable permissions for gradlew |
| 70 | + run: chmod +x ./gradlew |
| 71 | + |
| 72 | + - name: Update plugin version in gradle.properties |
| 73 | + run: | |
| 74 | + git fetch --tags --force |
| 75 | + latest_tag=$(git describe --tags $(git rev-list --tags --max-count=1) || echo "v0.0.0") |
| 76 | + version=${latest_tag#v} |
| 77 | + IFS='.' read -r major minor patch <<< "$version" |
| 78 | + new_patch=$((patch + 1)) |
| 79 | + new_version="$major.$minor.$new_patch" |
| 80 | + sed -i "s/^plugin_version = .*/plugin_version = $new_version/" gradle.properties |
| 81 | + git config --global user.name "GitHub Actions" |
| 82 | + git config --global user.email "actions@github.com" |
| 83 | + git add gradle.properties |
| 84 | + git commit -m "Update plugin version to $new_version" |
| 85 | + git push origin 2b |
| 86 | + echo "NEW_VERSION=$new_version" >> $GITHUB_ENV |
| 87 | +
|
| 88 | + - name: Verify Gradle Wrapper |
| 89 | + run: ./gradlew --version |
| 90 | + |
| 91 | + - name: Gradle Wrapper Verification |
| 92 | + uses: gradle/wrapper-validation-action@v1 |
| 93 | + |
| 94 | + - name: Setup JDK for Java 17 |
| 95 | + uses: actions/setup-java@v3 |
| 96 | + with: |
| 97 | + java-version: '17' |
| 98 | + distribution: 'temurin' |
| 99 | + |
| 100 | + - name: Build Plugin for 2b (1.20.4) |
| 101 | + run: ./gradlew build |
| 102 | + |
| 103 | + - name: Rename and Upload artifact for 2b branch (1.20.4) |
| 104 | + run: mv build/libs/AutoBucket-*.jar build/libs/AutoBucket-1.20.4.jar |
| 105 | + |
| 106 | + - name: Upload artifact for 2b branch (1.20.4) |
| 107 | + uses: actions/upload-artifact@v4 |
| 108 | + with: |
| 109 | + name: AutoBucket-2b |
| 110 | + path: build/libs/AutoBucket-1.20.4.jar |
| 111 | + |
| 112 | + release: |
| 113 | + needs: [build-master, build-2b] |
| 114 | + runs-on: ubuntu-24.04 |
| 115 | + |
| 116 | + permissions: |
| 117 | + contents: write |
| 118 | + |
| 119 | + steps: |
| 120 | + - name: Check out the repository |
| 121 | + uses: actions/checkout@v4 |
| 122 | + |
| 123 | + - name: Download build artifact (master) |
| 124 | + uses: actions/download-artifact@v4 |
| 125 | + with: |
| 126 | + name: AutoBucket-master |
| 127 | + path: AutoBucket-master |
| 128 | + |
| 129 | + - name: Download build artifact (2b) |
| 130 | + uses: actions/download-artifact@v4 |
| 131 | + with: |
| 132 | + name: AutoBucket-2b |
| 133 | + path: AutoBucket-2b |
| 134 | + |
| 135 | + - name: Get and increment latest tag |
| 136 | + id: get_tag |
| 137 | + run: | |
| 138 | + git fetch --tags --force |
| 139 | + latest_tag=$(git describe --tags $(git rev-list --tags --max-count=1) || echo "v0.0.0") |
| 140 | + version=${latest_tag#v} |
| 141 | + IFS='.' read -r major minor patch <<< "$version" |
| 142 | + new_patch=$((patch + 1)) |
| 143 | + new_tag="v$major.$minor.$new_patch" |
| 144 | + echo "NEW_TAG=$new_tag" >> $GITHUB_ENV |
| 145 | +
|
| 146 | + - name: Create and push new tag |
| 147 | + env: |
| 148 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 149 | + run: | |
| 150 | + git config --global user.name "GitHub Actions" |
| 151 | + git config --global user.email "actions@github.com" |
| 152 | + git fetch --unshallow --tags |
| 153 | + git tag ${{ env.NEW_TAG }} |
| 154 | + git push https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} ${{ env.NEW_TAG }} |
| 155 | +
|
| 156 | + - name: Create GitHub Release |
| 157 | + uses: marvinpinto/action-automatic-releases@latest |
| 158 | + with: |
| 159 | + repo_token: "${{ secrets.GITHUB_TOKEN }}" |
| 160 | + automatic_release_tag: "${{ env.NEW_TAG }}" |
| 161 | + prerelease: false |
| 162 | + files: | |
| 163 | + AutoBucket-master/AutoBucket-1.21.4.jar |
| 164 | + AutoBucket-2b/AutoBucket-1.20.4.jar |
0 commit comments