|
| 1 | +name: release-modrinth |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*" |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + changelog: |
| 10 | + description: "Optional changelog text (overrides tag annotation)" |
| 11 | + required: false |
| 12 | + type: string |
| 13 | + version_type: |
| 14 | + description: "Modrinth version type" |
| 15 | + required: false |
| 16 | + default: "release" |
| 17 | + type: choice |
| 18 | + options: |
| 19 | + - release |
| 20 | + - beta |
| 21 | + - alpha |
| 22 | + status: |
| 23 | + description: "Modrinth visibility status" |
| 24 | + required: false |
| 25 | + default: "listed" |
| 26 | + type: choice |
| 27 | + options: |
| 28 | + - listed |
| 29 | + - unlisted |
| 30 | + - draft |
| 31 | + - archived |
| 32 | + featured: |
| 33 | + description: "Feature this version" |
| 34 | + required: false |
| 35 | + default: false |
| 36 | + type: boolean |
| 37 | + |
| 38 | +jobs: |
| 39 | + publish: |
| 40 | + runs-on: ubuntu-24.04 |
| 41 | + permissions: |
| 42 | + contents: read |
| 43 | + steps: |
| 44 | + - name: Checkout repository |
| 45 | + uses: actions/checkout@v4 |
| 46 | + with: |
| 47 | + fetch-depth: 0 |
| 48 | + |
| 49 | + - name: Set up JDK 21 |
| 50 | + uses: actions/setup-java@v4 |
| 51 | + with: |
| 52 | + java-version: "21" |
| 53 | + distribution: "microsoft" |
| 54 | + |
| 55 | + - name: Make release script executable |
| 56 | + run: chmod +x scripts/publish_modrinth.sh |
| 57 | + |
| 58 | + - name: Validate tag matches gradle.properties |
| 59 | + if: startsWith(github.ref, 'refs/tags/') |
| 60 | + run: | |
| 61 | + set -euo pipefail |
| 62 | + TAG_VERSION="${GITHUB_REF_NAME#v}" |
| 63 | + MOD_VERSION="$(awk -F= '$1=="mod_version"{print $2}' gradle.properties | tail -n1)" |
| 64 | + if [[ -z "${MOD_VERSION}" ]]; then |
| 65 | + echo "Could not read mod_version from gradle.properties" >&2 |
| 66 | + exit 1 |
| 67 | + fi |
| 68 | + if [[ "${TAG_VERSION}" != "${MOD_VERSION}" ]]; then |
| 69 | + echo "Tag version (${TAG_VERSION}) does not match mod_version (${MOD_VERSION})." >&2 |
| 70 | + exit 1 |
| 71 | + fi |
| 72 | +
|
| 73 | + - name: Build changelog file |
| 74 | + run: | |
| 75 | + set -euo pipefail |
| 76 | + if [[ "${{ github.event_name }}" == "workflow_dispatch" ]] && [[ -n "${{ inputs.changelog }}" ]]; then |
| 77 | + printf "%s\n" "${{ inputs.changelog }}" > .release-changelog.md |
| 78 | + exit 0 |
| 79 | + fi |
| 80 | +
|
| 81 | + if [[ "${{ github.ref_type }}" == "tag" ]]; then |
| 82 | + TAG_MSG="$(git for-each-ref "refs/tags/${GITHUB_REF_NAME}" --format='%(contents)')" |
| 83 | + if [[ -n "${TAG_MSG}" ]]; then |
| 84 | + printf "%s\n" "${TAG_MSG}" > .release-changelog.md |
| 85 | + exit 0 |
| 86 | + fi |
| 87 | + fi |
| 88 | +
|
| 89 | + printf "Automated release from GitHub Actions.\n" > .release-changelog.md |
| 90 | +
|
| 91 | + - name: Publish to Modrinth |
| 92 | + env: |
| 93 | + MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }} |
| 94 | + MODRINTH_VERSION_TYPE: ${{ inputs.version_type || 'release' }} |
| 95 | + MODRINTH_STATUS: ${{ inputs.status || 'listed' }} |
| 96 | + MODRINTH_FEATURED: ${{ inputs.featured || false }} |
| 97 | + run: | |
| 98 | + set -euo pipefail |
| 99 | + if [[ -z "${MODRINTH_TOKEN}" ]]; then |
| 100 | + echo "Missing MODRINTH_TOKEN secret." >&2 |
| 101 | + exit 1 |
| 102 | + fi |
| 103 | + scripts/publish_modrinth.sh --changelog-file .release-changelog.md |
0 commit comments