-
Notifications
You must be signed in to change notification settings - Fork 13
254 lines (245 loc) · 11.8 KB
/
publish.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
name: _step.publish
on:
workflow_call:
inputs:
publish_platform_channel:
type: string
required: true
publish_type:
type: string
required: true
jobs:
generate_matrix:
uses: ./.github/workflows/generate_matrix.yml
release_core:
runs-on: ubuntu-24.04
# Allow the mod publish step to add assets to release
# https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token
permissions:
contents: write
outputs:
commit_count: ${{ steps.shared_publish_info.outputs.commit_count }}
github_changelog: ${{ steps.changelog.outputs.result }}
github_tag: ${{ steps.shared_publish_info.outputs.github_tag }}
mod_name: ${{ steps.shared_publish_info.outputs.mod_name }}
mod_version: ${{ steps.shared_publish_info.outputs.mod_version }}
mod_full_version: ${{ steps.shared_publish_info.outputs.mod_version }}
release_title: ${{ steps.shared_publish_info.outputs.release_title }}
short_sha: ${{ steps.shared_publish_info.outputs.short_sha }}
steps:
- name: Checkout the sources
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: build-artifacts
path: build-artifacts
- name: Read Properties mod info
id: mod_info
uses: christian-draeger/[email protected]
with:
path: gradle.properties
properties: 'mod.name mod.version'
- name: Get shared properties
id: shared_publish_info
env:
REPO_OWNER: ${{ github.repository_owner }}
run: |
short_sha=$(echo ${GITHUB_SHA} | cut -c1-7)
commit_count=$(git log | grep -e '^commit [a-zA-Z0-9]*' | wc -l)
mod_name=${{ steps.mod_info.outputs.mod-name }}
mod_version=${{ steps.mod_info.outputs.mod-version }}
mod_full_version="$mod_version.$commit_count+$short_sha"
if [ "${{ inputs.publish_type }}" == 'release' ]
then
github_tag="${{ github.ref }}"
release_title="${{ github.event.release.name }}"
elif [ "${{ inputs.publish_type }}" == "dev" ]
then
if [ "$REPO_OWNER" == 'Hendrix-Shen' ]
then
github_tag="${{ github.ref_name }}.$commit_count"
release_title="[CI#${{ github.run_number }}]$mod_name $mod_full_version"
elif [ "$REPO_OWNER" == 'Nyan-Work' ]
then
github_tag="nyan-work/${{ github.ref_name }}.$commit_count"
release_title="[CI#${{ github.run_number }}]$mod_name $mod_full_version (Nyan)"
else
github_tag="$REPO_OWNER/${{ github.ref_name }}.$commit_count"
release_title="[CI#${{ github.run_number }}]$mod_name $mod_full_version (Fork)"
fi
else
echo Unknown publish type ${{ inputs.publish_type }}
exit 1
fi
echo "short_sha=$short_sha" >> $GITHUB_OUTPUT
echo "commit_count=$commit_count" >> $GITHUB_OUTPUT
echo "github_tag=$github_tag" >> $GITHUB_OUTPUT
echo "mod_name=$mod_name" >> $GITHUB_OUTPUT
echo "mod_version=$mod_version" >> $GITHUB_OUTPUT
echo "mod_full_version=$mod_full_version" >> $GITHUB_OUTPUT
echo "release_title=$release_title" >> $GITHUB_OUTPUT
- name: Prepare changelog
uses: actions/github-script@v7
id: changelog
with:
script: |
if ('${{ inputs.publish_type }}' === 'release') {
return process.env.CHANGELOG;
} else {
return process.env.CHANGELOG_DEV;
}
result-encoding: string
env:
CHANGELOG: |-
${{ github.event.release.body }}
CHANGELOG_DEV: |-
**This version is automatically released by CI Build**
Latest commit log:
${{ github.event.head_commit.message }}
- name: Publish Minecraft Mods (Dev Channel)
if: ${{ inputs.publish_type == 'dev' }}
uses: Kir-Antipov/[email protected]
with:
github-tag: ${{ steps.shared_publish_info.outputs.github_tag }}
github-token: ${{ secrets.GITHUB_TOKEN }}
github-changelog: ${{ steps.changelog.outputs.result }}
github-prerelease: true
github-commitish: ${{ github.sha }}
files: |
build-artifacts/magiclib-wrapper/fabric/build/tmp/submods/publish/!(*-@(dev|sources|javadoc|empty)).jar
build-artifacts/magiclib-wrapper/forge/build/tmp/submods/publish/!(*-@(dev|sources|javadoc|empty)).jar
build-artifacts/magiclib-wrapper/neoforge/build/tmp/submods/publish/!(*-@(dev|sources|javadoc|empty)).jar
name: ${{ steps.shared_publish_info.outputs.release_title }}
retry-attempts: 3
retry-delay: 10000
- name: Publish Minecraft Mods (Stable Channel)
if: ${{ inputs.publish_channel == 'release' }}
uses: Kir-Antipov/[email protected]
with:
github-tag: ${{ steps.shared_publish_info.outputs.github_tag }}
github-token: ${{ secrets.GITHUB_TOKEN }}
files: |
build-artifacts/magiclib-wrapper/fabric/build/tmp/submods/publish/!(*-@(dev|sources|javadoc|empty)).jar
build-artifacts/magiclib-wrapper/forge/build/tmp/submods/publish/!(*-@(dev|sources|javadoc|empty)).jar
build-artifacts/magiclib-wrapper/neoforge/build/tmp/submods/publish/!(*-@(dev|sources|javadoc|empty)).jar
retry-attempts: 3
retry-delay: 10000
release:
runs-on: ubuntu-24.04
strategy:
matrix: ${{ fromJSON(needs.generate_matrix.outputs.matrix) }}
needs:
- generate_matrix
- release_core
# Allow the mod publish step to add assets to release
# https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token
permissions:
contents: write
steps:
- name: Checkout the sources
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: build-artifacts
path: build-artifacts
- name: Get publish info
id: publish_info
run: |
pip install jproperties
python .github/workflows/scripts/publish_info.py
env:
MOD_PLATFORM: ${{ matrix.platform }}
MOD_MC_VER: ${{ matrix.mc_ver }}
- name: Prepare file information
id: file_info
run: |
shopt -s extglob
FILE_PATHS=$(ls ${{ format('build-artifacts/magiclib-wrapper/{0}/{1}/build/libs/!(*-@(dev|sources|shadow|javadoc|empty)).jar', matrix.platform, matrix.mc_ver) }})
if (( ${#FILE_PATHS[@]} != 1 )); then
echo "Error: Found ${#FILE_PATHS[@]} files, expected exactly 1"
exit 1
else
FILE_PATH=${FILE_PATHS[0]}
fi
FILE_NAME=$(basename $FILE_PATH)
FILE_HASH=$(sha256sum $FILE_PATH | awk '{ print $1 }')
echo "path=$FILE_PATH" >> $GITHUB_OUTPUT
echo "name=$FILE_NAME" >> $GITHUB_OUTPUT
echo "hash=$FILE_HASH" >> $GITHUB_OUTPUT
cat $GITHUB_OUTPUT
- name: Attach file info to changelog
uses: actions/github-script@v7
id: changelog
with:
script: return process.env.CHANGELOG
result-encoding: string
env:
CHANGELOG: |-
${{ needs.release_core.outputs.github_changelog }}
-------
Build Information
- File name: `${{ steps.file_info.outputs.name }}`
- SHA-256: `${{ steps.file_info.outputs.hash }}`
- Built from: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
- name: Publish Minecraft Mods (Dev Channel)
if: ${{ inputs.publish_type == 'dev' }}
uses: Kir-Antipov/[email protected]
with:
modrinth-id: JOGZQCse
modrinth-token: ${{ secrets.MODRINTH_API_TOKEN || '${undefined}' }}
curseforge-id: 1022790
curseforge-token: ${{ secrets.CF_API_TOKEN || '${undefined}' }}
github-tag: ${{ needs.release_core.outputs.github_tag }}
github-token: ${{ secrets.GITHUB_TOKEN }}
github-files: |
build-artifacts/magiclib-wrapper/${{ matrix.platform }}/${{ matrix.mc_ver }}/build/libs/!(*-@(dev|sources|javadoc|empty)).jar
build-artifacts/magiclib-wrapper/${{ matrix.platform }}/${{ matrix.mc_ver }}/build/tmp/submods/publish/!(*-@(dev|sources|javadoc|empty)).jar
build-artifacts/magiclib-wrapper/${{ matrix.platform }}/${{ matrix.mc_ver }}/build/tmp/submods/unpublish/!(*-@(dev|sources|javadoc|empty)).jar
files: |
build-artifacts/magiclib-wrapper/${{ matrix.platform }}/${{ matrix.mc_ver }}/build/libs/!(*-@(dev|sources|javadoc|empty)).jar
curseforge-changelog: ${{ steps.changelog.outputs.result }}
curseforge-name: ${{ needs.release_core.outputs.release_title }}
modrinth-changelog: ${{ steps.changelog.outputs.result }}
modrinth-name: ${{ needs.release_core.outputs.release_title }}
version: ${{ format('v{0}.{1}-mc{2}-{3}', needs.release_core.outputs.mod_version, needs.release_core.outputs.commit_count, matrix.mc_ver, matrix.platform) }}
version-type: alpha
loaders: ${{ steps.publish_info.outputs.publish_loaders }}
game-versions: ${{ steps.publish_info.outputs.publish_game_versions }}
game-version-filter: any
dependencies: ${{ steps.publish_info.outputs.publish_dependencies }}
retry-attempts: 3
retry-delay: 10000
- name: Publish Minecraft Mods (Stable Channel)
if: ${{ inputs.publish_type == 'release' }}
uses: Kir-Antipov/[email protected]
with:
modrinth-id: mv1zH6ln
modrinth-token: ${{ secrets.MODRINTH_API_TOKEN || '${undefined}' }}
curseforge-id: 576459
curseforge-token: ${{ secrets.CF_API_TOKEN || '${undefined}' }}
github-tag: ${{ needs.release_core.outputs.github_tag }}
github-token: ${{ secrets.GITHUB_TOKEN }}
github-files: |
build-artifacts/magiclib-wrapper/${{ matrix.platform }}/${{ matrix.mc_ver }}/build/libs/!(*-@(dev|sources|javadoc|empty)).jar
build-artifacts/magiclib-wrapper/${{ matrix.platform }}/${{ matrix.mc_ver }}/build/tmp/submods/publish/!(*-@(dev|sources|javadoc|empty)).jar
build-artifacts/magiclib-wrapper/${{ matrix.platform }}/${{ matrix.mc_ver }}/build/tmp/submods/unpublish/!(*-@(dev|sources|javadoc|empty)).jar
files: |
build-artifacts/magiclib-wrapper/${{ matrix.platform }}/${{ matrix.mc_ver }}/build/libs/!(*-@(dev|sources|javadoc|empty)).jar
curseforge-changelog: ${{ steps.changelog.outputs.result }}
curseforge-name: ${{ needs.release_core.outputs.release_title }}
modrinth-changelog: ${{ steps.changelog.outputs.result }}
modrinth-name: ${{ needs.release_core.outputs.release_title }}
version: ${{ format('v{0}.{1}-mc{2}-{3}', needs.release_core.outputs.mod_version, needs.release_core.outputs.commit_count, matrix.mc_ver, matrix.platform) }}
version-type: ${{ github.event.release.prerelease && 'beta' || 'release' }}
loaders: ${{ steps.publish_info.outputs.publish_loaders }}
game-versions: ${{ steps.publish_info.outputs.publish_game_versions }}
game-version-filter: any
dependencies: ${{ steps.publish_info.outputs.publish_dependencies }}
retry-attempts: 3
retry-delay: 10000