Skip to content

Commit

Permalink
Employed labels for dispatching.
Browse files Browse the repository at this point in the history
  • Loading branch information
grigorye committed Jun 26, 2023
1 parent 893ddfd commit cc22833
Showing 1 changed file with 33 additions and 17 deletions.
50 changes: 33 additions & 17 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ on:
branches: [main]

pull_request:
types: [opened, synchronize, reopened, ready_for_review]
types: [opened, synchronize, reopened, ready_for_review, labeled]

issue_comment:
types: [created, edited, deleted]
Expand All @@ -32,32 +32,48 @@ jobs:
name: 'Paths Filter'
uses: ./.github/workflows/paths-filter.yml

comments-filter:
name: 'Comments Filter'
labels-filter:
name: 'Labels Filter'
runs-on: ubuntu-latest
outputs:
should-test: ${{ steps.filter.outputs.should-test }}
should-build: ${{ steps.filter.outputs.should-build }}
steps:
- name: 'Filter labels'
id: filter
if: ${{ github.event_name == 'pull_request' && github.event.action == 'labeled' }}
run: |
if [[ "${{ github.event.label.name }}" =~ 'ci: test' ]]; then
echo "should-test=true" >> $GITHUB_OUTPUT
fi
if [[ "${{ github.event.label.name }}" =~ 'ci: build' ]]; then
echo "should-build=true" >> $GITHUB_OUTPUT
fi
comments-filter:
name: 'Comments filter'
runs-on: ubuntu-latest
permissions:
pull-requests: write
issues: write
steps:
- name: 'Filter comments'
id: filter
if: ${{ github.event_name == 'issue_comment' }}
run: |
echo "should-test=false" >> $GITHUB_OUTPUT
echo "should-build=false" >> $GITHUB_OUTPUT
if [[ "${{ github.event_name }}" == 'issue_comment' ]]; then
if [[ "${{ github.event.comment.body }}" =~ '@ci test this please' ]]; then
echo "should-test=true" >> $GITHUB_OUTPUT
fi
if [[ "${{ github.event.comment.body }}" =~ '@ci build this please' ]]; then
echo "should-build=true" >> $GITHUB_OUTPUT
fi
if [[ "${{ github.event.comment.body }}" =~ '@ci test this please' ]]; then
gh pr edit "$PR" --add-label 'ci: test'
fi
if [[ "${{ github.event.comment.body }}" =~ '@ci build this please' ]]; then
gh pr edit "$PR" --add-label 'ci: build'
fi
env:
PR: ${{ github.event.issue.number }}
GH_TOKEN: ${{ github.token }}

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

build-app:
name: 'App'
needs: [paths-filter, comments-filter]
if: ${{ !inputs.skip-build-app && github.event.pull_request.draft != true && needs.paths-filter.outputs.should-build != 'false' && needs.comments-filter.outputs.should-build == 'true' }}
needs: [paths-filter, labels-filter]
if: ${{ !inputs.skip-build-app && github.event.pull_request.draft != true && needs.paths-filter.outputs.should-build != 'false' && needs.labels-filter.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 cc22833

Please sign in to comment.