Skip to content

refactor: update build process to use SpectraLab name and adjust pack… #15

refactor: update build process to use SpectraLab name and adjust pack…

refactor: update build process to use SpectraLab name and adjust pack… #15

Workflow file for this run

name: Build SpectraLab Executables and Create Release for Windows and macOS
on:
workflow_dispatch:
inputs:
version:
description: "Version number (e.g., 1.0.0)"
required: false
default: "1.0.0"
push:
branches:
- master
permissions:
contents: write # Required for creating GitHub Release and uploading assets
jobs:
build-windows:
runs-on: windows-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12" # Adjust to your Python version
- name: Install uv
run: pip install uv
- name: Cache Python dependencies
uses: actions/cache@v4
with:
path: ~/.cache/uv
key: ${{ runner.os }}-uv-${{ hashFiles('**/uv.lock') }}
restore-keys: |
${{ runner.os }}-uv-
- name: Install dependencies with uv
run: uv sync # Assuming pyproject.toml is used; if requirements.txt, change to uv pip install -r requirements.txt
- name: Install PyInstaller and Pillow (for icon conversion)
run: uv pip install pyinstaller pillow # If not in pyproject.toml, install additionally
- name: Set version
id: version
run: |
# Try to read version from pyproject.toml first
try {
$pyprojectContent = Get-Content "pyproject.toml" -Raw
if ($pyprojectContent -match 'version\s*=\s*"([^"]+)"') {
$pyprojectVersion = $matches[1]
Write-Host "Found version in pyproject.toml: $pyprojectVersion"
} else {
$pyprojectVersion = $null
}
} catch {
Write-Host "Could not read pyproject.toml"
$pyprojectVersion = $null
}
if ("${{ github.event_name }}" -eq "workflow_dispatch") {
$version = "${{ inputs.version }}"
if ([string]::IsNullOrEmpty($version)) {
if ($pyprojectVersion) {
$version = $pyprojectVersion
} else {
$version = "1.0.0"
}
}
} else {
if ($pyprojectVersion) {
$version = "$pyprojectVersion-build${{ github.run_number }}"
} else {
$version = "1.0.${{ github.run_number }}"
}
}
echo "version=$version" >> $env:GITHUB_OUTPUT
shell: pwsh
- name: Convert icon for Windows
run: |
uv run python -c "
from PIL import Image
icon = Image.open('icon/icon.png')
icon.save('icon/icon.ico', format='ICO', sizes=[(256,256), (128,128), (64,64), (48,48), (32,32), (16,16)])
"
shell: pwsh
- name: Build executable for Windows
run: |
uv run pyinstaller --noconsole --onedir --icon=icon/icon.ico --name "SpectraLab" --exclude-module docs --exclude docs main.py
shell: pwsh
- name: Zip Windows distribution folder
run: |
Compress-Archive -Path "dist/SpectraLab/*" -DestinationPath "dist/SpectraLab-Windows.zip"
shell: pwsh
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: executable-windows-latest-v${{ steps.version.outputs.version }}
path: dist/
build-macos:
runs-on: macos-14 # Supports Apple Silicon (ARM64)
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12" # Adjust to your Python version
- name: Install uv
run: pip install uv
- name: Cache Python dependencies
uses: actions/cache@v4
with:
path: ~/.cache/uv
key: ${{ runner.os }}-uv-${{ hashFiles('**/uv.lock') }}
restore-keys: |
${{ runner.os }}-uv-
- name: Install dependencies with uv
run: uv sync # Assuming pyproject.toml is used; if requirements.txt, change to uv pip install -r requirements.txt
- name: Install PyInstaller and Pillow (for icon conversion)
run: uv pip install pyinstaller pillow # If not in pyproject.toml, install additionally
- name: Set version
id: version
run: |
# Try to read version from pyproject.toml first
pyproject_version=""
if [ -f "pyproject.toml" ]; then
pyproject_version=$(grep -E '^version\s*=' pyproject.toml | grep -oE '"[^"]*"' | tr -d '"')
if [ -n "$pyproject_version" ]; then
echo "Found version in pyproject.toml: $pyproject_version"
fi
fi
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
version="${{ inputs.version }}"
if [ -z "$version" ]; then
if [ -n "$pyproject_version" ]; then
version="$pyproject_version"
else
version="1.0.0"
fi
fi
else
if [ -n "$pyproject_version" ]; then
version="$pyproject_version-build${{ github.run_number }}"
else
version="1.0.${{ github.run_number }}"
fi
fi
echo "version=$version" >> $GITHUB_OUTPUT
- name: Convert icon for macOS
run: |
mkdir icon/icon.iconset
sips -z 16 16 icon/icon.png --out icon/icon.iconset/icon_16x16.png
sips -z 32 32 icon/icon.png --out icon/icon.iconset/icon_16x16@2x.png
sips -z 32 32 icon/icon.png --out icon/icon.iconset/icon_32x32.png
sips -z 64 64 icon/icon.png --out icon/icon.iconset/icon_32x32@2x.png
sips -z 128 128 icon/icon.png --out icon/icon.iconset/icon_128x128.png
sips -z 256 256 icon/icon.png --out icon/icon.iconset/icon_128x128@2x.png
sips -z 256 256 icon/icon.png --out icon/icon.iconset/icon_256x256.png
sips -z 512 512 icon/icon.png --out icon/icon.iconset/icon_256x256@2x.png
sips -z 512 512 icon/icon.png --out icon/icon.iconset/icon_512x512.png
sips -z 1024 1024 icon/icon.png --out icon/icon.iconset/icon_512x512@2x.png
iconutil -c icns icon/icon.iconset -o icon/icon.icns
rm -rf icon/icon.iconset
shell: bash
- name: Build executable for macOS
run: |
uv run pyinstaller --noconsole --onedir --icon=icon/icon.icns --name "SpectraLab" --windowed --exclude-module docs --exclude docs main.py
# If needed for .app bundle, additionally handle Info.plist
if [ -d "dist/SpectraLab.app" ]; then
cp icon/icon.icns "dist/SpectraLab.app/Contents/Resources/"
plutil -replace CFBundleIconFile -string icon.icns "dist/SpectraLab.app/Contents/Info.plist"
fi
shell: bash
- name: Zip macOS .app bundle
run: |
cd dist
if [ -d "SpectraLab.app" ]; then
zip -r "SpectraLab-macOS.zip" "SpectraLab.app"
fi
shell: bash
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: executable-macos-14-v${{ steps.version.outputs.version }}
path: dist/
release:
needs: [build-windows, build-macos]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download Windows artifact
uses: actions/download-artifact@v4
with:
name: executable-windows-latest-v${{ needs.build-windows.outputs.version }}
path: dist/windows
- name: Download macOS artifact
uses: actions/download-artifact@v4
with:
name: executable-macos-14-v${{ needs.build-macos.outputs.version }}
path: dist/macos
- name: Create Release
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ needs.build-windows.outputs.version }}
name: Release v${{ needs.build-windows.outputs.version }}
draft: false
prerelease: false
files: |
dist/windows/SpectraLab-Windows.zip
dist/macos/SpectraLab-macOS.zip