-
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.
Refactor PR Body regexing into independent GH Action
- Loading branch information
Showing
4 changed files
with
321 additions
and
220 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 |
---|---|---|
|
@@ -22,50 +22,56 @@ outputs: | |
project-path: | ||
value: ${{ steps.create.outputs.path }} | ||
description: "The file path to the root of the created project." | ||
briefcase-template-repo: | ||
value: ${{ steps.template.outputs.repo }} | ||
description: "Template repo used to create app." | ||
briefcase-template-ref: | ||
value: ${{ steps.template.outputs.ref }} | ||
description: "Template ref used to create app." | ||
|
||
|
||
runs: | ||
using: composite | ||
steps: | ||
- name: Briefcase Template Override | ||
id: template-override | ||
env: | ||
GITHUB_TOKEN: ${{ github.token }} | ||
- name: Checkout beeware/.github | ||
uses: actions/[email protected] | ||
with: | ||
path: beeware-app-create-.github | ||
|
||
- name: Check for Briefcase Template Repo Override | ||
id: template-repo-override | ||
uses: ./beeware-app-create-.github/.github/actions/pr-body-parse | ||
with: | ||
key-regex: 'BRIEFCASE[-_]*TEMPLATE[-_]*REPO' | ||
testing-pr-body: ${{ inputs.testing-pr-body }} | ||
|
||
- name: Check for Briefcase Template Ref Override | ||
id: template-ref-override | ||
uses: ./beeware-app-create-.github/.github/actions/pr-body-parse | ||
with: | ||
key-regex: 'BRIEFCASE[-_]*TEMPLATE[-_]*REF' | ||
testing-pr-body: ${{ inputs.testing-pr-body }} | ||
|
||
- name: Declare Briefcase Template | ||
id: template | ||
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 $&') | ||
REPO="${{ steps.template-repo-override.outputs.extracted-value || inputs.briefcase-template-source }}" | ||
REF="${{ steps.template-ref-override.outputs.extracted-value || inputs.briefcase-template-branch }}" | ||
# 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 }}" | ||
if [ -n "${REPO}" ]; then | ||
printf -- "repo=%q\n" "${REPO}" | tee -a ${GITHUB_OUTPUT} | ||
printf -- "repo-cmdline=--template '%q'\n" "${REPO}" | tee -a ${GITHUB_OUTPUT} | ||
fi | ||
if [ -z "${TEMPLATE_REF}" ]; then | ||
TEMPLATE_REF="${{ inputs.briefcase-template-branch }}" | ||
if [ -n "${REF}" ]; then | ||
printf -- "ref=%q\n" "${REF}" | tee -a ${GITHUB_OUTPUT} | ||
printf -- "ref-cmdline=--template-branch '%q'\n" "${REF}" | tee -a ${GITHUB_OUTPUT} | ||
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 GUI toolkit through case insensitivity | ||
case "$(tr '[:upper:]' '[:lower:]' <<< "${{ inputs.framework }}")" in | ||
toga ) BOOTSTRAP=Toga ;; | ||
|
@@ -89,7 +95,9 @@ runs: | |
rm -rf "${APP_DIR}" | ||
# Roll out the project | ||
briefcase new --no-input ${TEMPLATE} ${TEMPLATE_BRANCH} \ | ||
briefcase new --no-input \ | ||
${{ steps.template.outputs.repo-cmdline }} \ | ||
${{ steps.template.outputs.ref-cmdline }} \ | ||
-Q "formal_name=${APP_NAME}" \ | ||
-Q "app_name=${APP_DIR}" \ | ||
-Q "bootstrap=${BOOTSTRAP}" | ||
|
@@ -99,4 +107,5 @@ runs: | |
echo " > Bootstrap: ${BOOTSTRAP}" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,38 +32,38 @@ outputs: | |
runs: | ||
using: composite | ||
steps: | ||
- name: Use Specified Briefcase Version | ||
id: briefcase-override | ||
env: | ||
GITHUB_TOKEN: ${{ github.token }} | ||
- name: Checkout beeware/.github | ||
uses: actions/[email protected] | ||
with: | ||
path: beeware-install-briefcase-.github | ||
|
||
- name: Check for Briefcase Repo Override | ||
id: briefcase-repo-override | ||
uses: ./beeware-install-briefcase-.github/.github/actions/pr-body-parse | ||
with: | ||
key-regex: 'BRIEFCASE[-_]*REPO' | ||
testing-pr-body: ${{ inputs.testing-pr-body }} | ||
|
||
- name: Check for Briefcase Ref Override | ||
id: briefcase-ref-override | ||
uses: ./beeware-install-briefcase-.github/.github/actions/pr-body-parse | ||
with: | ||
key-regex: 'BRIEFCASE[-_]*REF' | ||
testing-pr-body: ${{ inputs.testing-pr-body }} | ||
|
||
- name: Declare Briefcase Source | ||
id: briefcase | ||
shell: bash | ||
run: | | ||
# 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') | ||
fi | ||
printf "::group::Retrieved PR Body\n%s\n::endgroup::\n" "${PR_BODY}" | ||
BRIEFCASE_REPO=$(printf "%s" "${PR_BODY}" | perl -wlne '/BRIEFCASE[-_]*REPO:\s*\K\S+/i and print $&') | ||
BRIEFCASE_REF=$(printf "%s" "${PR_BODY}" | perl -wlne '/BRIEFCASE[-_]*REF:\s*\K\S+/i and print $&') | ||
# If a version is not in the PR, use inputs specified in CI workflow | ||
if [ -z "${BRIEFCASE_REPO}" ]; then | ||
BRIEFCASE_REPO="${{ inputs.briefcase-url }}" | ||
fi | ||
if [ -z "${BRIEFCASE_REF}" ]; then | ||
BRIEFCASE_REF="${{ inputs.briefcase-override-version }}" | ||
fi | ||
REPO="${{ steps.briefcase-repo-override.outputs.extracted-value || inputs.briefcase-url }}" | ||
REF="${{ steps.briefcase-ref-override.outputs.extracted-value || inputs.briefcase-override-version }}" | ||
# Expose repo and version via outputs | ||
echo "repo=${BRIEFCASE_REPO}" | tee -a ${GITHUB_OUTPUT} | ||
echo "ref=${BRIEFCASE_REF}" | tee -a ${GITHUB_OUTPUT} | ||
printf -- "repo=%s\n" "${REPO}" | tee -a ${GITHUB_OUTPUT} | ||
printf -- "ref=%s\n" "${REF}" | tee -a ${GITHUB_OUTPUT} | ||
- name: Derive Target Briefcase Version | ||
id: briefcase-derived | ||
if: steps.briefcase-override.outputs.ref == '' | ||
if: steps.briefcase.outputs.ref == '' | ||
shell: bash | ||
run: | | ||
# Branch or tag that triggered the workflow. | ||
|
@@ -136,8 +136,8 @@ runs: | |
id: install | ||
shell: bash | ||
run: | | ||
REPO="${{ steps.briefcase-override.outputs.repo || inputs.briefcase-url }}" | ||
REF="${{ steps.briefcase-override.outputs.ref || steps.briefcase-derived.outputs.version }}" | ||
REPO="${{ steps.briefcase.outputs.repo }}" | ||
REF="${{ steps.briefcase.outputs.ref || steps.briefcase-derived.outputs.version }}" | ||
echo "Installing ${REPO}@${REF}" | ||
python -m pip install \ | ||
|
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,37 @@ | ||
name: PR Body Parse | ||
description: Parse a value from the body of the relevant PR for a specific key | ||
|
||
inputs: | ||
key-regex: | ||
description: "The regex for the key identifying the value to return, e.g. BRIEFCASE[-_]*REPO" | ||
required: true | ||
testing-pr-body: | ||
description: "Override value for body of PR; only for testing." | ||
required: false | ||
|
||
outputs: | ||
extracted-value: | ||
value: ${{ steps.parse.outputs.extracted-value }} | ||
description: "The value extracted from the PR's body for the specified key." | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
- name: Parse PR Body for ${{ inputs.key-regex }} | ||
id: parse | ||
env: | ||
GITHUB_TOKEN: ${{ github.token }} | ||
shell: bash | ||
run: | | ||
# Retrieve PR Body (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}" | ||
# Parse value with given regex | ||
EXTRACTED_VALUE=$(printf "%s" "${PR_BODY}" | perl -wlne '/${{ inputs.key-regex }}:\s*\K\S+/i and print $&') | ||
# Expose value as an output | ||
printf -- "extracted-value=%s\n" "${EXTRACTED_VALUE}" | tee -a ${GITHUB_OUTPUT} |
Oops, something went wrong.