-
-
Notifications
You must be signed in to change notification settings - Fork 7
585 lines (499 loc) · 19.4 KB
/
compiler.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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
---
name: Compiler
on:
push: null
jobs:
# Setup and test variables from the code
setup-env:
name: Setup environment
runs-on: ubuntu-latest
outputs:
APP_VERSION: ${{ steps.set-vars.outputs.APP_VERSION }}
AMS_VERSION: ${{ steps.set-vars.outputs.AMS_VERSION }}
TELEPATH_VERSION: ${{ steps.set-vars.outputs.TELEPATH_VERSION }}
EXPORTED_ENV: ${{ steps.set-vars.outputs.EXPORTED_ENV }}
steps:
- name: Clone Repo
uses: actions/checkout@v4
- name: Setup environment variables
id: set-vars
run: |
get_env() {
local key="$1"
local path="source/constants.py"
value=$(python3 -c "with open('$path', 'r') as f: print([l for l in f.readlines() if '$key'.lower() in l][0].split(' = ')[1][1:-2].strip())")
echo "$key=$value" >> $GITHUB_OUTPUT
}
# Retrieve and set environment variables
get_env APP_VERSION
get_env AMS_VERSION
get_env TELEPATH_VERSION
echo "EXPORTED_ENV=true" >> $GITHUB_OUTPUT
test-env:
name: Test environment
runs-on: ubuntu-latest
needs: setup-env
steps:
- name: Test environment variables
run: |
echo auto-mcs-${{ needs.setup-env.outputs.APP_VERSION }}
echo "${{ needs.setup-env.outputs.EXPORTED_ENV }}" | grep "true"
# Compile binaries for every OS
windows:
name: Windows Build
runs-on: windows-2019
needs: [setup-env, test-env]
steps:
- name: Clone Repo
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: '3.9'
- name: Compile auto-mcs
shell: pwsh
run: |
systeminfo
$python_path = "$env:LOCALAPPDATA\Programs\Python\Python39"
md $python_path
Move-Item -Force C:\hostedtoolcache\windows\Python\3.9.13\x64\* $python_path
powershell -noprofile -executionpolicy bypass -file .\build-tools\build-windows.ps1
- name: Upload Executable
uses: actions/upload-artifact@v4
with:
name: auto-mcs-windows-${{ needs.setup-env.outputs.APP_VERSION }}
path: build-tools/dist/
retention-days: 5
macos:
name: macOS Build
runs-on: macos-13
needs: [setup-env, test-env]
steps:
- name: Clone Repo
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Install Dependencies
run: |
brew install [email protected] [email protected] create-dmg
- name: Compile auto-mcs
run: |
root=$(pwd)
cd build-tools
mkdir -p /Users/runner/Library/Fonts
chmod +x build-macos.sh
sudo ./build-macos.sh
chmod +x dist/auto-mcs.app/Contents/MacOS/auto-mcs
# Create .dmg from .app
max_attempts=5
attempt=1
set +e
while [ $attempt -le $max_attempts ]; do
# Attempt to create the disk image
sudo create-dmg \
--volname "auto-mcs" \
--volicon "$root/other/macos-dmg/icon.icns" \
--background "$root/other/macos-dmg/bg.png" \
--window-pos 200 120 \
--window-size 835 620 \
--icon-size 128 \
--text-size 16 \
--icon "auto-mcs.app" 230 277 \
--hide-extension "auto-mcs.app" \
--app-drop-link 593 277 \
"$root/build-tools/dist/auto-mcs.dmg" \
"$root/build-tools/dist/auto-mcs.app"
# Check if the .dmg file was created successfully
if [[ -f "$root/build-tools/dist/auto-mcs.dmg" ]]; then
echo "Disk image created successfully."
break
else
echo "Attempt $attempt failed: Disk image creation resource is busy."
attempt=$(( attempt + 1 ))
sleep 5 # Wait for a few seconds before retrying
fi
# Fail if max attempts are reached
if [ $attempt -gt $max_attempts ]; then
echo "Failed to create disk image after $max_attempts attempts."
set -e
exit 1
fi
done
- name: Upload Binary
uses: actions/upload-artifact@v4
with:
name: auto-mcs-macos-${{ needs.setup-env.outputs.APP_VERSION }}
path: build-tools/dist/auto-mcs.dmg
retention-days: 5
linux:
name: Linux Build
runs-on: ubuntu-20.04
needs: [setup-env, test-env]
steps:
- name: Clone Repo
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Install Dependencies
run: |
sudo apt update -y
sudo apt install xvfb fluxbox libasound2 libasound-dev tk8.6 libtk8.6 tcl8.6 libtcl8.6 -y
export DISPLAY=:0.0
Xvfb :0 -screen 0 1280x720x24 > /dev/null 2>&1 &
sleep 1
fluxbox > /dev/null 2>&1 &
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: '3.9'
- name: Compile auto-mcs
run: |
spec_file="auto-mcs.linux.spec"
sudo cp -f /usr/lib/x86_64-linux-gnu/libcrypt.so.1 /usr/lib64/libcrypt.so.2
export DISPLAY=:0.0
cd build-tools
current=$( pwd )
python3.9 -m pip install --upgrade pip setuptools wheel
python3.9 -m venv ./venv
source ./venv/bin/activate
pip install -r reqs-linux.txt
python -m kivy.tools.packaging.pyinstaller_hooks hook ./venv/lib/python3.9/site-packages/kivy/tools/packaging/pyinstaller_hooks/kivy-hook.py
cp -f ../source/gui-assets/fonts/Consolas* /usr/share/fonts
fc-cache -f
# python locale-gen.py
# Patch plyer (pull #822)
FILECHOOSER="./venv/lib/python3.9/site-packages/plyer/platforms/linux/filechooser.py"
sed -i 's/--confirm-overwrite//g' "$FILECHOOSER"
sed -i '/self\.title/d' "$FILECHOOSER"
sed -i '/self\.icon/d' "$FILECHOOSER"
echo Compiling auto-mcs
export KIVY_AUDIO=ffpyplayer
cd $current
cp $spec_file ../source
cd ../source
pyinstaller $spec_file --upx-dir $current/upx/linux --clean
cd $current
rm -rf ../source/$spec_file
mv -f ../source/dist .
deactivate
if ! [ -f $current/dist/auto-mcs ]; then
"[FAIL] Something went wrong during compilation"
exit 1
else
echo [SUCCESS] Compiled binary: \"$current/dist/auto-mcs\"
fi
chmod +x dist/auto-mcs
- name: Upload Binary
uses: actions/upload-artifact@v4
with:
name: auto-mcs-linux-${{ needs.setup-env.outputs.APP_VERSION }}
path: build-tools/dist/
retention-days: 5
linux-arm:
name: Linux Build (arm64)
runs-on: ubuntu-20.04
needs: [setup-env, test-env]
steps:
- name: Clone Repo
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Create artifact directory
run: |
mkdir build-tools/dist
- name: Configure VM & compile auto-mcs
uses: pguyot/[email protected]
with:
cpu: cortex-a53
cpu_info: cpuinfo/raspberrypi_zero2_w_arm64
base_image: raspios_lite_arm64:2022-04-04
image_additional_mb: 4096
copy_artifact_path: build-tools/dist/*
copy_artifact_dest: build-tools/dist
commands: |
# Install dependencies
mkdir -p /usr/lib64/
sudo cp -f /usr/lib/aarch64-linux-gnu/libcrypt.so.1 /usr/lib64/libcrypt.so.2
sudo apt update -y
sudo apt install xvfb fluxbox libasound2 libasound-dev tk8.6 libtk8.6 tcl8.6 libtcl8.6 upx python3-venv python3-tk python3-dev fontconfig -y
export DISPLAY=:0.0
Xvfb :0 -screen 0 1280x720x24 > /dev/null 2>&1 &
sleep 1
fluxbox > /dev/null 2>&1 &
# Build auto-mcs
spec_file="auto-mcs.linux.spec"
export DISPLAY=:0.0
cd build-tools
current=$( pwd )
python3 -m venv ./venv
. ./venv/bin/activate
pip install -r reqs-linux.txt
python -m kivy.tools.packaging.pyinstaller_hooks hook ./venv/lib/python3.9/site-packages/kivy/tools/packaging/pyinstaller_hooks/kivy-hook.py
cp -f ../source/gui-assets/fonts/Consolas* /usr/share/fonts
fc-cache -f
# python locale-gen.py
# Patch plyer (pull #822)
FILECHOOSER="./venv/lib/python3.9/site-packages/plyer/platforms/linux/filechooser.py"
sed -i 's/--confirm-overwrite//g' "$FILECHOOSER"
sed -i '/self\.title/d' "$FILECHOOSER"
sed -i '/self\.icon/d' "$FILECHOOSER"
echo Compiling auto-mcs
export KIVY_AUDIO=ffpyplayer
cd $current
cp $spec_file ../source
cd ../source
pyinstaller $spec_file --upx-dir /usr/bin --clean
cd $current
rm -rf ../source/$spec_file
mv -f ../source/dist .
if ! [ -f $current/dist/auto-mcs ]; then
"[FAIL] Something went wrong during compilation"
exit 1
else
echo [SUCCESS] Compiled binary: \"$current/dist/auto-mcs\"
fi
chmod +x dist/auto-mcs
- name: Upload Binary
uses: actions/upload-artifact@v4
with:
name: auto-mcs-linux-arm64-${{ needs.setup-env.outputs.APP_VERSION }}
path: build-tools/dist/
retention-days: 5
alpine:
name: Docker Build
runs-on: ubuntu-latest
needs: [setup-env, test-env]
steps:
- name: Clone Repo
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Setup Alpine Linux
uses: jirutka/setup-alpine@v1
with:
branch: v3.15
- name: Install Dependencies
run: |
apk add xvfb fluxbox python3 py3-pip gcc pangomm-dev pkgconfig python3-dev zlib-dev libffi-dev musl-dev linux-headers mtdev-dev mtdev
export DISPLAY=:0.0
Xvfb :0 -screen 0 1280x720x24 > /dev/null 2>&1 &
sleep 1
fluxbox > /dev/null 2>&1 &
shell: alpine.sh --root {0}
- name: Compile auto-mcs
run: |
spec_file="auto-mcs.docker.spec"
export DISPLAY=:0.0
cd build-tools
current=$( pwd )
python3.9 -m pip install --upgrade pip setuptools wheel
python3.9 -m venv ./venv
source ./venv/bin/activate
pip install -r reqs-docker.txt
echo Compiling auto-mcs
cd $current
cp $spec_file ../source
cd ../source
pyinstaller $spec_file --upx-dir $current/upx/linux --clean
cd $current
rm -rf ../source/$spec_file
mv -f ../source/dist .
deactivate
if ! [ -f $current/dist/auto-mcs ]; then
"[FAIL] Something went wrong during compilation"
exit 1
else
echo [SUCCESS] Compiled binary: \"$current/dist/auto-mcs\"
fi
chmod +x dist/auto-mcs
shell: alpine.sh {0}
- name: Upload Binary
uses: actions/upload-artifact@v4
with:
name: auto-mcs-alpine-${{ needs.setup-env.outputs.APP_VERSION }}
path: build-tools/dist/
retention-days: 5
alpine-arm:
name: Docker Build (arm64)
runs-on: ubuntu-latest
needs: [setup-env, test-env]
steps:
- name: Clone Repo
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Setup Alpine Linux
uses: jirutka/setup-alpine@v1
with:
arch: aarch64
branch: v3.15
- name: Install Dependencies
run: |
apk add xvfb fluxbox python3 py3-pip gcc pangomm-dev pkgconfig python3-dev zlib-dev libffi-dev musl-dev linux-headers mtdev-dev mtdev
export DISPLAY=:0.0
Xvfb :0 -screen 0 1280x720x24 > /dev/null 2>&1 &
sleep 1
fluxbox > /dev/null 2>&1 &
shell: alpine.sh --root {0}
- name: Compile auto-mcs
run: |
spec_file="auto-mcs.docker.spec"
export DISPLAY=:0.0
cd build-tools
current=$( pwd )
python3.9 -m pip install --upgrade pip setuptools wheel
python3.9 -m venv ./venv
source ./venv/bin/activate
pip install -r reqs-docker.txt
echo Compiling auto-mcs
cd $current
cp $spec_file ../source
cd ../source
pyinstaller $spec_file --upx-dir $current/upx/linux --clean
cd $current
rm -rf ../source/$spec_file
mv -f ../source/dist .
deactivate
if ! [ -f $current/dist/auto-mcs ]; then
"[FAIL] Something went wrong during compilation"
exit 1
else
echo [SUCCESS] Compiled binary: \"$current/dist/auto-mcs\"
fi
chmod +x dist/auto-mcs
shell: alpine.sh {0}
- name: Upload Binary
uses: actions/upload-artifact@v4
with:
name: auto-mcs-alpine-arm64-${{ needs.setup-env.outputs.APP_VERSION }}
path: build-tools/dist/
retention-days: 5
# Upload artifacts to auto-mcs cloud
upload-cloud:
name: Upload to auto-mcs cloud
runs-on: ubuntu-latest
needs: [setup-env, windows, macos, linux, linux-arm, alpine, alpine-arm]
steps:
- name: Download All Artifacts
uses: actions/download-artifact@v4
with:
path: ./artifacts
- name: List Downloaded Artifacts (Debugging)
run: |
echo "Downloaded artifacts:"
ls -R ./artifacts
- name: Upload Artifacts
env:
CLOUD_URL: ${{ secrets.CLOUD_URL }}
CLOUD_USERNAME: ${{ secrets.CLOUD_USERNAME }}
CLOUD_PASSWORD: ${{ secrets.CLOUD_PASSWORD }}
APP_VERSION: ${{ needs.setup-env.outputs.APP_VERSION }}
run: |
# Verify remote folder exists
version_folder="${APP_VERSION}-beta"
echo "Creating directory ${version_folder} if it doesn't exist..."
curl -u "$CLOUD_USERNAME:$CLOUD_PASSWORD" -X MKCOL "${CLOUD_URL}/${version_folder}" || echo "Directory already exists or creation failed"
find ./artifacts -type f | while read file; do
# Extract platform name by removing version numbers and trailing hyphens
dir_name=$(basename $(dirname "$file"))
platform_name=$(echo "$dir_name" | sed -E 's/-[0-9]+(\.[0-9]+)*(-beta\.[0-9]+)?$//')
platform_name="${platform_name%-}" # Remove any trailing hyphens
# Check if the file has an extension; if not, add ".bin" as a placeholder
base_filename=$(basename "$file")
if [[ "$base_filename" == *.* ]]; then
extension="${base_filename##*.}"
new_filename="${platform_name}-${APP_VERSION}-beta.${extension}"
else
new_filename="${platform_name}-${APP_VERSION}-beta.bin"
fi
echo "Uploading $new_filename to ${CLOUD_URL}/${version_folder}..."
# Upload the file to the versioned subfolder with the new name
curl -u "$CLOUD_USERNAME:$CLOUD_PASSWORD" -T "$file" "${CLOUD_URL}/${version_folder}/${new_filename}"
done
# Upload metadata
echo "Commit: ${{ github.sha }}" > ./commit-metadata.txt
echo "URL: https://github.com/macarooni-man/auto-mcs/commit/${{ github.sha }}" >> ./commit-metadata.txt
echo "Author: ${{ github.actor }}" >> ./commit-metadata.txt
echo "Repository: ${{ github.repository }}" >> ./commit-metadata.txt
echo "Branch: ${{ github.ref_name }}" >> ./commit-metadata.txt
echo "Workflow Run: ${{ github.run_id }}" >> ./commit-metadata.txt
echo "Timestamp: $(date)" >> ./commit-metadata.txt
curl -u "$CLOUD_USERNAME:$CLOUD_PASSWORD" -T "./commit-metadata.txt" "${CLOUD_URL}/${version_folder}/commit-metadata.txt"
# Upload source code
source="auto-mcs-source-${APP_VERSION}-beta.zip"
curl -L -o ./${source} \
https://github.com/${{ github.repository }}/archive/refs/heads/${{ github.ref_name }}.zip
curl -u "$CLOUD_USERNAME:$CLOUD_PASSWORD" -T "${source}" "${CLOUD_URL}/${version_folder}/${source}"
# Publish images to Docker Hub
publish-docker:
name: Publish Docker image
runs-on: ubuntu-latest
needs: [setup-env, alpine, alpine-arm]
permissions:
packages: write
contents: read
attestations: write
id-token: write
env:
REGISTRY: docker.io
IMAGE_NAME: macarooniman/auto-mcs
APP_VERSION: ${{ needs.setup-env.outputs.APP_VERSION }}
TAG_SUFFIX: ${{ github.ref_name == 'main' && 'latest' || 'beta' }}
steps:
- name: Clone Repo
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Download x86_64 binary
uses: actions/download-artifact@v4
with:
name: auto-mcs-alpine-${{ env.APP_VERSION }}
path: ./binaries/x86_64
- name: Download arm64 binary
uses: actions/download-artifact@v4
with:
name: auto-mcs-alpine-arm64-${{ env.APP_VERSION }}
path: ./binaries/arm64
- name: Prepare build context
run: |
mkdir -p ./docker
mv binaries/x86_64/auto-mcs ./docker/auto-mcs-amd64
mv binaries/arm64/auto-mcs ./docker/auto-mcs-arm64
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.IMAGE_NAME }}
labels: |
org.opencontainers.image.title={{ env.IMAGE_NAME }}
org.opencontainers.image.description=auto-mcs (docker)
org.opencontainers.image.version={{ env.APP_VERSION }}
org.opencontainers.image.revision={{ github.sha }}
org.opencontainers.image.created={{ now }}
org.opencontainers.image.authors=Kaleb Efflandt <[email protected]>
org.opencontainers.image.url=https://auto-mcs.com
org.opencontainers.image.source=https://github.com/{{ github.repository }}
org.opencontainers.image.licenses=GPL-3.0
- name: Build and push Docker image
id: push
uses: docker/build-push-action@v3
with:
context: ./docker
file: ./docker/Dockerfile
push: true
platforms: linux/amd64,linux/arm64
tags: |
${{ env.IMAGE_NAME }}:${{ env.APP_VERSION }}
${{ env.IMAGE_NAME }}:${{ env.TAG_SUFFIX }}
labels: ${{ steps.meta.outputs.labels }}