Skip to content

Commit be6fd85

Browse files
committed
Add publish-curseforge GitHub Actions workflow.
Introduces a new workflow that runs when a new build has been published on GitHub Releases. It converts the release notes to CurseForge HTML and sends it to CurseForge along with the jar-file. Note: The workflow currently relies on the version string being appended to the filename of the jar-file. Without it, the file reference in the `curl` request that uploads the build would need to change. The workflow references a new secret, `CURSEFORGE_TOKEN`, which is just an API key for the CurseForge API. The token was created on CurseForge under profile settings (My API Tokens). In order to properly upload a new build to CurseForge, we need a list of "game version IDs", which isn't completely trivial. The API gives us a means of looking up _all_ Minecraft game version IDs, but we then have to manually filter out the ones that don't apply to Bukkit plugins, as there are duplicate entries for each Minecraft version, and only some of them work for Bukkit plugins (which turns out to be the ones with game version type ID 1). The structure of the `metadata` field combined with how incredibly difficult bash can be to work with has resulted in some gnarly text processing trying to filter the JSON response and turning it into a list for use in the `jq` template, but it gets the job done. The CurseForge base URL and project ID are both hardcoded, and things would probably be cleaner if they were made into variables, but we don't need this workflow anywhere else, so it's fine for now. The workflow can be invoked directly via the `workflow_dispatch` event, which might come in handy if something in the pipeline breaks. Lots of inspiration was found in the probably really great GitHub Action `curseforge-upload` [1]. We could have probably just used that, but it's nice to have full control of the process. At any rate, thanks to itsmeow and NotMyFault for publishing their work. --- [1] https://github.com/itsmeow/curseforge-upload
1 parent b881943 commit be6fd85

1 file changed

Lines changed: 77 additions & 0 deletions

File tree

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: publish-curseforge
2+
3+
on:
4+
release:
5+
types:
6+
- 'released'
7+
workflow_dispatch:
8+
inputs:
9+
tag_name:
10+
description: 'The tag name of the release to publish'
11+
required: true
12+
type: string
13+
14+
jobs:
15+
publish:
16+
runs-on: ubuntu-latest
17+
18+
permissions:
19+
contents: read
20+
21+
env:
22+
TAG_NAME: ${{ github.event.release.tag_name || inputs.tag_name }}
23+
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v4
27+
28+
- name: Download release assets
29+
run: gh release download "${TAG_NAME}"
30+
env:
31+
GITHUB_TOKEN: ${{ github.token }}
32+
33+
- name: Publish to CurseForge
34+
run: |
35+
echo 'Extract release notes'
36+
changelog=$(scripts/extract-release-notes -f curse "${TAG_NAME}")
37+
38+
echo 'Look up game version IDs'
39+
game_version_type_id=1
40+
game_version_names='"1.20","1.19","1.18","1.17","1.16","1.15","1.14","1.13"'
41+
42+
type_condition="(.gameVersionTypeID == ${game_version_type_id})"
43+
name_condition="(.name | startswith(${game_version_names}))"
44+
45+
game_version_ids=$(
46+
curl -s -X GET 'https://minecraft.curseforge.com/api/game/versions' \
47+
-H "X-Api-Token: ${{ secrets.CURSEFORGE_TOKEN }}" \
48+
| jq -c ".[] | select(${type_condition} and ${name_condition}) | .id" \
49+
| paste -sd, - \
50+
)
51+
52+
echo 'Create metadata file'
53+
cat << EOF > metadata.jq
54+
{
55+
changelog: \$changelog,
56+
changelogType: "html",
57+
displayName: \$displayName,
58+
gameVersions: \$gameVersions,
59+
releaseType: "beta"
60+
}
61+
EOF
62+
63+
jq -c -n \
64+
--arg changelog "${changelog}" \
65+
--arg displayName "MobArena v${TAG_NAME}" \
66+
--argjson gameVersions "[${game_version_ids}]" \
67+
-f metadata.jq \
68+
> metadata.json
69+
70+
echo 'Publish build to CurseForge'
71+
base_url='https://minecraft.curseforge.com'
72+
project_id=31265
73+
74+
curl -s -X POST "${base_url}/api/projects/${project_id}/upload-file" \
75+
-H "X-Api-Token: ${{ secrets.CURSEFORGE_TOKEN }}" \
76+
-F 'metadata=<metadata.json' \
77+
-F "file=@MobArena-${TAG_NAME}.jar"

0 commit comments

Comments
 (0)