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

Switched to on demand running of workflows in PRs. #112

Merged
merged 6 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .github/workflows/filter-on-pr-label-or-input.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: main

on:
workflow_call:
inputs:
action:
description: "Action (xxx `ci: xxx` in PR labels)"
type: string
skip-non-pr:
description: "Whether to skip non-PR events"
type: string # true | false
default: 'true'
required: false
outputs:
should-run:
value: ${{ jobs.filter.outputs.should-run }}

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

jobs:
filter:
name: 'Analysis'
runs-on: ubuntu-latest
outputs:
should-run: ${{ steps.filter.outputs.should-run }}
env:
GH_TOKEN: ${{ secrets.ON_DEMAND_TRIGGER_GH_TOKEN }}
steps:
- name: 'Filter'
id: filter
run: |
action="${{ inputs.action }}"
if ${{ github.event_name != 'pull_request' }}; then
if ${{ inputs.skip-non-pr == 'false' }}; then
should_run=true
else
should_run=false
fi
else
PR_NUMBER=${{ github.event.pull_request.number }}
labels=($(gh pr view "$PR_NUMBER" --repo "$GITHUB_REPOSITORY" --json labels --jq .labels.[].name))
if [[ " ${labels[@]} " =~ "ci: $action" ]]; then
printf -v "should_run" "%s" "true" # https://stackoverflow.com/a/16973754/1859783
else
printf -v "should_run" "%s" "false"
fi
fi
echo "should-run=$should_run" >> $GITHUB_OUTPUT
65 changes: 28 additions & 37 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,41 @@ on:
required: false
default: false
type: boolean

push:
branches: [main]
pull_request:
types: [opened, synchronize, reopened, ready_for_review]

pull_request: {}

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

jobs:
tests-filter:
name: 'Filter Tests'
uses: ./.github/workflows/filter-on-pr-label-or-input.yml
secrets: inherit
with:
action: 'tests'
skip-non-pr: ${{ inputs.skip-tests }}

build-app-filter:
name: 'Filter Build App'
uses: ./.github/workflows/filter-on-pr-label-or-input.yml
secrets: inherit
with:
action: 'build-app'
skip-non-pr: ${{ inputs.skip-build-app }}

paths-filter:
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, tests-filter]
if: ${{ !inputs.skip-tests && github.event.pull_request.draft != true && needs.paths-filter.outputs.should-test != 'false' && needs.tests-filter.outputs.should-run == 'true' }}
uses: grigorye/ReusableWorkflows/.github/workflows/tests-generic.yml@v20
secrets: inherit
with:
Expand All @@ -38,39 +58,10 @@ 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, build-app-filter]
if: ${{ !inputs.skip-build-app && github.event.pull_request.draft != true && needs.paths-filter.outputs.should-build != 'false' && needs.build-app-filter.outputs.should-run == 'true' }}
uses: grigorye/ReusableWorkflows/.github/workflows/build-app-generic.yml@v20
with:
macos-app-scheme: 'TMBuddy'
build-configs: '[\"app-store\", \"developer-id\"]'
secrets: inherit

finalize:
name: 'Finalize Run'
if: always()
needs: [paths-filter, tests, build-app]
runs-on: ubuntu-latest
steps:
- name: 'Flag non-succeeding app builds'
if: always() && needs.paths-filter.outputs.should-build != 'false' && needs.build-app.result != 'success'
uses: actions/github-script@v6
with:
script: |
core.setFailed('Some app build did not succeed.')
- name: 'Flag tests that did not run'
if: always() && needs.paths-filter.outputs.should-test != 'false' && needs.tests.result != 'success'
uses: actions/github-script@v6
with:
script: |
core.setFailed('Some tests did not run.')
- name: 'Flag tests that did fail'
if: always() && needs.paths-filter.outputs.should-test != 'false' && needs.tests.outputs.tests-passed != 'true'
uses: actions/github-script@v6
with:
script: |
core.setFailed('Some tests did fail.')
- name: 'Report success for skipped jobs'
if: always() && needs.paths-filter.outputs.should-test == 'false' && needs.paths-filter.outputs.should-build == 'false'
run: |
echo 'No job to do.'