Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reusable actions to create and/or verify a new project #68

Merged
merged 9 commits into from
Nov 18, 2023
93 changes: 93 additions & 0 deletions .github/actions/app-create/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
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 $&')

# If a template is not in the PR, use inputs specified in CI workflow
if [ -z "${TEMPLATE_REPO}" ]; then
TEMPLATE_REPO="${{ inputs.briefcase-template-source }}"
fi
if [ -z "${TEMPLATE_REF}" ]; then
TEMPLATE_REF="${{ inputs.briefcase-template-branch }}"
fi

# Expose template repo and branch via outputs
echo "repo=${TEMPLATE_REPO}" | tee -a ${GITHUB_OUTPUT}
echo "ref=${TEMPLATE_REF}" | tee -a ${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}
10 changes: 4 additions & 6 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 All @@ -58,10 +58,8 @@ runs:
fi

# Expose repo and version via outputs
echo "Briefcase Repo: ${BRIEFCASE_REPO}"
echo "Briefcase Ref: ${BRIEFCASE_REF}"
echo "repo=${BRIEFCASE_REPO}" >> ${GITHUB_OUTPUT}
echo "ref=${BRIEFCASE_REF}" >> ${GITHUB_OUTPUT}
echo "repo=${BRIEFCASE_REPO}" | tee -a ${GITHUB_OUTPUT}
echo "ref=${BRIEFCASE_REF}" | tee -a ${GITHUB_OUTPUT}
freakboy3742 marked this conversation as resolved.
Show resolved Hide resolved

- name: Derive Target Briefcase Version
id: briefcase-derived
Expand Down
Loading
Loading