Update README.md #4
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" ] | |
| release: | |
| types: [created] | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v3 | |
| with: | |
| distribution: 'temurin' | |
| java-version: '17' | |
| - name: Build with Maven | |
| run: mvn clean package | |
| - name: Upload plugin artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: Plugin | |
| path: target/${{ github.event.repository.name }}-*.jar | |
| - name: Get Plugin Version | |
| id: version | |
| run: echo "VERSION=$(basename $(ls target/${{ github.event.repository.name }}-*.jar | grep -vE '(-sources|-javadoc).jar') .jar | sed 's/${{ github.event.repository.name }}-//')" >> $GITHUB_ENV | |
| - name: Delete existing GitHub release (if exists) | |
| run: | | |
| RELEASE_ID=$(gh release view ${{ env.VERSION }} --json id -q '.id' || echo "") | |
| if [ -n "$RELEASE_ID" ]; then | |
| echo "Deleting existing release..." | |
| gh release delete ${{ env.VERSION }} --yes | |
| fi | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Delete existing tag (if exists) | |
| run: | | |
| if git rev-parse "${{ env.VERSION }}" >/dev/null 2>&1; then | |
| echo "Deleting existing tag..." | |
| git tag -d ${{ env.VERSION }} | |
| git push origin :refs/tags/${{ env.VERSION }} | |
| fi | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Rename & Upload Latest Release | |
| run: | | |
| JAR_FILE=$(ls target/${{ github.event.repository.name }}-*.jar | grep -vE '(-sources|-javadoc).jar' | head -n 1) | |
| cp "$JAR_FILE" target/${{ github.event.repository.name }}-latest.jar | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| tag_name: ${{ env.VERSION }} | |
| name: Release ${{ env.VERSION }} | |
| draft: false | |
| prerelease: false | |
| files: | | |
| target/${{ github.event.repository.name }}-latest.jar | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Checkout Maven repository | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: CroaBeast/repo | |
| path: maven-repo | |
| token: ${{ secrets.MAVEN_DEPLOY_TOKEN }} | |
| - name: Configure Git | |
| run: | | |
| git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
| git config --global user.name "github-actions[bot]" | |
| - name: Deploy to Maven repository | |
| run: | | |
| # Create directory structure | |
| mkdir -p maven-repo/me/croabeast/${{ github.event.repository.name }}/${{ env.VERSION }} | |
| # Copy JAR file | |
| cp target/${{ github.event.repository.name }}-${{ env.VERSION }}.jar maven-repo/me/croabeast/${{ github.event.repository.name }}/${{ env.VERSION }}/ | |
| # Create POM file | |
| cat > maven-repo/me/croabeast/${{ github.event.repository.name }}/${{ env.VERSION }}/${{ github.event.repository.name }}-${{ env.VERSION }}.pom << EOF | |
| <?xml version="1.0" encoding="UTF-8"?> | |
| <project> | |
| <modelVersion>4.0.0</modelVersion> | |
| <groupId>me.croabeast</groupId> | |
| <artifactId>${{ github.event.repository.name }}</artifactId> | |
| <version>${{ env.VERSION }}</version> | |
| <packaging>jar</packaging> | |
| </project> | |
| EOF | |
| # Update or create maven-metadata.xml | |
| cat > maven-repo/me/croabeast/${{ github.event.repository.name }}/maven-metadata.xml << EOF | |
| <?xml version="1.0" encoding="UTF-8"?> | |
| <metadata> | |
| <groupId>me.croabeast</groupId> | |
| <artifactId>${{ github.event.repository.name }}</artifactId> | |
| <versioning> | |
| <latest>${{ env.VERSION }}</latest> | |
| <release>${{ env.VERSION }}</release> | |
| <versions> | |
| <version>${{ env.VERSION }}</version> | |
| </versions> | |
| <lastUpdated>$(date +%Y%m%d%H%M%S)</lastUpdated> | |
| </versioning> | |
| </metadata> | |
| EOF | |
| # Commit and push changes | |
| cd maven-repo | |
| git add . | |
| git commit -m "Deploy ${{ github.event.repository.name }} ${{ env.VERSION }}" | |
| git push | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |