Home > Enterprise >  GitAction: Trigger workflow on PR approval AND when base branch is main AND .csv file is updated
GitAction: Trigger workflow on PR approval AND when base branch is main AND .csv file is updated

Time:10-04

I was trying with following code but it is not taking care of all 3 conditions due to following reason:

  1. base_ref will only work on pull_request/push event not on pull_request_review
  2. action dorny/[email protected] only works with pull_request/push event
on:
  pull_request_review:
    types: [submitted]
    branches:
      - main

jobs:
  myJob:
    name: myJob
    if: github.event.review.state == 'approved' && startsWith(github.base_ref, 'main/')
    runs-on: [self-hosted, prd]
    steps:
      - name: Checkout repository
        uses: actions/[email protected]
      - name: Check if *.csv is modified
        uses: dorny/[email protected]
        id: changes
        with:
          filters: |
            csv:
              - 'data/*.csv'    
      - name: Run process bmv script
        if: ${{ steps.changes.outputs.csv == 'true' }}
        run: |
          echo "-Started running script-"

Can any one suggest how can i handle all 3 conditions : PR approval, base branch as main and only csv is modified.

CodePudding user response:

Finally I got the answer by doing Matteo's way and also tweaking existing code. Tweaks: Updated dorny/[email protected] to dorny/[email protected] as this version support it to work on other than pull/pill_request events.

on:
  pull_request_review:
    types: [submitted]

jobs:
  myJob:
    name: myJob
    if: startsWith(github.event.pull_request.base.ref, 'main') && (github.event.review.state == 'approved')
    runs-on: [self-hosted, prd]
    steps:
      - name: Checkout repository
        uses: actions/[email protected]
      - name: Check if *.csv is modified
        uses: dorny/[email protected]
        id: changes
        with:
          filters: |
            csv:
              - 'data/*.csv'    
      - name: Run process bmv script
        if: ${{ steps.changes.outputs.csv == 'true' }}
        run: |
          echo "-Started running script-"

Thanks for all the help, above is the complete working solution which check for all 3 conditions i.e run workflow only when PR is approved and PR has base branch as main and only csv file inside data folder is modified.

  • Related