Skip to content

Commit 1b60641

Browse files
added automatic publication and moved to 2.5.1
1 parent 409e5d1 commit 1b60641

1 file changed

Lines changed: 88 additions & 46 deletions

File tree

‎.github/workflows/modrinth.yml‎

Lines changed: 88 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
name: Publish to Modrinth
1+
name: Publish to Modrinth and CurseForge
22

33
on:
44
workflow_dispatch:
55
inputs:
66
channel:
7-
description: 'Release channel on Modrinth'
7+
description: 'Release channel'
88
type: choice
99
options: [release, beta, alpha]
1010
default: release
1111
changelog:
12-
description: 'Changelog (Markdown)'
12+
description: 'Changelog (Markdown). Leave empty to use the GitHub release notes'
1313
type: string
1414
required: false
1515
default: ''
@@ -18,8 +18,15 @@ permissions:
1818
contents: read
1919

2020
jobs:
21-
modrinth:
21+
# Resolves versions, downloads the JAR once and shares it with both publish jobs.
22+
prepare:
2223
runs-on: ubuntu-latest
24+
outputs:
25+
mc: ${{ steps.versions.outputs.mc }}
26+
mc_family: ${{ steps.versions.outputs.mc_family }}
27+
mod: ${{ steps.versions.outputs.mod }}
28+
jar: ${{ steps.release.outputs.jar }}
29+
changelog: ${{ steps.release.outputs.changelog }}
2330
steps:
2431
- name: Checkout code
2532
uses: actions/checkout@v4
@@ -33,68 +40,103 @@ jobs:
3340
| sed 's/.*=\s*//' | tr -d '[:space:]')
3441
echo "mc=$MC" >> "$GITHUB_OUTPUT"
3542
echo "mod=$MOD" >> "$GITHUB_OUTPUT"
43+
# CurseForge groups versions by family, e.g. 1.21.1 -> "Minecraft 1.21"
44+
echo "mc_family=$(echo "$MC" | cut -d. -f1,2)" >> "$GITHUB_OUTPUT"
3645
37-
- name: Setup JDK 21
38-
uses: actions/setup-java@v4
39-
with:
40-
java-version: '21'
41-
distribution: 'temurin'
46+
# Release for v<mc>-<mod>; if it doesn't exist, use the latest release.
47+
- name: Download JAR and notes from GitHub release
48+
id: release
49+
env:
50+
GH_TOKEN: ${{ github.token }}
51+
TAG: v${{ steps.versions.outputs.mc }}-${{ steps.versions.outputs.mod }}
52+
INPUT_CHANGELOG: ${{ inputs.changelog }}
53+
run: |
54+
if ! gh release view "$TAG" >/dev/null 2>&1; then
55+
echo "No release for $TAG, falling back to latest release"
56+
TAG=$(gh release view --json tagName --jq .tagName 2>/dev/null || true)
57+
if [ -z "$TAG" ]; then
58+
echo "::error::No GitHub releases found in this repository"
59+
exit 1
60+
fi
61+
fi
62+
echo "Using release $TAG"
4263
43-
- name: Make Gradle wrapper executable
44-
run: chmod +x ./gradlew
64+
mkdir -p dist
65+
gh release download "$TAG" --pattern '*.jar' --dir dist
4566
46-
- name: Build
47-
run: ./gradlew build
67+
# Only the compiled mod JAR: skip -sources / -javadoc / -dev
68+
find dist -name '*.jar' \
69+
\( -name '*-sources.jar' -o -name '*-javadoc.jar' -o -name '*-dev.jar' -name '*-slim.jar' \) -delete
4870
49-
# Only the compiled mod JAR: skip -sources / -javadoc / -dev
50-
- name: Locate mod JAR
51-
id: jar
52-
run: |
53-
JARS=$(find build/libs -maxdepth 1 -name '*.jar' \
54-
! -name '*-sources.jar' ! -name '*-javadoc.jar' ! -name '*-dev.jar')
55-
COUNT=$(echo "$JARS" | grep -c . || true)
71+
COUNT=$(find dist -name '*.jar' | wc -l)
5672
if [ "$COUNT" -ne 1 ]; then
57-
echo "::error::Expected exactly 1 JAR in build/libs, found $COUNT"
58-
ls -l build/libs
73+
echo "::error::Expected exactly 1 JAR from release $TAG, found $COUNT"
74+
ls -l dist
5975
exit 1
6076
fi
61-
echo "path=$JARS" >> "$GITHUB_OUTPUT"
77+
echo "jar=$(find dist -name '*.jar')" >> "$GITHUB_OUTPUT"
6278
63-
# Typed changelog wins; otherwise release notes for this tag;
64-
# otherwise the latest release; otherwise empty. Never fails.
65-
- name: Resolve changelog
66-
id: changelog
67-
env:
68-
GH_TOKEN: ${{ github.token }}
69-
TAG: v${{ steps.versions.outputs.mc }}-${{ steps.versions.outputs.mod }}
70-
INPUT_CHANGELOG: ${{ inputs.changelog }}
71-
run: |
79+
# Typed changelog wins, otherwise the release notes
7280
if [ -n "$INPUT_CHANGELOG" ]; then
7381
BODY="$INPUT_CHANGELOG"
74-
elif BODY=$(gh release view "$TAG" --json body --jq .body 2>/dev/null); then
75-
echo "Using release notes from $TAG"
7682
else
77-
echo "No release for $TAG, falling back to latest release"
78-
BODY=$(gh release view --json body --jq .body 2>/dev/null || true)
83+
BODY=$(gh release view "$TAG" --json body --jq .body)
7984
fi
8085
{
81-
echo 'body<<CHANGELOG_EOF'
86+
echo 'changelog<<CHANGELOG_EOF'
8287
echo "$BODY"
8388
echo 'CHANGELOG_EOF'
8489
} >> "$GITHUB_OUTPUT"
8590
91+
- name: Share JAR with publish jobs
92+
uses: actions/upload-artifact@v4
93+
with:
94+
name: mod-jar
95+
path: dist/*.jar
96+
if-no-files-found: error
97+
98+
modrinth:
99+
needs: prepare
100+
runs-on: ubuntu-latest
101+
steps:
102+
- name: Download JAR
103+
uses: actions/download-artifact@v4
104+
with:
105+
name: mod-jar
106+
path: dist
107+
86108
- name: Publish to Modrinth
87109
uses: cloudnode-pro/modrinth-publish@v2
88110
with:
89111
token: ${{ secrets.MODRINTH_TOKEN }}
90112
project: ${{ vars.MODRINTH_ID }}
91-
name: ${{ steps.versions.outputs.mod }} (MC ${{ steps.versions.outputs.mc }})
92-
version: ${{ steps.versions.outputs.mod }}
113+
name: ${{ needs.prepare.outputs.mod }} (MC ${{ needs.prepare.outputs.mc }})
114+
version: ${{ needs.prepare.outputs.mod }}
93115
channel: ${{ inputs.channel }}
94-
changelog: ${{ steps.changelog.outputs.body }}
95-
loaders: neoforge
96-
game-versions: ${{ steps.versions.outputs.mc }}
97-
files: ${{ steps.jar.outputs.path }}
98-
# Uncomment if your mod needs Fabric API (replace with the real project ID):
99-
# dependencies: |-
100-
# [{ "project_id": "P7dR8mSH", "dependency_type": "required" }]
116+
changelog: ${{ needs.prepare.outputs.changelog }}
117+
loaders: forge
118+
game-versions: ${{ needs.prepare.outputs.mc }}
119+
files: ${{ needs.prepare.outputs.jar }}
120+
121+
curseforge:
122+
needs: prepare
123+
runs-on: ubuntu-latest
124+
steps:
125+
- name: Download JAR
126+
uses: actions/download-artifact@v4
127+
with:
128+
name: mod-jar
129+
path: dist
130+
131+
- name: Publish to CurseForge
132+
uses: itsmeow/curseforge-upload@v3
133+
with:
134+
token: ${{ secrets.CURSEFORGE_TOKEN }}
135+
project_id: ${{ vars.CURSEFORGE_ID }}
136+
game_endpoint: minecraft
137+
file_path: ${{ needs.prepare.outputs.jar }}
138+
display_name: ${{ needs.prepare.outputs.mod }} (MC ${{ needs.prepare.outputs.mc }})
139+
release_type: ${{ inputs.channel }}
140+
changelog: ${{ needs.prepare.outputs.changelog }}
141+
changelog_type: markdown
142+
game_versions: "Minecraft ${{ needs.prepare.outputs.mc_family }}:${{ needs.prepare.outputs.mc }},Java 20,Forge"

0 commit comments

Comments
 (0)