0

here is the workflow file:

## Automatically approve a PR if it does not modify the files contained in /prod_folder
name: auto-approve
on:
  pull_request:
    branches:
      - main

env:
  SHOULD_NOT_APPROVE_AUTOMATICALLY: 0

jobs:
  ## Check whether the /prod_folder has been modified
  check_prod_folder:
    runs-on: ubuntu-latest
    name: Check prod_folder Job
    if: contains(github.base_ref, 'main')
    steps:
      - name: Checkout repo
        uses: actions/checkout@v1
      - name: Get changed files
        id: get-changed-files
        uses: tj-actions/changed-files@v31
      - name: Setup variable if /prod_folder has been modified
        run: |
          for file in ${{ steps.get-changed-files.outputs.all_changed_files }}; do
            if [[ $file == *"prod_folder"* ]]; then
              echo "$file is within prod_folder"
              SHOULD_NOT_APPROVE_AUTOMATICALLY=1
              break
            else
              echo "$file is NOT within prod_folder"
            fi
          done
          echo "SHOULD_NOT_APPROVE_AUTOMATICALLY: $SHOULD_NOT_APPROVE_AUTOMATICALLY"
      - name: Auto Merge if env var is 0
        if: ${{ env.SHOULD_NOT_APPROVE_AUTOMATICALLY == 0 }}
        uses: "pascalgn/automerge-action@v0.15.3"
        env:
          GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
          MERGE_LABELS: ""
          MERGE_METHOD: "squash"
          UPDATE_LABELS: ""
          UPDATE_METHOD: "rebase"

I can confirm that the "Setup variable" step works, as I changed one file in /prod_folder and got the following message that the variable is properly set to 1:

dev_folder/testview4.view.lkml is NOT within prod_folder
prod_folder/testview4.view.lkml is within prod_folder
SHOULD_NOT_APPROVE_AUTOMATICALLY: 1

However the last step is still executed (and the PR merged). Does anyone know why? Thanks!

  • As far as I can see env vars are not shared between steps and you need to do something specific to get this behavior. See https://docs.github.com/en/github-ae@latest/actions/learn-github-actions/environment-variables#passing-values-between-steps-and-jobs-in-a-workflow – DerMolly Oct 11 '22 at 22:27
  • Does this answer your question? [How do I set an env var with a bash expression in GitHub Actions?](https://stackoverflow.com/questions/57968497/how-do-i-set-an-env-var-with-a-bash-expression-in-github-actions) – DerMolly Oct 11 '22 at 22:35

0 Answers0