Update maven-publish.yml #2
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: Package & Release Plugin | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| pull_request: | |
| branches: [ "main" ] | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up JDK 8 | |
| uses: actions/setup-java@v3 | |
| with: | |
| distribution: 'temurin' | |
| java-version: '8' | |
| - name: Build with Maven | |
| run: mvn clean package | |
| - name: Upload plugin artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: Plugin | |
| path: target/CommandFramework-*.jar | |
| - name: Get Plugin Version | |
| id: version | |
| run: echo "VERSION=$(basename $(ls target/CommandFramework-*.jar | grep -vE '(-sources|-javadoc).jar') .jar | sed 's/CommandFramework-//')" >> $GITHUB_ENV | |
| - name: Delete existing GitHub release (if exists) | |
| run: | | |
| RELEASE_ID=$(gh release view v${{ env.VERSION }} --json id -q '.id' || echo "") | |
| if [ -n "$RELEASE_ID" ]; then | |
| echo "Deleting existing release..." | |
| gh release delete v${{ env.VERSION }} --yes | |
| fi | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Delete existing tag (if exists) | |
| run: | | |
| if git rev-parse "v${{ env.VERSION }}" >/dev/null 2>&1; then | |
| echo "Deleting existing tag..." | |
| git tag -d v${{ env.VERSION }} | |
| git push origin :refs/tags/v${{ env.VERSION }} | |
| fi | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Rename & Upload Latest Release | |
| run: | | |
| JAR_FILE=$(ls target/CommandFramework-*.jar | grep -vE '(-sources|-javadoc).jar' | head -n 1) | |
| cp "$JAR_FILE" target/CommandFramework-latest.jar | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| tag_name: v${{ env.VERSION }} | |
| name: Release v${{ env.VERSION }} | |
| draft: false | |
| prerelease: false | |
| files: | | |
| target/CommandFramework-latest.jar | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |