From 893ddfda23e5cf91fbf81a3bd75cd4e9c1258209 Mon Sep 17 00:00:00 2001 From: Grigory Entin Date: Mon, 26 Jun 2023 01:29:01 +0200 Subject: [PATCH] Implemented basic comment-based job filtering. --- .github/workflows/main.yml | 40 ++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5c96cbec..82ca0f40 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -16,16 +16,48 @@ on: push: branches: [main] + + pull_request: + types: [opened, synchronize, reopened, ready_for_review] + + issue_comment: + types: [created, edited, deleted] +defaults: + run: + shell: bash --noprofile --norc -x -euo pipefail {0} + jobs: paths-filter: name: 'Paths Filter' uses: ./.github/workflows/paths-filter.yml + comments-filter: + name: 'Comments Filter' + runs-on: ubuntu-latest + outputs: + should-test: ${{ steps.filter.outputs.should-test }} + should-build: ${{ steps.filter.outputs.should-build }} + + steps: + - name: 'Filter comments' + id: filter + 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 + fi + 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, 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' }} uses: grigorye/ReusableWorkflows/.github/workflows/tests-generic.yml@v20 secrets: inherit with: @@ -36,8 +68,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, 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' }} uses: grigorye/ReusableWorkflows/.github/workflows/build-app-generic.yml@v20 with: macos-app-scheme: 'TMBuddy'