1.4 - Fix #41
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 (Temurin 21) | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: 'temurin' | |
| java-version: '21' | |
| - name: Set up Gradle | |
| uses: gradle/actions/setup-gradle@v4 | |
| - name: Make gradlew executable | |
| run: chmod +x gradlew | |
| - name: Build with Gradle | |
| run: | | |
| ./gradlew --no-daemon clean :core:build :shaded:shadowJar :shaded-all:shadowJar :plugin:shadowJar | |
| - name: Get Version from Gradle | |
| id: version | |
| run: | | |
| VER=$(./gradlew -q properties | awk -F': ' '/^version:/ {print $2; exit}') | |
| echo "VERSION=$VER" >> $GITHUB_ENV | |
| echo "version=$VER" >> $GITHUB_OUTPUT | |
| - name: Upload all module artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: Takion-artifacts-${{ env.VERSION }} | |
| path: | | |
| core/build/libs/*-${{ env.VERSION }}.jar | |
| core/build/libs/*-${{ env.VERSION }}-sources.jar | |
| core/build/libs/*-${{ env.VERSION }}-javadoc.jar | |
| shaded-all/build/libs/*-${{ env.VERSION }}.jar | |
| shaded-all/build/libs/*-${{ env.VERSION }}-sources.jar | |
| shaded-all/build/libs/*-${{ env.VERSION }}-javadoc.jar | |
| shaded/build/libs/*-${{ env.VERSION }}.jar | |
| shaded/build/libs/*-${{ env.VERSION }}-sources.jar | |
| shaded/build/libs/*-${{ env.VERSION }}-javadoc.jar | |
| plugin/build/libs/*-${{ env.VERSION }}.jar | |
| plugin/build/libs/*-${{ env.VERSION }}-sources.jar | |
| plugin/build/libs/*-${{ env.VERSION }}-javadoc.jar | |
| if-no-files-found: ignore | |
| - 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: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ env.VERSION }} | |
| name: Release ${{ env.VERSION }} | |
| files: | | |
| core/build/libs/*-${{ env.VERSION }}.jar | |
| shaded-all/build/libs/*-${{ env.VERSION }}.jar | |
| shaded/build/libs/*-${{ env.VERSION }}.jar | |
| plugin/build/libs/*-${{ env.VERSION }}.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 all modules to Maven repository (group me.croabeast.takion) | |
| env: | |
| VERSION: ${{ env.VERSION }} | |
| run: | | |
| set -e | |
| deploy_module () { | |
| MODULE_DIR="$1" | |
| ARTIFACT_ID="$2" | |
| SRC_DIR="$MODULE_DIR/build/libs" | |
| DEST_DIR="maven-repo/me/croabeast/takion/$ARTIFACT_ID/$VERSION" | |
| ART="$ARTIFACT_ID-$VERSION" | |
| mkdir -p "$DEST_DIR" | |
| MAIN_JAR=$(ls "$SRC_DIR"/*-"$VERSION".jar | grep -vE '(-sources|-javadoc).jar' | head -n1 || true) | |
| [ -n "$MAIN_JAR" ] && cp "$MAIN_JAR" "$DEST_DIR/$ART.jar" || true | |
| SRC_JAR=$(ls "$SRC_DIR"/*-"$VERSION"-sources.jar 2>/dev/null | head -n1 || true) | |
| [ -n "$SRC_JAR" ] && cp "$SRC_JAR" "$DEST_DIR/$ART-sources.jar" || true | |
| DOC_JAR=$(ls "$SRC_DIR"/*-"$VERSION"-javadoc.jar 2>/dev/null | head -n1 || true) | |
| [ -n "$DOC_JAR" ] && cp "$DOC_JAR" "$DEST_DIR/$ART-javadoc.jar" || true | |
| cat > "$DEST_DIR/$ART.pom" << EOF | |
| <?xml version="1.0" encoding="UTF-8"?> | |
| <project> | |
| <modelVersion>4.0.0</modelVersion> | |
| <groupId>me.croabeast.takion</groupId> | |
| <artifactId>$ARTIFACT_ID</artifactId> | |
| <version>$VERSION</version> | |
| <packaging>jar</packaging> | |
| </project> | |
| EOF | |
| META_DIR="maven-repo/me/croabeast/takion/$ARTIFACT_ID" | |
| mkdir -p "$META_DIR" | |
| cat > "$META_DIR/maven-metadata.xml" << EOF | |
| <?xml version="1.0" encoding="UTF-8"?> | |
| <metadata> | |
| <groupId>me.croabeast.takion</groupId> | |
| <artifactId>$ARTIFACT_ID</artifactId> | |
| <versioning> | |
| <latest>$VERSION</latest> | |
| <release>$VERSION</release> | |
| <versions> | |
| <version>$VERSION</version> | |
| </versions> | |
| <lastUpdated>$(date -u +%Y%m%d%H%M%S)</lastUpdated> | |
| </versioning> | |
| </metadata> | |
| EOF | |
| } | |
| deploy_module core core | |
| deploy_module shaded-all shaded-all | |
| deploy_module shaded shaded | |
| deploy_module plugin plugin | |
| cd maven-repo | |
| git add . | |
| git commit -m "Deploy Takion $VERSION" || echo "No changes to commit" | |
| git push |