diff --git a/.github/workflows/enforce-labels.yml b/.github/workflows/enforce-labels.yml index 2f448866b0..0eee9af4cf 100644 --- a/.github/workflows/enforce-labels.yml +++ b/.github/workflows/enforce-labels.yml @@ -4,6 +4,10 @@ name: Enforce PR labels on: pull_request: types: [labeled, unlabeled, opened, edited, synchronize] + workflow_run: + workflows: [Protect Files] + types: [completed] + jobs: enforce-label: name: EnforceLabel @@ -12,5 +16,5 @@ jobs: - name: Enforce Label uses: yogevbd/enforce-label-action@a3c219da6b8fa73f6ba62b68ff09c469b3a1c024 with: - BANNED_LABELS: "hold, DB migrations changed" + BANNED_LABELS: "hold,DB-migrations-changed" BANNED_LABELS_DESCRIPTION: "PRs with ${bannedLabel.name} label cannot be merged" diff --git a/.github/workflows/protect-files.yml b/.github/workflows/protect-files.yml index 685d6be2d7..1c10e517f1 100644 --- a/.github/workflows/protect-files.yml +++ b/.github/workflows/protect-files.yml @@ -7,10 +7,11 @@ name: Protect Files on: pull_request: - types: + types: - opened - synchronize - paths: + - unlabeled + paths: - "util/Migrator/DbScripts/**.sql" jobs: @@ -18,7 +19,7 @@ jobs: name: Check for file changes runs-on: ubuntu-20.04 outputs: - changes: steps.check-changes.outputs.changes_detected + changes: ${{steps.check-changes.outputs.changes_detected}} strategy: fail-fast: true @@ -26,34 +27,29 @@ jobs: include: - name: Database Scripts path: util/Migrator/DbScripts - label: "DB migrations changed" + label: "DB-migrations-changed" steps: - - name: Checkout PR + - name: Checkout repo uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b with: - fetch-depth: 0 + fetch-depth: 2 - name: Check for file changes id: check-changes run: | - MODIFIED_FILES=$(git diff --name-only --diff-filter=M ${GITHUB_BASE_REF}) + MODIFIED_FILES=$(git diff --name-only --diff-filter=M HEAD~1) - for file in $MODIFIED_FILES; do - if [[ $file == *"${{ matrix.path }}"*]]; then - echo "::set-output name=changes_detected::'true'" + for file in $MODIFIED_FILES + do + if [[ $file == *"${{ matrix.path }}"* ]]; then + echo "::set-output name=changes_detected::true" break - else echo "::set-output name=changes_detected::'false'" + else echo "::set-output name=changes_detected::false" fi done - label-pr: - name: Add label to pull request - runs-on: ubuntu-20.04 - needs: - - changed-files - if: needs.changed-files.outputs.changes == "true" || job.changed-files.status == "failure" - steps: - - name: Label PR + - name: Add label to pull request + if: contains(steps.check-changes.outputs.changes_detected, true) uses: andymckay/labeler@e6c4322d0397f3240f0e7e30a33b5c5df2d39e90 with: add-labels: ${{ matrix.label }}