Fix some stuff #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: Build & Release | |
| on: | |
| push: | |
| branches: [ main ] | |
| workflow_dispatch: | |
| tags: | |
| - 'v*' | |
| permissions: | |
| contents: write | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| name: Mod Building | |
| outputs: | |
| version: ${{ steps.version.outputs.version }} | |
| filename: ${{ steps.build.outputs.filename }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup Java | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: 'temurin' | |
| java-version: '17' | |
| cache: gradle | |
| - name: Grant execute permission for gradlew | |
| run: chmod +x gradlew | |
| - name: Build project | |
| id: build | |
| run: | | |
| ./gradlew build | |
| # Read mod id and version from gradle.properties to match Gradle's jar naming | |
| MOD_ID=$(grep "^mod_id=" gradle.properties | cut -d'=' -f2) | |
| MOD_VER=$(grep "^mod_version=" gradle.properties | cut -d'=' -f2) | |
| # Prefer the canonical Gradle artifact name: ${MOD_ID}-${MOD_VER}*.jar | |
| JAR_FILE=$(ls build/libs/"${MOD_ID}-${MOD_VER}"*.jar 2>/dev/null | grep -v sources | head -1 || true) | |
| # Fallback: pick the first non-sources jar | |
| if [ -z "$JAR_FILE" ]; then | |
| JAR_FILE=$(ls build/libs/*.jar | grep -v sources | head -1 || true) | |
| fi | |
| echo "filename=$(basename "$JAR_FILE")" >> $GITHUB_OUTPUT | |
| - name: Get version from gradle.properties | |
| id: version | |
| run: | | |
| VERSION=$(grep "^mod_version=" gradle.properties | cut -d'=' -f2) | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| - name: Upload build artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: mod-build | |
| path: build/libs/ | |
| release: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| name: Create Release | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| steps: | |
| - name: Checkout (fetch tags) | |
| uses: actions/checkout@v4 | |
| - name: Determine tag and annotated message | |
| id: taginfo | |
| run: | | |
| TAG=${GITHUB_REF##*/} | |
| echo "tag=$TAG" >> $GITHUB_OUTPUT | |
| # Try to read annotated tag contents | |
| BODY=$(git for-each-ref --format='%(contents)' refs/tags/$TAG 2>/dev/null || true) | |
| if [ -z "$BODY" ]; then | |
| BODY=$(git tag -l --format='%(contents)' "$TAG" 2>/dev/null || true) | |
| fi | |
| # Fallback to commit message if no tag message | |
| if [ -z "$BODY" ]; then | |
| BODY=$(git log -1 --pretty=%B) | |
| fi | |
| echo "body<<EOF" >> $GITHUB_OUTPUT | |
| echo "$BODY" >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| - name: Download artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: mod-build | |
| path: ./artifacts | |
| - name: Create GitHub Release | |
| id: create_release | |
| uses: actions/create-release@v1 | |
| with: | |
| tag_name: ${{ steps.taginfo.outputs.tag }} | |
| release_name: ${{ steps.taginfo.outputs.tag }} | |
| body: ${{ steps.taginfo.outputs.body }} | |
| draft: false | |
| prerelease: false | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Upload release asset | |
| uses: actions/upload-release-asset@v1 | |
| with: | |
| upload_url: ${{ steps.create_release.outputs.upload_url }} | |
| asset_path: ./artifacts/${{ needs.build.outputs.filename }} | |
| asset_name: ${{ needs.build.outputs.filename }} | |
| asset_content_type: application/java-archive |