diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4e0e521..eafc382 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,29 +9,15 @@ permissions: contents: write jobs: - release: + build: runs-on: ubuntu-latest - + outputs: + version: ${{ steps.version.outputs.version }} + tag: ${{ steps.version.outputs.tag }} + steps: - name: Checkout code uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Set up Java 21 - uses: actions/setup-java@v4 - with: - distribution: 'temurin' - java-version: '21' - - - name: Setup Gradle - uses: gradle/gradle-build-action@v2 - with: - cache-read-only: false - - - name: Grant execute permission for gradlew - if: runner.os != 'Windows' - run: chmod +x ./gradlew - name: Get version from tag id: version @@ -40,22 +26,28 @@ jobs: echo "version=$VERSION" >> $GITHUB_OUTPUT echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT + - name: Set up Java 21 + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '21' + cache: 'gradle' + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + - name: Update gradle.properties version run: | sed -i "s/mod_version=.*/mod_version=${{ steps.version.outputs.version }}/" gradle.properties - name: Build with Gradle - run: ./gradlew clean build --no-daemon + run: chmod +x ./gradlew && ./gradlew build --no-daemon --build-cache --parallel - name: Verify build output run: | - echo "=== JAR Files ===" - ls -lh build/libs/ - echo "" - echo "=== Verifying JAR content ===" for jar in build/libs/*.jar; do if [[ "$jar" != *"sources"* ]]; then - SIZE=$(stat -c%s "$jar" 2>/dev/null || stat -f%z "$jar" 2>/dev/null) + SIZE=$(stat -c%s "$jar") CLASSES=$(jar tf "$jar" | grep -c "\.class$" || echo 0) echo "$(basename $jar): ${SIZE} bytes, ${CLASSES} class files" if [ "$CLASSES" -eq 0 ]; then @@ -66,19 +58,43 @@ jobs: fi done + - name: Upload build artifacts + uses: actions/upload-artifact@v4 + with: + name: release-jars + path: | + build/libs/netmusiclist-${{ steps.version.outputs.version }}.jar + LICENSE.txt + retention-days: 1 + + changelog: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Get version from tag + id: version + run: | + VERSION=${GITHUB_REF#refs/tags/v} + echo "version=$VERSION" >> $GITHUB_OUTPUT + echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT + - name: Generate changelog - id: changelog run: | PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "") - + if [ -z "$PREVIOUS_TAG" ]; then CHANGELOG="Initial Release" else CHANGELOG=$(git log $PREVIOUS_TAG..${{ steps.version.outputs.tag }} --pretty=format:"- %s" --no-merges) fi - + { - echo "## 📦 NetMusicList ${{ steps.version.outputs.version }}" + echo "## NetMusicList ${{ steps.version.outputs.version }}" echo "" echo "### Minecraft Version" echo "- **Minecraft**: 1.21.1" @@ -88,20 +104,42 @@ jobs: echo "### Changes" echo "$CHANGELOG" echo "" - echo "### 📥 Installation" + echo "### Installation" echo "1. Make sure [Fabric Loader](https://fabricmc.net/use/) and [Fabric API](https://modrinth.com/mod/fabric-api) are installed" echo "2. Make sure [NetMusic Mod](https://www.mcmod.cn/class/2329.html) version 1.21.1 is installed" echo "3. Place the downloaded jar file into the \`.minecraft/mods\` folder" echo "4. Launch the game to use it" } > RELEASE_NOTES.md + - name: Upload changelog + uses: actions/upload-artifact@v4 + with: + name: release-notes + path: RELEASE_NOTES.md + retention-days: 1 + + release: + needs: [build, changelog] + runs-on: ubuntu-latest + + steps: + - name: Download build artifacts + uses: actions/download-artifact@v4 + with: + name: release-jars + + - name: Download changelog + uses: actions/download-artifact@v4 + with: + name: release-notes + - name: Create Release on GitHub uses: softprops/action-gh-release@v2 with: - name: NetMusicList v${{ steps.version.outputs.version }} + name: NetMusicList v${{ needs.build.outputs.version }} body_path: RELEASE_NOTES.md files: | - build/libs/netmusiclist-${{ steps.version.outputs.version }}.jar + build/libs/netmusiclist-${{ needs.build.outputs.version }}.jar LICENSE.txt env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}