Skip to content

Commit

Permalink
Switched to body-based trigger.
Browse files Browse the repository at this point in the history
  • Loading branch information
grigorye committed Jun 29, 2023
1 parent b3797f9 commit aa5c279
Showing 1 changed file with 50 additions and 6 deletions.
56 changes: 50 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,61 @@ on:
push:
branches: [main]
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
types: [opened, synchronize, reopened, ready_for_review, edited]

defaults:
run:
shell: bash --noprofile --norc -x -euo pipefail {0}

jobs:
pr-trigger:
name: 'PR Trigger Filter'
runs-on: ubuntu-latest
outputs:
should-test: ${{ steps.filter.outputs.should-test }}
should-build: ${{ steps.filter.outputs.should-build }}
env:
GH_TOKEN: ${{ secrets.ON_DEMAND_TRIGGER_GH_TOKEN }}

steps:
- name: 'Filter body'
if: ${{ github.event_name == 'pull_request' && github.event.action == 'edited' }}
id: filter
run: |
echo "should-test=false" >> $GITHUB_OUTPUT
echo "should-build=false" >> $GITHUB_OUTPUT
jq . "$GITHUB_EVENT_PATH"
new_body=$(jq -r '.pull_request.body' "$GITHUB_EVENT_PATH")
old_body=$(jq -r '.changes.body.from' "$GITHUB_EVENT_PATH")
if ! [[ "$new_body" =~ '- [x] *Run* checks:' && "$old_body" =~ '- [ ] *Run* checks:' ]]; then
exit 0
fi
if [[ "$new_body" =~ '- [x] all' ]]; then
echo "should-test=true" >> $GITHUB_OUTPUT
echo "should-build=true" >> $GITHUB_OUTPUT
fi
if [[ "$new_body" =~ '- [x] tests' ]]; then
echo "should-test=true" >> $GITHUB_OUTPUT
fi
if [[ "$new_body" =~ '- [x] build app' ]]; then
echo "should-build=true" >> $GITHUB_OUTPUT
fi
# Change the body, to allow re-triggering.
updated_body=$(echo "$new_body" | sed 's/- \[x\] \*Run\* checks:/- [ ] \*Run\* checks:/')
pr_number=${{ github.event.pull_request.number }}
gh pr edit "$pr_number" --body "$updated_body" --repo "${{ github.repository }}"
paths-filter:
needs: pr-trigger
if : ${{ github.event_name != 'pull_request' || needs.pr-trigger.outputs.should-test == 'true' || needs.pr-trigger.outputs.should-build == 'true' }}
name: 'Paths Filter'
uses: ./.github/workflows/paths-filter.yml

tests:
name: 'Tests'
needs: [paths-filter]
if: ${{ !inputs.skip-tests && github.event.pull_request.draft != true && needs.paths-filter.outputs.should-test != 'false' }}
needs: [paths-filter, pr-trigger]
if: ${{ !inputs.skip-tests && github.event.pull_request.draft != true && needs.paths-filter.outputs.should-test != 'false' && (github.event_name != 'pull_request' || needs.pr-trigger.outputs.should-test == 'true') }}
uses: grigorye/ReusableWorkflows/.github/workflows/tests-generic.yml@v20
secrets: inherit
with:
Expand All @@ -38,8 +82,8 @@ jobs:

build-app:
name: 'App'
needs: [paths-filter]
if: ${{ !inputs.skip-build-app && github.event.pull_request.draft != true && needs.paths-filter.outputs.should-build != 'false' }}
needs: [paths-filter, pr-trigger]
if: ${{ !inputs.skip-build-app && github.event.pull_request.draft != true && needs.paths-filter.outputs.should-build != 'false' && (github.event_name != 'pull_request' || needs.pr-trigger.outputs.should-build == 'true') }}
uses: grigorye/ReusableWorkflows/.github/workflows/build-app-generic.yml@v20
with:
macos-app-scheme: 'TMBuddy'
Expand Down

0 comments on commit aa5c279

Please sign in to comment.