Merge pull request #105 from macarooni-man/dev #856
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
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 }} |