|
| 1 | +name: Package & Release Plugin |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ "main" ] |
| 6 | + pull_request: |
| 7 | + branches: [ "main" ] |
| 8 | + release: |
| 9 | + types: [ created ] |
| 10 | + |
| 11 | +jobs: |
| 12 | + build: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Checkout repository |
| 17 | + uses: actions/checkout@v4 |
| 18 | + |
| 19 | + - name: Set up JDK 8 |
| 20 | + uses: actions/setup-java@v3 |
| 21 | + with: |
| 22 | + distribution: 'temurin' |
| 23 | + java-version: '8' |
| 24 | + |
| 25 | + - name: Setup Gradle |
| 26 | + uses: gradle/actions/setup-gradle@v3 |
| 27 | + |
| 28 | + - name: Grant execute permission for Gradle wrapper |
| 29 | + run: chmod +x gradlew |
| 30 | + |
| 31 | + - name: Build with Gradle |
| 32 | + run: ./gradlew build |
| 33 | + |
| 34 | + - name: Extract project info |
| 35 | + run: | |
| 36 | + PROJECT_NAME=$(./gradlew properties -q | grep "^name:" | awk '{print $2}') |
| 37 | + VERSION=$(./gradlew properties -q | grep "^version:" | awk '{print $2}') |
| 38 | + echo "PROJECT_NAME=$PROJECT_NAME" >> $GITHUB_ENV |
| 39 | + echo "VERSION=$VERSION" >> $GITHUB_ENV |
| 40 | +
|
| 41 | + - name: Upload plugin artifact |
| 42 | + uses: actions/upload-artifact@v4 |
| 43 | + with: |
| 44 | + name: Plugin |
| 45 | + path: build/libs/${{ env.PROJECT_NAME }}-*.jar |
| 46 | + |
| 47 | + - name: Delete existing GitHub release (if exists) |
| 48 | + run: | |
| 49 | + RELEASE_ID=$(gh release view ${{ env.VERSION }} --json id -q '.id' || echo "") |
| 50 | + if [ -n "$RELEASE_ID" ]; then |
| 51 | + echo "Deleting existing release..." |
| 52 | + gh release delete ${{ env.VERSION }} --yes |
| 53 | + fi |
| 54 | + env: |
| 55 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 56 | + |
| 57 | + - name: Delete existing tag (if exists) |
| 58 | + run: | |
| 59 | + if git rev-parse "${{ env.VERSION }}" >/dev/null 2>&1; then |
| 60 | + echo "Deleting existing tag..." |
| 61 | + git tag -d ${{ env.VERSION }} |
| 62 | + git push origin :refs/tags/${{ env.VERSION }} |
| 63 | + fi |
| 64 | + env: |
| 65 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 66 | + |
| 67 | + - name: Prepare release JAR |
| 68 | + run: | |
| 69 | + JAR_FILE=$(ls build/libs/${{ env.PROJECT_NAME }}-*.jar | grep -vE '(-sources|-javadoc|-all).jar' | head -n 1) |
| 70 | + cp "$JAR_FILE" build/libs/${{ env.PROJECT_NAME }}-latest.jar |
| 71 | +
|
| 72 | + - name: Create GitHub Release |
| 73 | + uses: softprops/action-gh-release@v1 |
| 74 | + with: |
| 75 | + tag_name: ${{ env.VERSION }} |
| 76 | + name: Release ${{ env.VERSION }} |
| 77 | + draft: false |
| 78 | + prerelease: false |
| 79 | + files: | |
| 80 | + build/libs/${{ env.PROJECT_NAME }}-latest.jar |
| 81 | + env: |
| 82 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 83 | + |
| 84 | + - name: Checkout Maven repository |
| 85 | + uses: actions/checkout@v4 |
| 86 | + with: |
| 87 | + repository: CroaBeast/repo |
| 88 | + path: maven-repo |
| 89 | + token: ${{ secrets.MAVEN_DEPLOY_TOKEN }} |
| 90 | + |
| 91 | + - name: Configure Git |
| 92 | + run: | |
| 93 | + git config --global user.email "github-actions[bot]@users.noreply.github.com" |
| 94 | + git config --global user.name "github-actions[bot]" |
| 95 | +
|
| 96 | + - name: Deploy to Maven repository |
| 97 | + run: | |
| 98 | + NAME=${{ env.PROJECT_NAME }} |
| 99 | +
|
| 100 | + # Create directory structure |
| 101 | + mkdir -p maven-repo/me/croabeast/${NAME}/${{ env.VERSION }} |
| 102 | +
|
| 103 | + # Copy JAR files |
| 104 | + cp build/libs/${NAME}-${{ env.VERSION }}.jar \ |
| 105 | + maven-repo/me/croabeast/${NAME}/${{ env.VERSION }}/ |
| 106 | + cp build/libs/${NAME}-${{ env.VERSION }}-javadoc.jar \ |
| 107 | + maven-repo/me/croabeast/${NAME}/${{ env.VERSION }}/ |
| 108 | + cp build/libs/${NAME}-${{ env.VERSION }}-sources.jar \ |
| 109 | + maven-repo/me/croabeast/${NAME}/${{ env.VERSION }}/ |
| 110 | +
|
| 111 | + # Create POM file |
| 112 | + cat > maven-repo/me/croabeast/${NAME}/${{ env.VERSION }}/${NAME}-${{ env.VERSION }}.pom << EOF |
| 113 | + <?xml version="1.0" encoding="UTF-8"?> |
| 114 | + <project> |
| 115 | + <modelVersion>4.0.0</modelVersion> |
| 116 | + <groupId>me.croabeast</groupId> |
| 117 | + <artifactId>${NAME}</artifactId> |
| 118 | + <version>${{ env.VERSION }}</version> |
| 119 | + <packaging>jar</packaging> |
| 120 | + </project> |
| 121 | + EOF |
| 122 | +
|
| 123 | + # Update or create maven-metadata.xml |
| 124 | + cat > maven-repo/me/croabeast/${NAME}/maven-metadata.xml << EOF |
| 125 | + <?xml version="1.0" encoding="UTF-8"?> |
| 126 | + <metadata> |
| 127 | + <groupId>me.croabeast</groupId> |
| 128 | + <artifactId>${NAME}</artifactId> |
| 129 | + <versioning> |
| 130 | + <latest>${{ env.VERSION }}</latest> |
| 131 | + <release>${{ env.VERSION }}</release> |
| 132 | + <versions> |
| 133 | + <version>${{ env.VERSION }}</version> |
| 134 | + </versions> |
| 135 | + <lastUpdated>$(date +%Y%m%d%H%M%S)</lastUpdated> |
| 136 | + </versioning> |
| 137 | + </metadata> |
| 138 | + EOF |
| 139 | +
|
| 140 | + # Commit and push changes |
| 141 | + cd maven-repo |
| 142 | + git add . |
| 143 | + git commit -m "Deploy ${NAME} ${{ env.VERSION }}" |
| 144 | + git push |
| 145 | +
|
| 146 | +env: |
| 147 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments