Skip to content

Commit

Permalink
Add an action to create a project and workflow to verify a created pr…
Browse files Browse the repository at this point in the history
…oject
  • Loading branch information
rmartin16 committed Nov 16, 2023
1 parent d908d34 commit 2f6a58c
Show file tree
Hide file tree
Showing 5 changed files with 268 additions and 56 deletions.
84 changes: 84 additions & 0 deletions .github/actions/app-create/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Create a Briefcase Project
description: Creates a new Briefcase project using a particular GUI toolkit and template.

inputs:
framework:
description: "The GUI toolkit to use to create the project."
default: "Toga"
briefcase-template-source:
description: "The template to use to roll out the project."
required: false
briefcase-template-branch:
description: "The git branch for the template to use to roll out the project."
required: false
testing-pr-body:
description: "Override value for body of PR; only for testing."
required: false

outputs:
project-path:
value: ${{ steps.create.outputs.path }}
description: "The file path to the root of the created project."

runs:
using: composite
steps:
- name: Briefcase Template Override
id: template-override
env:
GITHUB_TOKEN: ${{ github.token }}
shell: bash
run: |
# Check Body of PR for template to use
# (only PRs will have a value for github.event.pull_request.number)
PR_BODY="${{ inputs.testing-pr-body }}"
if [[ -z "${PR_BODY}" && -n "${{ github.event.pull_request.number }}" ]]; then
PR_BODY=$(gh api repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }} --jq '.body')
fi
printf "::group::Retrieved PR Body\n%s\n::endgroup::\n" "${PR_BODY}"
TEMPLATE_REPO=$(printf "%s" "${PR_BODY}" | perl -wlne '/BRIEFCASE[-_]*TEMPLATE[-_]*REPO:\s*\K\S+/i and print $&')
TEMPLATE_REF=$(printf "%s" "${PR_BODY}" | perl -wlne '/BRIEFCASE[-_]*TEMPLATE[-_]*REF:\s*\K\S+/i and print $&')
# Expose template repo and branch via outputs
echo "Template Repo: ${TEMPLATE_REPO}"
echo "Template Ref: ${TEMPLATE_REF}"
echo "repo=${TEMPLATE_REPO}" >> ${GITHUB_OUTPUT}
echo "ref=${TEMPLATE_REF}" >> ${GITHUB_OUTPUT}
- name: Create Briefcase Project
id: create
shell: bash
run: |
if [[ "${{ steps.template-override.outputs.repo }}" != "" ]]; then
TEMPLATE=$(printf -- "--template %q" "${{ steps.template-override.outputs.repo }}")
fi
if [[ "${{ steps.template-override.outputs.ref }}" != "" ]]; then
TEMPLATE_BRANCH=$(printf -- "--template-branch %q" "${{ steps.template-override.outputs.ref }}")
fi
# Map the requested GUI toolkit to the input that Briefcase expects
# Default to the input to accommodate arbitrary toolkits installed as plugins
case "$(tr '[:upper:]' '[:lower:]' <<< '${{ inputs.framework }}')" in
toga ) GUI_INPUT=1 ;;
pyside6 ) GUI_INPUT=2 ;;
ppb ) GUI_INPUT=3 ;;
pygame ) GUI_INPUT=4 ;;
* ) GUI_INPUT=${{ inputs.framework }} ;;
esac
ROOT_DIR="apps"
APP_DIR="verify-app"
APP_PATH="${ROOT_DIR}/${APP_DIR}"
# Prepare to create the project in APP_DIR
mkdir -p "${ROOT_DIR}"
cd "${ROOT_DIR}"
rm -rf "${APP_DIR}"
# Roll out the project
printf "Verify App\n%s\n\n\n\n\n\n\n\n%s\n" "${APP_DIR}" "${GUI_INPUT}" \
| briefcase new ${TEMPLATE} ${TEMPLATE_BRANCH}
echo "Rolled out project to ${APP_PATH}"
echo "path=${APP_PATH}" >> ${GITHUB_OUTPUT}
4 changes: 2 additions & 2 deletions .github/actions/install-briefcase/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ runs:
GITHUB_TOKEN: ${{ github.token }}
shell: bash
run: |
# Source version from Body of PR (if there is one; if there isn't,
# github.event.pull_request.number will be empty)
# Check Body of PR for Briefcase version to use
# (only PRs will have a value for github.event.pull_request.number)
PR_BODY="${{ inputs.testing-pr-body }}"
if [[ -z "${PR_BODY}" && -n "${{ github.event.pull_request.number }}" ]]; then
PR_BODY=$(gh api repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }} --jq '.body')
Expand Down
97 changes: 45 additions & 52 deletions .github/workflows/app-build-verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
repository: "beeware/.github"
path: "beeware-.github"

- name: Package name
- name: Package Name
id: package
run: echo "name=$(basename '${{ inputs.repository }}')" >> ${GITHUB_OUTPUT}

Expand All @@ -90,7 +90,7 @@ jobs:
echo "docker-cache-dir=C:/ProgramData/DockerDesktop" >> ${GITHUB_OUTPUT}
fi
- name: Cache Briefcase tools
- name: Cache Briefcase Tools
uses: actions/cache@v3.3.2
with:
key: briefcase-${{ runner.os }}-${{ inputs.repository }}-${{ inputs.framework }}-${{ inputs.target-platform }}-${{ inputs.target-format }}
Expand All @@ -100,7 +100,7 @@ jobs:
${{ steps.dirs.outputs.pip-cache-dir }}
${{ steps.dirs.outputs.docker-cache-dir }}
- name: Determine system python3 version
- name: Determine System python3 Version
id: system-python
run: |
echo "python-version=$(python3 -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')"
Expand All @@ -111,132 +111,125 @@ jobs:
with:
python-version: ${{ inputs.python-version }}

- name: Get packages
- name: Get Packages
# Briefcase will build and package itself in a previous step in its CI.
if: endsWith(inputs.repository, 'briefcase')
uses: actions/download-artifact@v3.0.2
with:
name: packages-${{ steps.package.outputs.name }}
path: dist

- name: Install Briefcase artifact
- name: Install Briefcase Artefact
if: endsWith(inputs.repository, 'briefcase')
run: python -m pip install dist/briefcase-*.whl

- name: Install Briefcase
if: ${{ !endsWith(inputs.repository, 'briefcase') }}
uses: ./beeware-.github/.github/actions/install-briefcase

- name: Create Briefcase project
# Don't run for template repos since they already contain a created app.
if: ${{ !endsWith(inputs.repository, '-template') || inputs.repository == 'beeware/briefcase-template' }}
run: |
if [[ "${{ inputs.briefcase-template-source }}" != "" ]]; then
TEMPLATE=$(printf -- "--template %q" "${{ inputs.briefcase-template-source }}")
fi
if [[ "${{ inputs.briefcase-template-branch }}" != "" ]]; then
TEMPLATE_BRANCH=$(printf -- "--template-branch %q" "${{ inputs.briefcase-template-branch }}")
fi
cd tests/apps
cat verify-${{ inputs.framework }}.config | briefcase new ${TEMPLATE} ${TEMPLATE_BRANCH}
- name: Create Briefcase Project
id: create
uses: ./beeware-.github/.github/actions/app-create
with:
gui-toolkit: ${{ inputs.framework }}
briefcase-template-source: ${{ inputs.briefcase-template-source }}
briefcase-template-branch: ${{ inputs.briefcase-template-branch }}

# In the steps below, using the builtin functions for comparison (instead of ==)
# allows for case-insensitivity to the inputs for the workflow.

- name: Build macOS app
- name: Build macOS App
if: >
startsWith(inputs.runner-os, 'macOS')
&& contains(fromJSON('["", "macOS"]'), inputs.target-platform)
&& contains(fromJSON('["", "app"]'), inputs.target-format)
working-directory: ${{ steps.create.outputs.project-path }}
run: |
cd tests/apps/verify-${{ inputs.framework }}
briefcase create macOS app
briefcase build macOS app
briefcase package macOS app --adhoc-sign
- name: Build macOS Xcode project
- name: Build macOS Xcode Project
if: >
startsWith(inputs.runner-os, 'macOS')
&& contains(fromJSON('["", "macOS"]'), inputs.target-platform)
&& contains(fromJSON('["", "Xcode"]'), inputs.target-format)
working-directory: ${{ steps.create.outputs.project-path }}
run: |
cd tests/apps/verify-${{ inputs.framework }}
briefcase create macOS Xcode
briefcase build macOS Xcode
briefcase package macOS Xcode --adhoc-sign
- name: Build Windows app
- name: Build Windows App
if: >
startsWith(inputs.runner-os, 'Windows')
&& contains(fromJSON('["", "Windows"]'), inputs.target-platform)
&& contains(fromJSON('["", "app"]'), inputs.target-format)
env:
WIX: "" # force Briefcase to install and use its own version of WiX
working-directory: ${{ steps.create.outputs.project-path }}
run: |
unset WIX # force Briefcase to install and use its own version of WiX
cd tests/apps/verify-${{ inputs.framework }}
briefcase create windows app
briefcase build windows app
briefcase package windows app --adhoc-sign
- name: Build Windows Visual Studio project
- name: Build Windows Visual Studio Project
if: >
startsWith(inputs.runner-os, 'Windows')
&& contains(fromJSON('["", "Windows"]'), inputs.target-platform)
&& contains(fromJSON('["", "VisualStudio"]'), inputs.target-format)
env:
WIX: "" # force Briefcase to install and use its own version of WiX
working-directory: ${{ steps.create.outputs.project-path }}
run: |
unset WIX # force Briefcase to install and use its own version of WiX
cd tests/apps/verify-${{ inputs.framework }}
briefcase create windows VisualStudio
briefcase build windows VisualStudio
briefcase package windows VisualStudio --adhoc-sign
- name: Build Linux System project (Ubuntu, local)
- name: Build Linux System Project (Ubuntu, local)
if: >
startsWith(inputs.runner-os, 'ubuntu')
&& startsWith(inputs.python-version, steps.system-python.outputs.python-version)
&& contains(fromJSON('["", "Linux"]'), inputs.target-platform)
&& contains(fromJSON('["", "system"]'), inputs.target-format)
working-directory: ${{ steps.create.outputs.project-path }}
run: |
sudo apt-get update -y && sudo apt-get install -y python3-dev python3-pip libcairo2-dev libgirepository1.0-dev
cd tests/apps/verify-${{ inputs.framework }}
sudo apt update -y
sudo apt-get install -y python3-dev python3-pip libcairo2-dev libgirepository1.0-dev
briefcase create linux system
briefcase build linux system
briefcase package linux system --adhoc-sign
- name: Build Linux System project (Debian, Dockerized)
- name: Build Linux System Project (Debian, Dockerized)
if: >
startsWith(inputs.runner-os, 'ubuntu')
&& contains(fromJSON('["", "Linux"]'), inputs.target-platform)
&& contains(fromJSON('["", "system"]'), inputs.target-format)
working-directory: ${{ steps.create.outputs.project-path }}
run: |
cd tests/apps/verify-${{ inputs.framework }}
briefcase create linux system --target debian:bullseye
briefcase build linux system --target debian:bullseye
briefcase package linux system --target debian:bullseye --adhoc-sign
- name: Build Linux System project (RPM, Dockerized)
# fedora:37 ships with Python 3.11 and PySide2 cannot be installed
- name: Build Linux System Project (RPM, Dockerized)
if: >
startsWith(inputs.runner-os, 'ubuntu')
&& !contains(fromJSON('["PySide2"]'), inputs.framework)
&& contains(fromJSON('["", "Linux"]'), inputs.target-platform)
&& contains(fromJSON('["", "system"]'), inputs.target-format)
working-directory: ${{ steps.create.outputs.project-path }}
run: |
cd tests/apps/verify-${{ inputs.framework }}
briefcase create linux system --target fedora:37
briefcase build linux system --target fedora:37
briefcase package linux system --target fedora:37 --adhoc-sign
- name: Build Linux System project (Arch, Dockerized)
# arch started shipping Python 3.11 on 3 may 2023 and PySide2 cannot be installed
- name: Build Linux System Project (Arch, Dockerized)
if: >
startsWith(inputs.runner-os, 'ubuntu')
&& !contains(fromJSON('["PySide2"]'), inputs.framework)
&& contains(fromJSON('["", "Linux"]'), inputs.target-platform)
&& contains(fromJSON('["", "system"]'), inputs.target-format)
working-directory: ${{ steps.create.outputs.project-path }}
run: |
cd tests/apps/verify-${{ inputs.framework }}
briefcase create linux system --target archlinux:latest
briefcase build linux system --target archlinux:latest
briefcase package linux system --target archlinux:latest --adhoc-sign
Expand All @@ -254,28 +247,28 @@ jobs:
# alive.
#
# Only runs when target platform and format are explicitly Linux and AppImage.
- name: Build AppImage project
- name: Build AppImage Project
if: >
startsWith(inputs.runner-os, 'ubuntu')
&& contains(fromJSON('["Linux"]'), inputs.target-platform)
&& contains(fromJSON('["AppImage"]'), inputs.target-format)
working-directory: ${{ steps.create.outputs.project-path }}
run: |
cd tests/apps/verify-${{ inputs.framework }}
briefcase create linux AppImage
briefcase build linux AppImage
briefcase package linux AppImage --adhoc-sign
- name: Build Flatpak project
- name: Build Flatpak Project
if: >
startsWith(inputs.runner-os, 'ubuntu')
&& contains(fromJSON('["", "Linux"]'), inputs.target-platform)
&& contains(fromJSON('["", "Flatpak"]'), inputs.target-format)
&& contains(fromJSON('["Toga", "PyGame"]'), inputs.framework)
working-directory: ${{ steps.create.outputs.project-path }}
run: |
sudo apt-get update -y
sudo apt-get install -y flatpak flatpak-builder
sudo apt update -y
sudo apt install -y flatpak flatpak-builder
cd tests/apps/verify-${{ inputs.framework }}
briefcase create linux flatpak
briefcase build linux flatpak
briefcase package linux flatpak --adhoc-sign
Expand All @@ -285,8 +278,8 @@ jobs:
contains(fromJSON('["", "Android"]'), inputs.target-platform)
&& contains(fromJSON('["", "Gradle"]'), inputs.target-format)
&& startsWith(inputs.framework, 'toga')
working-directory: ${{ steps.create.outputs.project-path }}
run: |
cd tests/apps/verify-${{ inputs.framework }}
briefcase create android gradle
briefcase build android gradle
briefcase package android gradle --adhoc-sign
Expand All @@ -297,8 +290,8 @@ jobs:
&& contains(fromJSON('["", "iOS"]'), inputs.target-platform)
&& contains(fromJSON('["", "Xcode"]'), inputs.target-format)
&& startsWith(inputs.framework, 'toga')
working-directory: ${{ steps.create.outputs.project-path }}
run: |
cd tests/apps/verify-${{ inputs.framework }}
briefcase create iOS xcode
briefcase build iOS xcode
briefcase package iOS xcode --adhoc-sign
Expand All @@ -308,13 +301,13 @@ jobs:
contains(fromJSON('["", "web"]'), inputs.target-platform)
&& contains(fromJSON('["", "static"]'), inputs.target-format)
&& startsWith(inputs.framework, 'toga')
working-directory: ${{ steps.create.outputs.project-path }}
run: |
cd tests/apps/verify-${{ inputs.framework }}
briefcase create web static
briefcase build web static
briefcase package web static
- name: Upload failure logs
- name: Upload Failure Logs
uses: actions/upload-artifact@v3.1.3
if: failure()
with:
Expand Down
Loading

0 comments on commit 2f6a58c

Please sign in to comment.