-
Notifications
You must be signed in to change notification settings - Fork 22
238 lines (192 loc) · 8.82 KB
/
build-gradle.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
name: Build and Version Update
permissions:
contents: write
on:
push:
branches:
- main
- merge
- dev
- fabric-experimental-gradle
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout main repository
uses: actions/checkout@v2
- name: Set up JDK
uses: actions/setup-java@v2
with:
java-version: '21'
distribution: 'adopt'
cache: gradle
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
with:
gradle-version: 8.8
# Temporary workaround to packetevents bugs, use custom fork build
- name: Checkout packetevents repository
uses: actions/checkout@v3
with:
repository: Axionize/packetevents
ref: 2.0-fabric-serverside-fix
path: packetevents
- name: Update version in packetevents
run: |
cd packetevents
sed -i 's/val fullVersion = ".*"/val fullVersion = "2.5.8"/' build.gradle.kts
- name: Build packetevents with Gradle
run: |
cd packetevents
gradle build -x test
- name: Publish packetevents to Maven Local
run: |
cd packetevents
gradle publishToMavenLocal
- name: Generate build number
id: buildnumber
uses: einaregilsson/build-number@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Update version in build.gradle.kts
id: update_version
run: |
# Read current fullVersion from build.gradle.kts
FULL_VERSION=$(grep 'val fullVersion =' build.gradle.kts | awk -F '"' '{print $2}')
IFS='.' read -ra VERSION_PARTS <<< "$FULL_VERSION"
PATCH=$((VERSION_PARTS[2] + 1))
NEW_VERSION="${VERSION_PARTS[0]}.${VERSION_PARTS[1]}.$PATCH-dev-b${{ steps.buildnumber.outputs.build_number }}"
echo "NEW_VERSION=${NEW_VERSION}" >> $GITHUB_ENV
# Update fullVersion in build.gradle
sed -i "s/val fullVersion = \".*\"/val fullVersion = \"$NEW_VERSION\"/" build.gradle.kts
# Ensure snapshot is set to false
sed -i "s/val snapshot = .*/val snapshot = false/" build.gradle.kts
- name: Build with Gradle
run: gradle clean build -x test
env:
GITHUB_REPOSITORY: ${{ github.repository }}
- name: Rename shaded jar to overwrite non-shaded jar
run: mv bukkit/build/libs/knockbacksync-bukkit-${{ env.NEW_VERSION }}-all.jar bukkit/build/libs/knockbacksync-bukkit-${{ env.NEW_VERSION }}.jar
# Download PaperSpigot (Choose version for reproducibility
- name: Download PaperSpigot
run: |
mkdir -p paper-server/plugins
curl -o paperclip.jar https://api.papermc.io/v2/projects/paper/versions/1.21.1/builds/120/downloads/paper-1.21.1-120.jar
mv paperclip.jar paper-server/
# Copy Plugin into Plugins Folder and Start Server
- name: Copy Plugin and Start Paper Server
run: |
cp bukkit/build/libs/knockbacksync-bukkit-${{ env.NEW_VERSION }}.jar paper-server/plugins/
cd paper-server
# Start the server to remap the plugin
timeout 60 java -Xms3G -Xmx3G -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=30 -XX:G1MaxNewSizePercent=40 -XX:G1HeapRegionSize=8M -XX:G1ReservePercent=20 -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 -XX:InitiatingHeapOccupancyPercent=15 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1 -jar -Dcom.mojang.eula.agree=true paperclip.jar --nogui || true
# Get the Hashes of the Original and Remapped JARs
- name: Calculate Hashes
run: |
# Calculate hash for the original JAR
ORIGINAL_HASH=$(sha256sum bukkit/build/libs/knockbacksync-bukkit-${{ env.NEW_VERSION }}.jar | awk '{print $1}')
echo "ORIGINAL_HASH=$ORIGINAL_HASH" >> $GITHUB_ENV
# Calculate hash for the remapped JAR
REMAPPED_HASH=$(sha256sum paper-server/plugins/.paper-remapped/knockbacksync-bukkit-${{ env.NEW_VERSION }}.jar | awk '{print $1}')
echo "REMAPPED_HASH=$REMAPPED_HASH" >> $GITHUB_ENV
# Calculate hash for the remapped JAR
FABRIC_HASH=$(sha256sum fabric/build/libs/knockbacksync-fabric-${{ env.NEW_VERSION }}.jar | awk '{print $1}')
echo "FABRIC_HASH=$FABRIC_HASH" >> $GITHUB_ENV
# Download, update, and re-upload dev-builds.txt
- name: Update dev-builds.txt
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Download the current dev-builds.txt
curl -L -o dev-builds.txt https://github.com/${{ github.repository }}/releases/latest/download/dev-builds.txt
# Create a copy of the original file
cp dev-builds.txt dev-builds.txt.original
# Ensure the file ends with a newline
sed -i -e '$a\' dev-builds.txt
# Function to add hash if it doesn't exist
add_hash_if_new() {
if ! grep -q "$1" dev-builds.txt; then
echo "$1" >> dev-builds.txt
fi
}
# Add new hashes if they don't exist
add_hash_if_new "${{ env.ORIGINAL_HASH }}"
add_hash_if_new "${{ env.REMAPPED_HASH }}"
add_hash_if_new "${{ env.FABRIC_HASH }}"
# Check if the file has changed
if cmp -s dev-builds.txt dev-builds.txt.original; then
echo "No changes to dev-builds.txt, skipping upload."
else
echo "Changes detected in dev-builds.txt, uploading new version."
# Get the latest release ID
RELEASE_ID=$(curl -s "https://api.github.com/repos/${{ github.repository }}/releases/latest" | jq -r .id)
# Delete the old dev-builds.txt asset
ASSET_ID=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/${{ github.repository }}/releases/$RELEASE_ID/assets" | \
jq -r '.[] | select(.name == "dev-builds.txt") | .id')
if [ ! -z "$ASSET_ID" ]; then
curl -X DELETE -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/${{ github.repository }}/releases/assets/$ASSET_ID"
fi
# Upload the new dev-builds.txt
curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
-H "Content-Type: application/octet-stream" \
--data-binary @dev-builds.txt \
"https://uploads.github.com/repos/${{ github.repository }}/releases/$RELEASE_ID/assets?name=dev-builds.txt"
fi
# Clean up
rm dev-builds.txt.original
- name: Create artifacts directory
run: mkdir -p artifacts
- name: Copy bukkit artifact
run: cp bukkit/build/libs/knockbacksync-bukkit-${{ env.NEW_VERSION }}.jar artifacts/
- name: Copy fabric artifact
run: cp fabric/build/libs/knockbacksync-fabric-${{ env.NEW_VERSION }}.jar artifacts/
- name: Zip the artifacts
run: zip -r KnockbackSync-${{ env.NEW_VERSION }}.zip artifacts/*
- name: Upload artifacts zip
uses: actions/upload-artifact@v4
with:
name: KnockbackSync-${{ env.NEW_VERSION }}.zip
path: KnockbackSync-${{ env.NEW_VERSION }}.zip
retention-days: 90
- uses: Kir-Antipov/[email protected]
with:
modrinth-id: ${{ vars.MODRINTH_ID }}
modrinth-featured: true
modrinth-unfeature-mode: subset
modrinth-token: ${{ secrets.MODRINTH_TOKEN }}
files: |
bukkit/build/libs/knockbacksync-bukkit-${{ env.NEW_VERSION }}.jar
name: KnockbackSync-${{ env.NEW_VERSION }}
version: ${{ env.NEW_VERSION }}
version-type: alpha
loaders: |
bukkit
spigot
paper
folia
purpur
game-versions: |
>=1.12.2
retry-attempts: 2
retry-delay: 10000
fail-mode: fail
- uses: Kir-Antipov/[email protected]
with:
modrinth-id: ${{ vars.MODRINTH_ID }}
modrinth-featured: true
modrinth-unfeature-mode: subset
modrinth-token: ${{ secrets.MODRINTH_TOKEN }}
files: |
fabric/build/libs/knockbacksync-fabric-${{ env.NEW_VERSION }}.jar
name: KnockbackSync-${{ env.NEW_VERSION }}
version: ${{ env.NEW_VERSION }}
version-type: alpha
loaders: |
fabric
game-versions: |
>=1.21
retry-attempts: 2
retry-delay: 10000
fail-mode: fail