Skip to content

Commit 3897bab

Browse files
committed
feat: registry publishing in workflow
1 parent 2f98560 commit 3897bab

File tree

1 file changed

+144
-26
lines changed

1 file changed

+144
-26
lines changed

.github/workflows/release-dev.yml

Lines changed: 144 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,37 @@
1-
name: Release on Modrinth
1+
name: Release and Publish
22

33
on:
44
push:
55
branches:
66
- main
77
workflow_dispatch:
88

9+
env:
10+
APP_SLUG: cloud-api-plugin
11+
REGISTRY_URL: https://registry.simplecloud.app
12+
MINECRAFT_VERSIONS: >-
13+
[
14+
"1.20",
15+
"1.20.1",
16+
"1.20.2",
17+
"1.20.3",
18+
"1.20.4",
19+
"1.20.5",
20+
"1.20.6",
21+
"1.21",
22+
"1.21.1",
23+
"1.21.2",
24+
"1.21.3",
25+
"1.21.4",
26+
"1.21.5"
27+
]
28+
929
jobs:
1030
build:
11-
name: Build ShadowJars and Create Release
1231
runs-on: ubuntu-latest
13-
32+
outputs:
33+
gradle_version: ${{ steps.versions.outputs.gradle_version }}
34+
commit_hash: ${{ steps.versions.outputs.commit_hash }}
1435
steps:
1536
- name: Checkout repository
1637
uses: actions/checkout@v3
@@ -36,55 +57,152 @@ jobs:
3657
- name: Make gradlew executable
3758
run: chmod +x ./gradlew
3859

60+
- name: Get Versions
61+
id: versions
62+
run: |
63+
echo "gradle_version=$(./gradlew properties -q | grep "version:" | awk '{print $2}')" >> $GITHUB_OUTPUT
64+
echo "commit_hash=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
65+
3966
- name: Build ShadowJars
4067
run: ./gradlew clean build shadowJar
4168

42-
- name: Get Gradle Version
43-
id: gradle_version
44-
run: echo "GRADLE_VERSION=$(./gradlew properties -q | grep "version:" | awk '{print $2}')" >> $GITHUB_ENV
69+
- name: Upload artifacts
70+
uses: actions/upload-artifact@v3
71+
with:
72+
name: build-artifacts
73+
path: |
74+
platform/*/build/libs/*.jar
4575
46-
- name: Get Commit Hash
47-
id: commit_hash
48-
run: echo "COMMIT_HASH=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
76+
publish-registry:
77+
needs: build
78+
runs-on: ubuntu-latest
79+
steps:
80+
- name: Download artifacts
81+
uses: actions/download-artifact@v3
82+
with:
83+
name: build-artifacts
84+
path: artifacts
4985

50-
- name: Publish to SimpleCloud Repository
51-
run: ./gradlew publishMavenJavaPublicationToSimplecloudRepository
52-
env:
53-
COMMIT_HASH: ${{ env.COMMIT_HASH }}
54-
SIMPLECLOUD_USERNAME: ${{ secrets.SIMPLECLOUD_USERNAME }}
55-
SIMPLECLOUD_PASSWORD: ${{ secrets.SIMPLECLOUD_PASSWORD }}
86+
- name: Create Registry Release
87+
id: create_registry_release
88+
run: |
89+
response=$(curl -X POST \
90+
-H "Authorization: Bearer ${{ secrets.REGISTRY_TOKEN }}" \
91+
-H "Content-Type: application/json" \
92+
"${REGISTRY_URL}/v1/applications/${APP_SLUG}/releases" \
93+
-d '{
94+
"version": "'"${{ needs.build.outputs.gradle_version }}"'",
95+
"manual_update": false
96+
}')
97+
echo "Response: $response"
98+
APP_ID=$(echo $response | jq -r '.release.application_id')
99+
echo "APP_ID=$APP_ID" >> $GITHUB_ENV
100+
101+
- name: Upload to Registry
102+
run: |
103+
# Upload Spigot Platform
104+
curl -X POST \
105+
-H "Authorization: Bearer ${{ secrets.REGISTRY_TOKEN }}" \
106+
-H "Content-Type: multipart/form-data" \
107+
-F "file=@artifacts/platform/spigot/build/libs/spigot.jar" \
108+
-F "platform=minecraft_plugin" \
109+
-F "arch=spigot" \
110+
-F "platform_versions=${{ env.MINECRAFT_VERSIONS }}" \
111+
"${REGISTRY_URL}/v1/applications/${APP_ID}/releases/${{ needs.build.outputs.gradle_version }}/files"
112+
113+
# Upload Paper Platform (same jar as Spigot)
114+
curl -X POST \
115+
-H "Authorization: Bearer ${{ secrets.REGISTRY_TOKEN }}" \
116+
-H "Content-Type: multipart/form-data" \
117+
-F "file=@artifacts/platform/spigot/build/libs/spigot.jar" \
118+
-F "platform=minecraft_plugin" \
119+
-F "arch=paper" \
120+
-F "platform_versions=${{ env.MINECRAFT_VERSIONS }}" \
121+
"${REGISTRY_URL}/v1/applications/${APP_ID}/releases/${{ needs.build.outputs.gradle_version }}/files"
122+
123+
# Upload BungeeCord Platform
124+
curl -X POST \
125+
-H "Authorization: Bearer ${{ secrets.REGISTRY_TOKEN }}" \
126+
-H "Content-Type: multipart/form-data" \
127+
-F "file=@artifacts/platform/bungeecord/build/libs/bungeecord.jar" \
128+
-F "platform=minecraft_plugin" \
129+
-F "arch=bungeecord" \
130+
-F "platform_versions=${{ env.MINECRAFT_VERSIONS }}" \
131+
"${REGISTRY_URL}/v1/applications/${APP_ID}/releases/${{ needs.build.outputs.gradle_version }}/files"
132+
133+
# Upload Velocity Platform
134+
curl -X POST \
135+
-H "Authorization: Bearer ${{ secrets.REGISTRY_TOKEN }}" \
136+
-H "Content-Type: multipart/form-data" \
137+
-F "file=@artifacts/platform/velocity/build/libs/velocity.jar" \
138+
-F "platform=minecraft_plugin" \
139+
-F "arch=velocity" \
140+
-F "platform_versions=${{ env.MINECRAFT_VERSIONS }}" \
141+
"${REGISTRY_URL}/v1/applications/${APP_ID}/releases/${{ needs.build.outputs.gradle_version }}/files"
142+
143+
publish-modrinth:
144+
needs: build
145+
runs-on: ubuntu-latest
146+
steps:
147+
- name: Checkout repository
148+
uses: actions/checkout@v3
149+
with:
150+
ref: main
151+
152+
- name: Set up JDK 21
153+
uses: actions/setup-java@v3
154+
with:
155+
distribution: 'adopt'
156+
java-version: '21'
157+
158+
- name: Download artifacts
159+
uses: actions/download-artifact@v3
160+
with:
161+
name: build-artifacts
162+
path: platform
163+
164+
- name: Make gradlew executable
165+
run: chmod +x ./gradlew
56166

57167
- name: Publish to Modrinth
58168
run: ./gradlew modrinth && ./gradlew modrinthSyncBody
59169
env:
60-
COMMIT_HASH: ${{ env.COMMIT_HASH }}
170+
COMMIT_HASH: ${{ needs.build.outputs.commit_hash }}
61171
MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }}
62172

63-
- name: Create Release
173+
create-github-release:
174+
needs: [build, publish-registry, publish-modrinth]
175+
runs-on: ubuntu-latest
176+
steps:
177+
- name: Download artifacts
178+
uses: actions/download-artifact@v3
179+
with:
180+
name: build-artifacts
181+
path: artifacts
182+
183+
- name: Create GitHub Release
64184
id: create_release
65185
uses: actions/create-release@v1
66186
with:
67-
tag_name: v${{ env.GRADLE_VERSION }}-dev.${{ env.COMMIT_HASH }}
68-
release_name: v${{ env.GRADLE_VERSION }}-dev.${{ env.COMMIT_HASH }}
187+
tag_name: v${{ needs.build.outputs.gradle_version }}-dev.${{ needs.build.outputs.commit_hash }}
188+
release_name: v${{ needs.build.outputs.gradle_version }}-dev.${{ needs.build.outputs.commit_hash }}
69189
draft: false
70190
prerelease: true
71191
commitish: main
72192
body: |
73-
This release contains dev builds for all Gradle modules.
193+
This release contains dev builds for all platform modules.
74194
env:
75195
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
76196

77-
- name: Upload ShadowJars to Release
197+
- name: Upload JARs to GitHub Release
78198
run: |
79-
# Find JAR files in any submodule's build/libs directory
80-
for jar in $(find . -type f -name "*.jar" -path "*/build/libs/*.jar" -not -path "./build/libs/*"); do
81-
# Check if the filename contains a version number (e.g., a dash followed by numbers)
199+
for jar in $(find ./artifacts -type f -name "*.jar"); do
82200
if [[ $(basename "$jar") =~ -[0-9]+\.[0-9]+ ]]; then
83201
echo "Skipping $jar due to version number"
84202
else
85203
echo "Uploading $jar"
86-
gh release upload v${{ env.GRADLE_VERSION }}-dev.${{ env.COMMIT_HASH }} "$jar"
204+
gh release upload v${{ needs.build.outputs.gradle_version }}-dev.${{ needs.build.outputs.commit_hash }} "$jar"
87205
fi
88206
done
89207
env:
90-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
208+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)