Skip to content

Commit

Permalink
Introduce public GitHub actions for Briefcase
Browse files Browse the repository at this point in the history
  • Loading branch information
rmartin16 committed May 21, 2024
1 parent 6931125 commit e86002d
Show file tree
Hide file tree
Showing 2 changed files with 228 additions and 0 deletions.
91 changes: 91 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,94 @@ jobs:
uses: beeware/.github/.github/workflows/pre-commit-run.yml@main
with:
pre-commit-source: pre-commit

briefcase-actions:
name: Briefcase Actions
needs: [ "pre-commit" ]
runs-on: ${{ matrix.os }}
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
target:
- { platform: "Linux", format: "system" }
- { platform: "Linux", format: "Flatpak" }
#- { platform: "Linux", format: "AppImage" }
- { platform: "Windows", format: "app" }
- { platform: "Windows", format: "VisualStudio" }
- { platform: "macOS", format: "app" }
- { platform: "macOS", format: "Xcode" }
- { platform: "iOS", format: "Xcode" }
- { platform: "Android", format: "Gradle" }
include:
- extra-args: ""
run-extra-args: ""
python-version: "3.X"
- target: { platform: "Linux", format: "system" }
os: "ubuntu-latest"
linux-system-target: "ubuntu:22.04"
python-version: ""
- target: { platform: "Linux", format: "Flatpak" }
os: "ubuntu-latest"
#- target: { platform: "Linux", format: "AppImage" }
# os: "ubuntu-latest"
- target: { platform: "Windows", format: "app" }
os: "windows-latest"
- target: { platform: "Windows", format: "VisualStudio" }
os: "windows-latest"
- target: { platform: "macOS", format: "app" }
os: "macos-14"
- target: { platform: "macOS", format: "Xcode" }
os: "macos-14"
- target: { platform: "iOS", format: "Xcode" }
os: "macos-14"
run-extra-args: "--device 'iPhone SE (3rd generation)::iOS 17.5'"
- target: { platform: "Android", format: "Gradle" }
os: "ubuntu-latest"
steps:

- name: Checkout
uses: actions/[email protected]

- name: Setup Python
uses: actions/[email protected]
with:
python-version: "3.x"

- name: Install Briefcase
uses: beeware/.github/.github/actions/install-briefcase@main

- name: Create Test Project
id: create
uses: beeware/.github/.github/actions/app-create@main

- name: Build App
uses: ./briefcase/command
with:
command: build
platform: ${{ matrix.target.platform }}
format: ${{ matrix.target.format }}
extra-args: ${{ matrix.extra-args }}
project-directory: ${{ steps.create.outputs.project-path }}
python-version: ${{ matrix.python-version }}
briefcase-version: 0.3.18

- name: Test App
uses: ./briefcase/command
with:
command: run
platform: ${{ matrix.target.platform }}
format: ${{ matrix.target.format }}
extra-args: -ru --test ${{ matrix.extra-args }} ${{ matrix.run-extra-args }}
project-directory: ${{ steps.create.outputs.project-path }}
python-version: ${{ matrix.python-version }}

- name: Package App
uses: ./briefcase/command
with:
command: package
platform: ${{ matrix.target.platform }}
format: ${{ matrix.target.format }}
extra-args: -u --adhoc-sign ${{ matrix.extra-args }}
project-directory: ${{ steps.create.outputs.project-path }}
python-version: ${{ matrix.python-version }}
137 changes: 137 additions & 0 deletions briefcase/command/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
name: Briefcase
description: Run a Briefcase command

inputs:
command:
description: "Name of the Briefcase command to run."
required: true
platform:
description: "The target platform for the Briefcase command."
required: true
format:
description: "The target format for the Briefcase command."
required: true
extra-args:
description: "Options to pass to Briefcase command."
required: false
default: ""
project-directory:
description: "Project base directory containing pyprojet.toml."
required: false
default: ${{ github.workspace }}
briefcase-version:
description: "The Briefcase version to use; the latest version is used by default."
required: false
default: "latest"
python-version:
description: "If specified, actions/setup-python will run for that version."
required: false
default: ""
android-emulator-config:
description: 'Configuration definition of emulator; defaults to {"avd":"beePhone"}.'
required: false
default: ""
linux-system-target:
description: 'The Linux target for the "--target" switch for Briefcase; e.g. "ubuntu:noble".'
required: false
default: ""

runs:
using: composite
steps:

- name: Workflow Configuration
id: config
shell: bash
run: |
case "${{ runner.os }}" in
Linux ) BRIEFCASE_DIR="$HOME/.cache/briefcase" ;;
macOS ) BRIEFCASE_DIR="$HOME/Library/Caches/org.beeware.briefcase" ;;
Windows ) BRIEFCASE_DIR="$HOME/AppData/Local/BeeWare/briefcase/Cache" ;;
* ) echo "::error::Failed to determine the Briefcase data directory path" ;;
esac
echo "briefcase-data-dir=${BRIEFCASE_DIR}" | tee -a ${GITHUB_OUTPUT}
CACHE_KEY="${{ runner.os }}|${{ inputs.platform }}"
# For Linux builds, the cache varies by the output format
if [ "${{ startsWith(runner.os, 'linux') }}" = "true" ]; then
CACHE_KEY="$CACHE_KEY|${{ inputs.format }}"
fi
echo "cache-key=$(date +%Y-%m)|${CACHE_KEY}" | tee -a ${GITHUB_OUTPUT}
- name: Cache Briefcase Tools
uses: actions/[email protected]
with:
key: briefcase-data|${{ steps.config.outputs.cache-key }}
path: ${{ steps.config.outputs.briefcase-data-dir }}

- name: Linux Run Dependencies
id: linux-deps
if: startswith(inputs.platform, 'linux') && startswith(inputs.command, 'run')
shell: bash
run: |
sudo apt update
sudo apt -y install --no-install-recommends socat xauth
echo "run-prefix=xvfb-run" | tee -a ${GITHUB_OUTPUT}
- name: Linux Target Check
id: linux
if: startswith(inputs.platform, 'linux') && startswith(inputs.format, 'system')
shell: bash
run: |
if [[ "${{ inputs.linux-system-target }}" != "" ]]; then
echo "briefcase-args=--target ${{ inputs.linux-system-target }}" | tee -a ${GITHUB_OUTPUT}
elif [[ ${{ contains(inputs.extra-args, '--target') }} != "true" ]]; then
echo '::error::Linux System builds must explicitly target a distribution.'
echo '::error::Use the extra-args parameter to include the --target option.'
exit 1
fi
- name: Flatpak Dependencies
if: startswith(inputs.format, 'Flatpak')
shell: bash
run: |
sudo apt update
sudo apt install -y --no-install-recommends flatpak flatpak-builder elfutils
- name: AppImage Dependencies
if: startswith(inputs.format, 'AppImage')
shell: bash
run: |
sudo apt update
sudo apt install -y --no-install-recommends libfuse2
- name: Android Emulator Configuration
id: android
if: startswith(inputs.platform, 'android') && startswith(inputs.command, 'run')
uses: rmartin16/.github-beeware/.github/actions/setup-android@setup-android
with:
emulator-config: ${{ inputs.android-emulator-config }}

- name: Set up Python
if: inputs.python-version != ''
uses: actions/[email protected]
with:
python-version: ${{ inputs.python-version }}

- name: Install Briefcase
shell: bash
run: |
if [[ "${{ inputs.briefcase-version }}" == "latest" ]]; then
python -m pip install -U briefcase
else
python -m pip install -U briefcase==${{ inputs.briefcase-version }}
fi
- name: Briefcase ${{ inputs.command }}
working-directory: ${{ inputs.project-directory }}
shell: bash
run: >
${{ steps.linux-deps.outputs.run-prefix }}
briefcase
${{ inputs.command }}
${{ inputs.platform }}
${{ inputs.format }}
${{ steps.linux.outputs.briefcase-args }}
${{ steps.android.outputs.briefcase-run-args }}
${{ inputs.extra-args }}

0 comments on commit e86002d

Please sign in to comment.