Skip to content

Commit 26f859e

Browse files
authored
ci: auto-dedupe yarn.lock file for PRs created by bots (#5982)
Otherwise this would block the PR if the `yarn.lock` file wasn't properly deduped by the changes made by the bot.
1 parent 464af85 commit 26f859e

File tree

2 files changed

+51
-18
lines changed

2 files changed

+51
-18
lines changed

.github/scripts/yarn-dedupe.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env bash
2+
3+
set -ex
4+
5+
if git diff --exit-code yarn.lock; then
6+
echo "✅ yarn.lock is already properly deduplicated"
7+
else
8+
echo "📝 yarn.lock was modified by dedupe command"
9+
10+
PR_AUTHOR="${PR_AUTHOR:-}"
11+
PR_USER_TYPE="${PR_USER_TYPE:-}"
12+
13+
if [[ "$PR_USER_TYPE" == "Bot" ]] && [[ "${GITHUB_EVENT_NAME:-}" == "pull_request" ]]; then
14+
echo "🤖 Bot-created PR detected. Auto-committing yarn.lock changes..."
15+
16+
git config --local user.email "action@github.com"
17+
git config --local user.name "GitHub Action"
18+
19+
git add yarn.lock
20+
git commit -m "Auto-dedupe yarn.lock dependencies"
21+
22+
git push origin HEAD:${GITHUB_HEAD_REF}
23+
24+
echo "✅ Successfully committed and pushed yarn.lock deduplication"
25+
else
26+
echo "❌ The yarn.lock file needs deduplication!"
27+
echo ""
28+
echo "The yarn dedupe command has modified your yarn.lock file."
29+
echo "This means there were duplicate dependencies that could be optimized."
30+
echo ""
31+
echo "To fix this issue:"
32+
echo "1. Run 'yarn dependencies:dedupe' locally"
33+
echo "2. Commit the updated yarn.lock file"
34+
echo "3. Push your changes"
35+
echo ""
36+
echo "This helps keep the dependency tree clean."
37+
exit 1
38+
fi
39+
fi

.github/workflows/project.yml

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,15 @@ jobs:
9999

100100
yarn-dedupe:
101101
runs-on: ubuntu-latest
102+
permissions:
103+
contents: write
104+
pull-requests: read
102105
steps:
103106
- name: Checkout code
104107
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
108+
with:
109+
token: ${{ secrets.GITHUB_TOKEN }}
110+
fetch-depth: 0
105111

106112
- name: Setup Node.js
107113
uses: ./.github/actions/node/active-lts
@@ -112,21 +118,9 @@ jobs:
112118
- name: Run yarn dependencies:dedupe
113119
run: yarn dependencies:dedupe
114120

115-
- name: Check if yarn.lock was modified
116-
run: |
117-
if git diff --exit-code yarn.lock; then
118-
echo "✅ yarn.lock is already properly deduplicated"
119-
else
120-
echo "❌ The yarn.lock file needs deduplication!"
121-
echo ""
122-
echo "The yarn dedupe command has modified your yarn.lock file."
123-
echo "This means there were duplicate dependencies that could be optimized."
124-
echo ""
125-
echo "To fix this issue:"
126-
echo "1. Run 'yarn dependencies:dedupe' locally"
127-
echo "2. Commit the updated yarn.lock file"
128-
echo "3. Push your changes"
129-
echo ""
130-
echo "This helps keep the dependency tree clean."
131-
exit 1
132-
fi
121+
- name: Run yarn dedupe check
122+
run: ./.github/scripts/yarn-dedupe.sh
123+
env:
124+
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
125+
PR_USER_TYPE: ${{ github.event.pull_request.user.type }}
126+
GITHUB_EVENT_NAME: ${{ github.event_name }}

0 commit comments

Comments
 (0)