From 751e9e05e8f05209ed61cfac207c639082089293 Mon Sep 17 00:00:00 2001 From: Grigory Entin Date: Mon, 26 Jun 2023 03:24:11 +0200 Subject: [PATCH] Employed labels for dispatching. --- .github/workflows/main.yml | 35 +++++++++------------ .github/workflows/on-pr-comment-trigger.yml | 30 ++++++++++++++++++ 2 files changed, 44 insertions(+), 21 deletions(-) create mode 100644 .github/workflows/on-pr-comment-trigger.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 82ca0f40..248c7aee 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,10 +18,7 @@ on: branches: [main] pull_request: - types: [opened, synchronize, reopened, ready_for_review] - - issue_comment: - types: [created, edited, deleted] + types: [opened, synchronize, reopened, ready_for_review, labeled] defaults: run: @@ -32,32 +29,28 @@ 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 comments' + - name: 'Filter labels' id: filter + if: ${{ github.event_name == 'pull_request' && github.event.action == 'labeled' }} 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.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 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: @@ -68,8 +61,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' diff --git a/.github/workflows/on-pr-comment-trigger.yml b/.github/workflows/on-pr-comment-trigger.yml new file mode 100644 index 00000000..db15f01a --- /dev/null +++ b/.github/workflows/on-pr-comment-trigger.yml @@ -0,0 +1,30 @@ +name: main + +on: + issue_comment: + types: [created, edited, deleted] + +defaults: + run: + shell: bash --noprofile --norc -x -euo pipefail {0} + +jobs: + comments-filter: + name: 'Comments filter' + runs-on: ubuntu-latest + permissions: + pull-requests: write + issues: write + steps: + - name: 'Filter comments' + if: ${{ github.event_name == 'issue_comment' }} + run: | + if [[ "${{ github.event.comment.body }}" =~ '@ci test this please' ]]; then + gh pr edit "$PR" --add-label 'ci: test' -R ${{ github.repository }} + fi + if [[ "${{ github.event.comment.body }}" =~ '@ci build this please' ]]; then + gh pr edit "$PR" --add-label 'ci: build' -R ${{ github.repository }} + fi + env: + PR: ${{ github.event.issue.number }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}