-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add reusable actions to create and/or verify a new project
- Loading branch information
Showing
5 changed files
with
284 additions
and
59 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
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_NAME="Verify App" | ||
APP_DIR="verifyapp" | ||
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 "%s\n%s\n\n\n\n\n\n\n\n%s\n" "${APP_NAME}" "${APP_DIR}" "${GUI_INPUT}" \ | ||
| briefcase new ${TEMPLATE} ${TEMPLATE_BRANCH} | ||
echo "Rolled out project to ${APP_PATH} (${{ inputs.framework }}->${GUI_INPUT})" | ||
printf "::group::pyproject.toml\n%s\n::endgroup::\n" "$(cat "${APP_DIR}/pyproject.toml")" | ||
printf "::group::app.py\n%s\n::endgroup::\n" "$(cat "${APP_DIR}/src/${APP_DIR}/app.py")" | ||
echo "path=${APP_PATH}" >> ${GITHUB_OUTPUT} |
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 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
Oops, something went wrong.