Skip to content

Commit

Permalink
Extracted filter-on-pr-label-or-input.yml.
Browse files Browse the repository at this point in the history
  • Loading branch information
grigorye committed Jun 29, 2023
1 parent ee58aaf commit bedcc0e
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 52 deletions.
48 changes: 48 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,48 @@
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: boolean
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
62 changes: 10 additions & 52 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,61 +26,19 @@ defaults:
jobs:
tests-filter:
name: 'Filter Tests'
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="test"
if ${{ github.event_name != 'pull_request' }}; then
if ${{ inputs.skip-tests == '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
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'
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="build-app"
if ${{ github.event_name != 'pull_request' }}; then
if ${{ inputs.skip-build-app == '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
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'
Expand Down

0 comments on commit bedcc0e

Please sign in to comment.