Skip to content

Commit 725fad7

Browse files
committed
build: better GH Actions publishing
including choice of where to publish, and optional skipping of tagging, and proper errors in CI when no auth for the mod host
1 parent 298c76b commit 725fad7

3 files changed

Lines changed: 73 additions & 14 deletions

File tree

.github/workflows/publish.yml

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,32 @@ name: Publish Release
55

66
on:
77
workflow_dispatch:
8+
inputs:
9+
abort_on_tag_conflict:
10+
description: 'Abort if tag already exists'
11+
required: true
12+
type: boolean
13+
default: true
14+
publish_github_packages:
15+
description: 'Publish to GitHub Packages'
16+
required: true
17+
type: boolean
18+
default: true
19+
publish_modrinth:
20+
description: 'Publish to Modrinth'
21+
required: true
22+
type: boolean
23+
default: true
24+
publish_curseforge:
25+
description: 'Publish to CurseForge'
26+
required: true
27+
type: boolean
28+
default: true
29+
publish_github_release:
30+
description: 'Publish GitHub Release'
31+
required: true
32+
type: boolean
33+
default: true
834

935
env:
1036
JAVA_VERSION: 21
@@ -37,22 +63,25 @@ jobs:
3763
echo "Extracted minecraft version: $MC_VERSION"
3864
echo "Tag will be: $TAG"
3965
40-
- name: ❌ Check if tag already exists
41-
run: |
42-
if git ls-remote --tags origin | grep -q "refs/tags/${{ steps.version.outputs.tag }}$"; then
43-
echo "❌ Tag ${{ steps.version.outputs.tag }} already exists!"
44-
echo "Please update the mod_version in gradle.properties to create a new release."
45-
exit 1
46-
fi
47-
echo "✅ Tag ${{ steps.version.outputs.tag }} does not exist, proceeding..."
48-
4966
- name: 🏷️ Create and push tag
5067
run: |
5168
git config user.name "github-actions[bot]"
5269
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
53-
git tag ${{ steps.version.outputs.tag }}
54-
git push origin ${{ steps.version.outputs.tag }}
55-
echo "✅ Created and pushed tag: ${{ steps.version.outputs.tag }}"
70+
71+
# Check if tag already exists remotely
72+
if git ls-remote --tags origin | grep -q "refs/tags/${{ steps.version.outputs.tag }}$"; then
73+
if [ "${{ inputs.abort_on_tag_conflict }}" = "true" ]; then
74+
echo "❌ Tag ${{ steps.version.outputs.tag }} already exists!"
75+
echo "Please update the mod_version in gradle.properties to create a new release."
76+
exit 1
77+
else
78+
echo "⚠️ Tag ${{ steps.version.outputs.tag }} already exists, skipping tag creation"
79+
fi
80+
else
81+
git tag ${{ steps.version.outputs.tag }}
82+
git push origin ${{ steps.version.outputs.tag }}
83+
echo "✅ Created and pushed tag: ${{ steps.version.outputs.tag }}"
84+
fi
5685
5786
- name: 🛂 Validate Gradle wrapper
5887
uses: gradle/actions/wrapper-validation@v4
@@ -111,29 +140,33 @@ jobs:
111140
path: '**/build/reports/'
112141

113142
- name: 📤 Publish to GitHub Packages
143+
if: inputs.publish_github_packages
114144
env:
115145
GITHUB_ACTOR: ${{ github.actor }}
116146
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
117147
IS_PIPELINE: true
118148
run: gradle publishMavenJavaPublicationToGitHubRepository
119149

120150
- name: 📤 Publish to Modrinth
151+
if: inputs.publish_modrinth
121152
env:
122153
MODRINTH: ${{ secrets.MODRINTH }}
123154
IS_PIPELINE: true
124155
run: gradle publishModrinth
125156

126157
- name: 📤 Publish to CurseForge
158+
if: inputs.publish_curseforge
127159
env:
128160
CURSEFORGE: ${{ secrets.CURSEFORGE }}
129161
IS_PIPELINE: true
130162
run: gradle publishCurseforge
131163

132164
- name: 📤 Create GitHub Release
165+
if: inputs.publish_github_release
133166
env:
134167
GITHUB: ${{ secrets.GITHUB_TOKEN }}
135168
IS_PIPELINE: true
136-
run: gradle publishGithub
169+
run: gradle publishGitHub
137170

138171
- name: 🧨 Cleanup Gradle cache
139172
run: |

build.gradle

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,32 @@ publisher {
248248
}
249249
}
250250

251+
tasks.named('publishCurseforge').configure {
252+
doFirst {
253+
def key = getenv('CURSEFORGE')
254+
if (key == 'NOT FOUND' || key.isEmpty()) {
255+
throw new GradleException("CURSEFORGE API key is required for publishing to CurseForge")
256+
}
257+
}
258+
}
259+
260+
tasks.named('publishModrinth').configure {
261+
doFirst {
262+
def key = getenv('MODRINTH')
263+
if (key == 'NOT FOUND' || key.isEmpty()) {
264+
throw new GradleException("MODRINTH API key is required for publishing to Modrinth")
265+
}
266+
}
267+
}
268+
269+
tasks.named('publishGitHub').configure {
270+
doFirst {
271+
def key = getenv('GITHUB')
272+
if (key == 'NOT FOUND' || key.isEmpty()) {
273+
throw new GradleException("GITHUB API key is required for publishing to GitHub")
274+
}
275+
}
276+
}
251277

252278
generatePomFileForMavenJavaPublication {}
253279

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fabric_version=0.133.0+1.21.8
1414
# Mod Properties
1515
mod_name = Essential Commands
1616
mod_id = essential_commands
17-
mod_version = 0.38.5
17+
mod_version = 0.38.5-joinpoints2
1818
# TODO @1.0.0: migrate to dev.jpcode
1919
maven_group = com.fibermc
2020
archives_base_name = essential_commands

0 commit comments

Comments
 (0)