Merge pull request #3 from NeverStopGaming/dev #24
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 | |
| on: | |
| push: {} | |
| pull_request: {} | |
| permissions: | |
| contents: write # nötig für GitHub Releases | |
| jobs: | |
| build: | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Validate Gradle wrapper | |
| uses: gradle/actions/wrapper-validation@v4 | |
| - name: Setup JDK | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: "21" | |
| distribution: "microsoft" | |
| - name: Make Gradle wrapper executable | |
| run: chmod +x ./gradlew | |
| - name: Build | |
| run: ./gradlew build | |
| - name: Capture build artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: Artifacts | |
| path: build/libs/ | |
| publish: | |
| name: Publish (Modrinth + GitHub Release) | |
| needs: build | |
| runs-on: ubuntu-24.04 | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Download build artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: Artifacts | |
| path: artifacts | |
| - name: List artifacts for debugging | |
| run: ls -R artifacts || echo "No artifacts found" | |
| - name: Find built JAR (ohne -sources/-javadoc) | |
| id: findjar | |
| run: | | |
| shopt -s nullglob || true | |
| # Alle Jars auflisten, aber sources/javadoc rausfiltern | |
| JAR=$(ls artifacts/*.jar 2>/dev/null | grep -vE '(-sources|-javadoc)\.jar$' | head -n 1 || true) | |
| if [ -z "$JAR" ]; then | |
| echo "No non-sources/non-javadoc JAR found in artifacts/" >&2 | |
| echo "Gefundene JARs (inkl. sources/javadoc, falls vorhanden):" >&2 | |
| ls artifacts/*.jar 2>/dev/null || echo "Keine JAR-Dateien gefunden" >&2 | |
| exit 1 | |
| fi | |
| echo "Gefundene JAR: $JAR" | |
| echo "jar=$JAR" >> "$GITHUB_OUTPUT" | |
| JARNAME=$(basename "$JAR") | |
| echo "jar=$JAR" >> "$GITHUB_OUTPUT" | |
| echo "jarname=$JARNAME" >> "$GITHUB_OUTPUT" | |
| - name: Read gradle properties | |
| id: gradleprops | |
| run: | | |
| if [ ! -f gradle.properties ]; then | |
| echo "gradle.properties not found" >&2 | |
| exit 1 | |
| fi | |
| VERSION=$(grep '^mod_version=' gradle.properties | cut -d'=' -f2- | tr -d '\r') | |
| # Minecraft-Version aus gradle.properties verwenden | |
| MC=$(grep '^minecraft_version=' gradle.properties | cut -d'=' -f2- | tr -d '\r') | |
| # Loader (kannst du ggf. anpassen, z.B. "fabric,quilt") | |
| LOADERS="fabric" | |
| if [ -z "$VERSION" ]; then | |
| echo "mod_version not set in gradle.properties" >&2 | |
| exit 1 | |
| fi | |
| echo "Version: $VERSION" | |
| echo "Minecraft version (from gradle.properties): $MC" | |
| echo "Loaders: $LOADERS" | |
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | |
| echo "game_versions=$MC" >> "$GITHUB_OUTPUT" | |
| echo "loaders=$LOADERS" >> "$GITHUB_OUTPUT" | |
| - name: Modrinth Publish | |
| uses: cloudnode-pro/modrinth-publish@v2.1.5 | |
| with: | |
| # in Repo-Secrets hinterlegt: | |
| # MODRINTH_TOKEN, MODRINTH_PROJECT_ID | |
| token: ${{ secrets.MODRINTH_TOKEN }} | |
| project: ${{ secrets.MODRINTH_PROJECT_ID }} | |
| files: ${{ steps.findjar.outputs.jar }} | |
| # Primary-File nur der Dateiname, nicht der Pfad | |
| primary-file: ${{ steps.findjar.outputs.jarname }} | |
| name: v${{ steps.gradleprops.outputs.version }} | |
| version: ${{ steps.gradleprops.outputs.version }} | |
| changelog: Automated publish from GitHub Actions | |
| loaders: ${{ steps.gradleprops.outputs.loaders }} | |
| game-versions: ${{ steps.gradleprops.outputs.game_versions }} | |
| - name: Create GitHub Release | |
| uses: ncipollo/release-action@v1 | |
| with: | |
| tag: v${{ steps.gradleprops.outputs.version }} | |
| name: v${{ steps.gradleprops.outputs.version }} | |
| artifacts: ${{ steps.findjar.outputs.jar }} | |
| artifactContentType: application/java-archive |