Skip to content

Commit c61d16a

Browse files
committed
reduce jar size, add metrics, add auto publishing to marketplace
1 parent 941f9da commit c61d16a

13 files changed

Lines changed: 1370 additions & 10 deletions

File tree

Lines changed: 248 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
1+
# .github/workflows/promote-release.yml
2+
3+
name: Promote Release
4+
5+
on:
6+
workflow_dispatch:
7+
inputs:
8+
source_tag:
9+
description: Existing build release tag to promote, for example v7.0.0-rc.1+build.7
10+
required: true
11+
type: string
12+
target_tag:
13+
description: Clean public release tag, for example v7.0.0-rc.1. Leave empty to strip +build.N automatically.
14+
required: false
15+
type: string
16+
publish_modrinth:
17+
description: Publish promoted release to Modrinth
18+
required: true
19+
default: true
20+
type: boolean
21+
publish_hangar:
22+
description: Publish promoted release to Hangar
23+
required: true
24+
default: true
25+
type: boolean
26+
27+
permissions:
28+
contents: write
29+
30+
concurrency:
31+
group: promote-release-${{ inputs.source_tag }}-${{ inputs.target_tag }}
32+
cancel-in-progress: false
33+
34+
jobs:
35+
promote:
36+
name: Promote and publish release
37+
runs-on: ubuntu-latest
38+
timeout-minutes: 20
39+
40+
steps:
41+
- name: Resolve promotion metadata
42+
id: meta
43+
shell: bash
44+
env:
45+
GH_TOKEN: ${{ github.token }}
46+
run: |
47+
set -euo pipefail
48+
49+
source_tag="${{ inputs.source_tag }}"
50+
target_tag="${{ inputs.target_tag }}"
51+
52+
if [[ "$source_tag" != v* ]]; then
53+
source_tag="v${source_tag}"
54+
fi
55+
56+
if [[ -z "$target_tag" ]]; then
57+
if [[ "$source_tag" != *+build.* ]]; then
58+
echo "target_tag is required when source_tag does not contain +build." >&2
59+
exit 1
60+
fi
61+
62+
target_tag="${source_tag%%+build.*}"
63+
fi
64+
65+
if [[ "$target_tag" != v* ]]; then
66+
target_tag="v${target_tag}"
67+
fi
68+
69+
if [[ "$target_tag" == *+build.* ]]; then
70+
echo "target_tag must be a clean public tag without +build metadata." >&2
71+
exit 1
72+
fi
73+
74+
if [[ "$source_tag" == "$target_tag" ]]; then
75+
echo "source_tag and target_tag must be different." >&2
76+
exit 1
77+
fi
78+
79+
if ! gh release view "$source_tag" --repo "${GITHUB_REPOSITORY}" >/dev/null 2>&1; then
80+
echo "Source release does not exist: ${source_tag}" >&2
81+
exit 1
82+
fi
83+
84+
if gh release view "$target_tag" --repo "${GITHUB_REPOSITORY}" >/dev/null 2>&1; then
85+
echo "Target release already exists: ${target_tag}" >&2
86+
exit 1
87+
fi
88+
89+
source_commit="$(
90+
gh release view "$source_tag" \
91+
--repo "${GITHUB_REPOSITORY}" \
92+
--json targetCommitish \
93+
--jq '.targetCommitish'
94+
)"
95+
96+
if [[ -z "$source_commit" || "$source_commit" == "null" ]]; then
97+
echo "Could not resolve target commit from source release: ${source_tag}" >&2
98+
exit 1
99+
fi
100+
101+
source_url="$(
102+
gh release view "$source_tag" \
103+
--repo "${GITHUB_REPOSITORY}" \
104+
--json url \
105+
--jq '.url'
106+
)"
107+
108+
target_version="${target_tag#v}"
109+
110+
github_prerelease="false"
111+
modrinth_channel="release"
112+
hangar_channel="Release"
113+
114+
if [[ "$target_version" == *alpha* ]]; then
115+
github_prerelease="true"
116+
modrinth_channel="alpha"
117+
hangar_channel="Alpha"
118+
elif [[ "$target_version" == *-* ]]; then
119+
github_prerelease="true"
120+
modrinth_channel="beta"
121+
hangar_channel="Beta"
122+
fi
123+
124+
echo "source_tag=${source_tag}" >> "$GITHUB_OUTPUT"
125+
echo "target_tag=${target_tag}" >> "$GITHUB_OUTPUT"
126+
echo "target_version=${target_version}" >> "$GITHUB_OUTPUT"
127+
echo "source_commit=${source_commit}" >> "$GITHUB_OUTPUT"
128+
echo "source_url=${source_url}" >> "$GITHUB_OUTPUT"
129+
echo "github_prerelease=${github_prerelease}" >> "$GITHUB_OUTPUT"
130+
echo "modrinth_channel=${modrinth_channel}" >> "$GITHUB_OUTPUT"
131+
echo "hangar_channel=${hangar_channel}" >> "$GITHUB_OUTPUT"
132+
133+
- name: Download source release jar
134+
id: asset
135+
shell: bash
136+
env:
137+
GH_TOKEN: ${{ github.token }}
138+
run: |
139+
set -euo pipefail
140+
141+
mkdir -p dist/source dist/promoted
142+
143+
gh release download "${{ steps.meta.outputs.source_tag }}" \
144+
--repo "${GITHUB_REPOSITORY}" \
145+
--pattern "HeadDB-*.jar" \
146+
--dir dist/source
147+
148+
mapfile -t jars < <(find dist/source -maxdepth 1 -type f -name 'HeadDB-*.jar' | sort)
149+
150+
if [[ "${#jars[@]}" -ne 1 ]]; then
151+
echo "Expected exactly one HeadDB jar in source release, found ${#jars[@]}." >&2
152+
printf '%s\n' "${jars[@]}" >&2
153+
exit 1
154+
fi
155+
156+
promoted_jar="dist/promoted/HeadDB-${{ steps.meta.outputs.target_version }}.jar"
157+
cp "${jars[0]}" "$promoted_jar"
158+
159+
echo "jar=${promoted_jar}" >> "$GITHUB_OUTPUT"
160+
161+
- name: Create release notes
162+
shell: bash
163+
run: |
164+
set -euo pipefail
165+
166+
cat > release-notes.md <<'EOF'
167+
HeadDB ${{ steps.meta.outputs.target_version }}
168+
169+
This release promotes an already-built GitHub release artifact.
170+
171+
Source build: ${{ steps.meta.outputs.source_tag }}
172+
Source release: ${{ steps.meta.outputs.source_url }}
173+
Source commit: ${{ steps.meta.outputs.source_commit }}
174+
175+
The attached jar is the promoted jar from the source build release.
176+
EOF
177+
178+
- name: Create promoted GitHub release
179+
shell: bash
180+
env:
181+
GH_TOKEN: ${{ github.token }}
182+
run: |
183+
set -euo pipefail
184+
185+
args=(
186+
"${{ steps.meta.outputs.target_tag }}"
187+
"${{ steps.asset.outputs.jar }}"
188+
--repo "${GITHUB_REPOSITORY}"
189+
--target "${{ steps.meta.outputs.source_commit }}"
190+
--title "HeadDB ${{ steps.meta.outputs.target_version }}"
191+
--notes-file release-notes.md
192+
)
193+
194+
if [[ "${{ steps.meta.outputs.github_prerelease }}" == "true" ]]; then
195+
args+=(--prerelease)
196+
fi
197+
198+
gh release create "${args[@]}"
199+
200+
- name: Publish to Modrinth
201+
if: ${{ inputs.publish_modrinth }}
202+
uses: cloudnode-pro/modrinth-publish@v2
203+
with:
204+
token: ${{ secrets.MODRINTH_TOKEN }}
205+
project: ${{ vars.MODRINTH_PROJECT_ID }}
206+
version: ${{ steps.meta.outputs.target_version }}
207+
name: HeadDB ${{ steps.meta.outputs.target_version }}
208+
channel: ${{ steps.meta.outputs.modrinth_channel }}
209+
changelog: |
210+
HeadDB ${{ steps.meta.outputs.target_version }}
211+
212+
Promoted from ${{ steps.meta.outputs.source_tag }}.
213+
214+
Source release: ${{ steps.meta.outputs.source_url }}
215+
loaders: |-
216+
paper
217+
folia
218+
game-versions: |-
219+
1.21.x
220+
26.1.x
221+
26.2.x
222+
files: ${{ steps.asset.outputs.jar }}
223+
224+
- name: Publish to Hangar
225+
if: ${{ inputs.publish_hangar }}
226+
uses: benwoo1110/hangar-upload-action@v1
227+
with:
228+
api_token: ${{ secrets.HANGAR_API_TOKEN }}
229+
slug: ${{ vars.HANGAR_PROJECT_SLUG }}
230+
version: ${{ steps.meta.outputs.target_version }}
231+
channel: ${{ steps.meta.outputs.hangar_channel }}
232+
description: |
233+
HeadDB ${{ steps.meta.outputs.target_version }}
234+
235+
Promoted from ${{ steps.meta.outputs.source_tag }}.
236+
237+
Source release: ${{ steps.meta.outputs.source_url }}
238+
files: |-
239+
[
240+
{
241+
"path": "${{ steps.asset.outputs.jar }}",
242+
"platforms": ["PAPER"]
243+
}
244+
]
245+
platform_dependencies: |-
246+
{
247+
"PAPER": ["1.21.x", "26.1.x", "26.2.x"]
248+
}
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
name: Publish Marketplaces
2+
3+
on:
4+
release:
5+
types:
6+
- published
7+
workflow_dispatch:
8+
inputs:
9+
tag:
10+
description: GitHub release tag to publish, for example v7.0.0-rc.1
11+
required: true
12+
type: string
13+
14+
permissions:
15+
contents: read
16+
17+
concurrency:
18+
group: publish-marketplaces-${{ github.event.release.tag_name || inputs.tag }}
19+
cancel-in-progress: false
20+
21+
jobs:
22+
publish:
23+
name: Publish marketplace versions
24+
if: >-
25+
${{
26+
github.event_name == 'workflow_dispatch' ||
27+
!contains(github.event.release.tag_name, '+build.')
28+
}}
29+
runs-on: ubuntu-latest
30+
timeout-minutes: 20
31+
32+
steps:
33+
- name: Resolve release metadata
34+
id: meta
35+
shell: bash
36+
run: |
37+
set -euo pipefail
38+
39+
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
40+
tag="${{ inputs.tag }}"
41+
else
42+
tag="${{ github.event.release.tag_name }}"
43+
fi
44+
45+
version="${tag#v}"
46+
base_version="${version%%+*}"
47+
48+
if [[ "$base_version" == *alpha* ]]; then
49+
modrinth_channel="alpha"
50+
hangar_channel="Alpha"
51+
elif [[ "$base_version" == *-* ]]; then
52+
modrinth_channel="beta"
53+
hangar_channel="Beta"
54+
else
55+
modrinth_channel="release"
56+
hangar_channel="Release"
57+
fi
58+
59+
echo "tag=${tag}" >> "$GITHUB_OUTPUT"
60+
echo "version=${version}" >> "$GITHUB_OUTPUT"
61+
echo "base_version=${base_version}" >> "$GITHUB_OUTPUT"
62+
echo "modrinth_channel=${modrinth_channel}" >> "$GITHUB_OUTPUT"
63+
echo "hangar_channel=${hangar_channel}" >> "$GITHUB_OUTPUT"
64+
65+
- name: Download GitHub release jar
66+
id: asset
67+
shell: bash
68+
env:
69+
GH_TOKEN: ${{ github.token }}
70+
run: |
71+
set -euo pipefail
72+
73+
mkdir -p dist
74+
75+
gh release download "${{ steps.meta.outputs.tag }}" \
76+
--repo "${GITHUB_REPOSITORY}" \
77+
--pattern "HeadDB-*.jar" \
78+
--dir dist
79+
80+
jar_path="$(find dist -maxdepth 1 -type f -name 'HeadDB-*.jar' | sort | head -n 1)"
81+
82+
if [[ -z "$jar_path" ]]; then
83+
echo "No HeadDB jar found in release ${{ steps.meta.outputs.tag }}." >&2
84+
exit 1
85+
fi
86+
87+
echo "jar=${jar_path}" >> "$GITHUB_OUTPUT"
88+
echo "Downloaded ${jar_path}"
89+
90+
- name: Publish to Modrinth
91+
uses: cloudnode-pro/modrinth-publish@v2
92+
with:
93+
token: ${{ secrets.MODRINTH_TOKEN }}
94+
project: ${{ vars.MODRINTH_PROJECT_ID }}
95+
version: ${{ steps.meta.outputs.version }}
96+
name: HeadDB ${{ steps.meta.outputs.version }}
97+
channel: ${{ steps.meta.outputs.modrinth_channel }}
98+
changelog: ${{ github.event.release.body || format('Published HeadDB {0}.', steps.meta.outputs.version) }}
99+
loaders: |-
100+
paper
101+
folia
102+
game-versions: |-
103+
1.21.x
104+
26.1.x
105+
files: ${{ steps.asset.outputs.jar }}
106+
107+
- name: Publish to Hangar
108+
uses: benwoo1110/hangar-upload-action@v1
109+
with:
110+
api_token: ${{ secrets.HANGAR_API_TOKEN }}
111+
slug: ${{ vars.HANGAR_PROJECT_SLUG }}
112+
version: ${{ steps.meta.outputs.version }}
113+
channel: ${{ steps.meta.outputs.hangar_channel }}
114+
description: ${{ github.event.release.body || format('Published HeadDB {0}.', steps.meta.outputs.version) }}
115+
files: |-
116+
[
117+
{
118+
"path": "${{ steps.asset.outputs.jar }}",
119+
"platforms": ["PAPER"]
120+
}
121+
]
122+
platform_dependencies: |-
123+
{
124+
"PAPER": ["1.21.x", "26.1.x"]
125+
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ Add the API module as a dependency if you want to integrate with HeadDB from ano
8383
<dependency>
8484
<groupId>io.github.silentdevelopment.headdb</groupId>
8585
<artifactId>headdb-api</artifactId>
86-
<version>7.0.0-rc.1</version>
86+
<version>7.0.0-rc.2</version>
8787
<scope>provided</scope>
8888
</dependency>
8989
```

headdb-api/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>io.github.silentdevelopment.headdb</groupId>
88
<artifactId>HeadDB</artifactId>
9-
<version>7.0.0-rc.1</version>
9+
<version>7.0.0-rc.2</version>
1010
</parent>
1111

1212
<artifactId>headdb-api</artifactId>

0 commit comments

Comments
 (0)