Add Mac installer (#101) #62
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
# This workflow builds and tests the macOS installer for YTMusic Deleter. | |
name: Build and Verify (macOS) | |
on: | |
push: | |
branches: # prevent push on tags since that's handled by another workflow | |
- '**' | |
paths-ignore: | |
- '**.md' | |
- '.flake8' | |
- '.gitignore' | |
- '.pre-commit-comfig.yaml' | |
- '**/build-exe.yml' | |
- '**/build-deb.yml' | |
- '**/pytest.yml' | |
- '**/release.yml' | |
pull_request: | |
workflow_dispatch: | |
workflow_call: | |
schedule: | |
- cron: '0 10 * * *' | |
concurrency: | |
group: build-dmg | |
cancel-in-progress: true | |
permissions: | |
contents: read | |
defaults: | |
run: | |
shell: bash | |
jobs: | |
build: | |
strategy: | |
matrix: | |
os: [macos-13, macos-14] | |
runs-on: ${{ matrix.os }} | |
outputs: | |
installer-version: ${{ steps.json-properties.outputs.version }} | |
cli-version: ${{ steps.run-cli.outputs.version }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- uses: pdm-project/setup-pdm@v4 | |
- name: Download fbs | |
env: | |
FBS_URL_ID: ${{ secrets.FBS_URL_ID }} | |
run: | | |
curl -L https://drive.google.com/uc?id=$FBS_URL_ID --output fbs_pro-1.2.1.tar.gz | |
- name: Install dependencies | |
run: | | |
pdm install -dG gui --no-editable | |
# adds `timeout` command | |
brew install coreutils | |
- name: Run CLI from venv | |
id: run-cli | |
run: | | |
. .venv/bin/activate | |
ytmusic-deleter | |
echo "version=$(ytmusic-deleter --version)" >> $GITHUB_OUTPUT | |
- name: Run fbs app | |
run: | | |
# Store the version argument | |
version_str="${{ steps.run-cli.outputs.version }}" | |
# Makes app run headless | |
export QT_QPA_PLATFORM=offscreen | |
# Launch the fbs app and kill it after 10 seconds, saving the output. | |
# We don't want the timing out to fail the job. Normally using `timeout --preserve-status` would handle this but | |
# still getting exit code "241" which is an unknown code. Alternatively, running the entire step in a separate | |
# script file allows using just `timeout 10s pdm fbs run` but would rather not do that. | |
output=$(timeout 10s pdm fbs run || true) | |
# Check if the output contains the right CLI version | |
if grep -q "$version_str" <<< "$output"; then | |
echo "GUI is running the right CLI version: $version_str" | |
else | |
echo "$version_str not found in output, which was the following:" | |
echo $output | |
exit 1 | |
fi | |
- name: Freeze prep | |
run: | | |
pdm freeze-prep | |
- name: Freeze exe | |
run: | | |
pdm fbs freeze | |
- name: Run frozen exe | |
run: | | |
# Store the version argument | |
version_str="${{ steps.run-cli.outputs.version }}" | |
# Makes app run headless | |
export QT_QPA_PLATFORM=offscreen | |
# Launch the fbs app and kill it after 10 seconds, saving the output. | |
output=$(timeout 10s ./gui/target/YTMusic_Deleter.app/Contents/MacOS/YTMusic_Deleter || true) | |
# Check if the output contains the right CLI version | |
if grep -q "$version_str" <<< "$output"; then | |
echo "GUI is running the right CLI version: $version_str" | |
else | |
echo "$version_str not found in output, which was the following:" | |
echo $output | |
exit 1 | |
fi | |
- name: Create installer | |
uses: nick-fields/retry@v3 | |
with: | |
command: pdm fbs installer | |
max_attempts: 10 | |
timeout_minutes: 20 | |
- name: Get base.json file | |
id: json-properties | |
uses: zoexx/[email protected] | |
with: | |
file_path: gui/src/build/settings/base.json | |
- name: Rename installer per version | |
id: rename-installer | |
run: | | |
if [[ "${{ matrix.os }}" == "macos-13" ]]; then | |
ARCH=x86_64 | |
else | |
ARCH=arm | |
fi | |
mv ./gui/target/mac-installer-to-be-renamed.dmg \ | |
./gui/target/YTMusic_Deleter-${{ steps.json-properties.outputs.version }}-MacOS-Installer_$ARCH.dmg | |
echo "ARCH=$ARCH" >> $GITHUB_ENV | |
- name: Save .dmg as artifact | |
id: upload_dmg | |
uses: actions/upload-artifact@v4 | |
with: | |
name: installer-dmg-${{ matrix.os }} | |
path: ./gui/target/YTMusic_Deleter-${{ steps.json-properties.outputs.version }}-MacOS-Installer_${{ env.ARCH }}.dmg | |
env: | |
ARCH: ${{ env.ARCH }} | |
verify: | |
strategy: | |
matrix: | |
os: [macos-13, macos-14] | |
runs-on: ${{ matrix.os }} | |
needs: build | |
steps: | |
- name: Download Artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: installer-dmg-${{ matrix.os }} | |
- name: Attach app image | |
run: | | |
# Have to redefine arch | |
if [[ "${{ matrix.os }}" == "macos-13" ]]; then | |
ARCH=x86_64 | |
else | |
ARCH=arm | |
fi | |
hdiutil attach ./YTMusic_Deleter-${{ needs.build.outputs.installer-version }}-MacOS-Installer_$ARCH.dmg | |
- name: Install dependencies | |
run: | | |
# adds `timeout` command | |
brew install coreutils | |
- name: Run application | |
run: | | |
# Makes app run headless | |
export QT_QPA_PLATFORM=offscreen | |
logfile="$HOME/YTMusic_Deleter/ytmusic-deleter-gui*.log" | |
timeout 10s /Volumes/YTMusic_Deleter/YTMusic_Deleter.app/Contents/MacOS/YTMusic_Deleter || true | |
version_str="${{ needs.build.outputs.cli-version }}" | |
if grep -q "$version_str" $logfile; then | |
echo "GUI is running the right CLI version: $version_str" | |
else | |
echo "The string "$version_str" was not found in $logfile, contents below:" | |
cat $logfile | |
exit 1 | |
fi |