|
| 1 | +name: Package & Release Plugin |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ "main" ] |
| 6 | + pull_request: |
| 7 | + branches: [ "main" ] |
| 8 | + |
| 9 | +jobs: |
| 10 | + build: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + |
| 13 | + steps: |
| 14 | + - name: Checkout repository |
| 15 | + uses: actions/checkout@v4 |
| 16 | + |
| 17 | + - name: Set up JDK 21 |
| 18 | + uses: actions/setup-java@v3 |
| 19 | + with: |
| 20 | + distribution: 'temurin' |
| 21 | + java-version: '21' |
| 22 | + |
| 23 | + - name: Build with Maven |
| 24 | + run: mvn clean package |
| 25 | + |
| 26 | + - name: Upload plugin artifact |
| 27 | + uses: actions/upload-artifact@v4 |
| 28 | + with: |
| 29 | + name: Plugin |
| 30 | + path: target/CommandFramework-*.jar |
| 31 | + |
| 32 | + - name: Get Plugin Version |
| 33 | + id: version |
| 34 | + run: echo "VERSION=$(basename $(ls target/CommandFramework-*.jar | grep -vE '(-sources|-javadoc).jar') .jar | sed 's/CommandFramework-//')" >> $GITHUB_ENV |
| 35 | + |
| 36 | + - name: Delete existing GitHub release (if exists) |
| 37 | + run: | |
| 38 | + RELEASE_ID=$(gh release view v${{ env.VERSION }} --json id -q '.id' || echo "") |
| 39 | + if [ -n "$RELEASE_ID" ]; then |
| 40 | + echo "Deleting existing release..." |
| 41 | + gh release delete v${{ env.VERSION }} --yes |
| 42 | + fi |
| 43 | + env: |
| 44 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 45 | + |
| 46 | + - name: Delete existing tag (if exists) |
| 47 | + run: | |
| 48 | + if git rev-parse "v${{ env.VERSION }}" >/dev/null 2>&1; then |
| 49 | + echo "Deleting existing tag..." |
| 50 | + git tag -d v${{ env.VERSION }} |
| 51 | + git push origin :refs/tags/v${{ env.VERSION }} |
| 52 | + fi |
| 53 | + env: |
| 54 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 55 | + |
| 56 | + - name: Rename & Upload Latest Release |
| 57 | + run: | |
| 58 | + JAR_FILE=$(ls target/CommandFramework-*.jar | grep -vE '(-sources|-javadoc).jar' | head -n 1) |
| 59 | + cp "$JAR_FILE" target/CommandFramework-latest.jar |
| 60 | +
|
| 61 | + - name: Create GitHub Release |
| 62 | + uses: softprops/action-gh-release@v1 |
| 63 | + with: |
| 64 | + tag_name: v${{ env.VERSION }} |
| 65 | + name: Release v${{ env.VERSION }} |
| 66 | + draft: false |
| 67 | + prerelease: false |
| 68 | + files: | |
| 69 | + target/CommandFramework-latest.jar |
| 70 | + env: |
| 71 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments