Skip to content

Commit 5b8f11a

Browse files
authored
Update enforce-codeowners.yml
1 parent 66066a2 commit 5b8f11a

File tree

1 file changed

+11
-24
lines changed

1 file changed

+11
-24
lines changed
Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Auto-Restore CODEOWNERS
1+
name: Enforce Original CODEOWNERS from Target Branch
22

33
on:
44
pull_request:
@@ -17,17 +17,17 @@ on:
1717
- hotfix
1818

1919
jobs:
20-
restore-codeowners:
20+
restore-original-codeowners:
2121
runs-on: ubuntu-latest
2222

2323
steps:
24-
- name: Checkout head branch
24+
- name: Checkout PR branch
2525
uses: actions/checkout@v3
2626
with:
2727
fetch-depth: 0
2828
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.ref_name }}
2929

30-
- name: Determine target and head branches
30+
- name: Get target and head branch
3131
id: vars
3232
run: |
3333
if [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then
@@ -38,32 +38,19 @@ jobs:
3838
echo "HEAD_BRANCH=${GITHUB_REF##*/}" >> $GITHUB_ENV
3939
fi
4040
41-
- name: Restore CODEOWNERS from template
41+
- name: Restore CODEOWNERS from target branch HEAD
4242
run: |
43-
echo "📌 Target branch: $TARGET_BRANCH"
44-
echo "📌 Head branch: $HEAD_BRANCH"
43+
echo "🔁 Restoring CODEOWNERS from base branch: $TARGET_BRANCH"
4544
46-
47-
# Normalize hotfix to use main's template
48-
if [[ "$TARGET_BRANCH" == "hotfix" ]]; then
49-
TEMPLATE=".github/CODEOWNERS.main"
50-
else
51-
TEMPLATE=".github/CODEOWNERS.$TARGET_BRANCH"
52-
fi
53-
54-
if [ -f "$TEMPLATE" ]; then
55-
cp "$TEMPLATE" .github/CODEOWNERS
56-
echo "✅ CODEOWNERS restored from $TEMPLATE"
57-
else
58-
echo "❌ No template found for branch: $TARGET_BRANCH"
59-
exit 1
60-
fi
45+
git fetch origin "$TARGET_BRANCH"
46+
git restore --source=origin/"$TARGET_BRANCH" --staged --worktree .github/CODEOWNERS
6147
48+
echo "✅ CODEOWNERS reset to match $TARGET_BRANCH"
6249
63-
- name: Commit and push updated CODEOWNERS
50+
- name: Commit and push restored CODEOWNERS
6451
run: |
6552
git config user.name "github-actions[bot]"
6653
git config user.email "github-actions[bot]@users.noreply.github.com"
6754
git add .github/CODEOWNERS
68-
git commit -m "ci: restore CODEOWNERS for $TARGET_BRANCH" || echo "ℹ️ No changes to commit"
55+
git commit -m "ci: restore CODEOWNERS from $TARGET_BRANCH" || echo "ℹ️ No changes to commit"
6956
git push origin HEAD:$HEAD_BRANCH || echo "ℹ️ Push skipped"

0 commit comments

Comments
 (0)