|
| 1 | +name: Upload Release Artifacts |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: [ '*' ] |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: read |
| 9 | + |
| 10 | +concurrency: |
| 11 | + group: publish-${{ github.workflow }}-${{ github.ref }} |
| 12 | + cancel-in-progress: false # Never cancel a release halfway through uploading. |
| 13 | + |
| 14 | +env: |
| 15 | + JAVA_VERSION: 21 |
| 16 | + # Only booleans here, the secrets themselves are passed to the steps that need them. This is a preventative measure. |
| 17 | + HAS_MAVEN: ${{ secrets.MAVEN_UPLOAD_URL != '' }} |
| 18 | + HAS_CURSEFORGE: ${{ secrets.CURSEFORGE_TOKEN != '' }} |
| 19 | + # The release tag ("modMajor.modMinor.modBug.minecraftVersionNoDots.loader" example: 1.2.1.121012) is used as-is for the mod version, build.gradle reads this. |
| 20 | + TAG: ${{ github.ref_name }} |
| 21 | + |
| 22 | +jobs: |
| 23 | + publish: |
| 24 | + name: Build and Publish |
| 25 | + runs-on: ubuntu-latest |
| 26 | + timeout-minutes: 30 |
| 27 | + permissions: |
| 28 | + contents: write # Required for mc-publish to create a GitHub release. |
| 29 | + |
| 30 | + steps: |
| 31 | + - name: Check out source |
| 32 | + uses: actions/checkout@v7 |
| 33 | + |
| 34 | + - name: Validate Gradle Wrapper |
| 35 | + uses: gradle/actions/wrapper-validation@v6 |
| 36 | + |
| 37 | + - name: Set up JDK ${{ env.JAVA_VERSION }} |
| 38 | + uses: actions/setup-java@v6 |
| 39 | + with: |
| 40 | + java-version: ${{ env.JAVA_VERSION }} |
| 41 | + distribution: 'microsoft' |
| 42 | + |
| 43 | + - name: Set up Gradle |
| 44 | + uses: gradle/actions/setup-gradle@v6 |
| 45 | + |
| 46 | + - name: Read gradle.properties |
| 47 | + run: | |
| 48 | + # Keeps the CurseForge ID defined in one place. |
| 49 | + prop() { grep -E "^$1\s*=" gradle.properties | cut -d= -f2- | tr -d '[:space:]'; } |
| 50 | + echo "CURSEFORGE_ID=$(prop curseforge_id)" >> "$GITHUB_ENV" |
| 51 | +
|
| 52 | + - name: Build and test |
| 53 | + run: | |
| 54 | + chmod +x ./gradlew |
| 55 | + ./gradlew clean check build |
| 56 | +
|
| 57 | + - name: Publish to Maven |
| 58 | + if: env.HAS_MAVEN == 'true' |
| 59 | + run: ./gradlew publish |
| 60 | + env: |
| 61 | + MAVEN_UPLOAD_URL: ${{ secrets.MAVEN_UPLOAD_URL }} |
| 62 | + MAVEN_UPLOAD_USERNAME: ${{ secrets.MAVEN_UPLOAD_USERNAME }} |
| 63 | + MAVEN_UPLOAD_PASSWORD: ${{ secrets.MAVEN_UPLOAD_PASSWORD }} |
| 64 | + |
| 65 | + # For additional properties and values that are not detected/set up here, you can read up on the docs here: |
| 66 | + # https://github.com/Kira-NT/mc-publish |
| 67 | + # I HEAVILY advise you read about this action, as this action can do a lot but also has a few quirks like changelog publishing not working right. |
| 68 | + - name: Publish to GitHub |
| 69 | + uses: Kira-NT/mc-publish@v3.3.2 |
| 70 | + with: |
| 71 | + github-token: ${{ github.token }} |
| 72 | + version: ${{ env.TAG }} |
| 73 | + # Main jar first so it becomes the primary file, sources/javadoc attached as extras. |
| 74 | + files: | |
| 75 | + build/libs/!(*-@(sources|javadoc)).jar |
| 76 | + build/libs/*-@(sources|javadoc).jar |
| 77 | +
|
| 78 | + - name: Publish to CurseForge |
| 79 | + if: env.HAS_CURSEFORGE == 'true' && env.CURSEFORGE_ID != '' |
| 80 | + uses: Kira-NT/mc-publish@v3.3.2 |
| 81 | + with: |
| 82 | + curseforge-token: ${{ secrets.CURSEFORGE_TOKEN }} |
| 83 | + # Read from curseforge_id in gradle.properties. |
| 84 | + curseforge-id: ${{ env.CURSEFORGE_ID }} |
| 85 | + version: ${{ env.TAG }} |
| 86 | + files: | |
| 87 | + build/libs/!(*-@(sources|javadoc)).jar |
| 88 | + build/libs/*-@(sources|javadoc).jar |
| 89 | + loaders: | |
| 90 | + neoforge |
| 91 | + environment: client | server |
| 92 | + java: ${{ env.JAVA_VERSION }} |
0 commit comments