-
Notifications
You must be signed in to change notification settings - Fork 1.5k
40 lines (36 loc) · 1.38 KB
/
Copy pathblock-remove-before-merge.yml
File metadata and controls
40 lines (36 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Copyright (c) Microsoft Corporation. All rights reserved.
name: "Block remove-before-merge paths"
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review, edited]
merge_group:
permissions:
contents: read
jobs:
check-paths:
name: "No remove-before-merge directories"
if: github.event_name == 'pull_request' && github.base_ref == 'main'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
timeout-minutes: 4
with:
fetch-depth: 2
- name: Check for remove-before-merge paths in PR
run: |
# pull_request checks out the merge commit; its first parent is the base.
git rev-parse --verify HEAD^2 >/dev/null 2>&1 || {
echo "::error::Expected a pull request merge commit."
exit 1
}
FILES_FILE=$(mktemp)
trap 'rm -f "$FILES_FILE"' EXIT
git diff --name-only -z HEAD^1 HEAD > "$FILES_FILE"
if grep -zqE '(^|/)[-a-zA-Z0-9_]+-remove-before-merge(/|$)' "$FILES_FILE"; then
echo "::error::This PR contains files under a 'remove-before-merge' directory. Remove them before merging."
echo ""
echo "Offending paths:"
grep -zE '(^|/)[-a-zA-Z0-9_]+-remove-before-merge(/|$)' "$FILES_FILE" | tr '\0' '\n'
exit 1
fi
echo "No remove-before-merge paths found. ✅"