Skip to content

Commit 7ad5d51

Browse files
authored
chore: Automation to check changes in the peerDependencies (#20213)
1 parent 900dd64 commit 7ad5d51

File tree

2 files changed

+144
-1
lines changed

2 files changed

+144
-1
lines changed

.github/workflows/ci-continuous-integration.yml

+73-1
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,80 @@ jobs:
8787
- name: Run linting validation
8888
run: |
8989
ci-scripts/validate-lint.sh
90+
check_peer_dependencies:
91+
name: CI - Check peerDependencies
92+
runs-on: ubuntu-latest
93+
steps:
94+
- uses: actions/checkout@v4
95+
with:
96+
fetch-depth: 0
97+
- name: Setup node
98+
uses: actions/setup-node@v4
99+
with:
100+
node-version: ${{ env.NODE_VERSION }}
101+
- name: Run peerDependencies check
102+
run: |
103+
bash ci-scripts/check-peer-deps.sh ${{ github.event.pull_request.base.ref }}
104+
- name: Collect peer dependency changes
105+
id: collect-peer-deps
106+
run: |
107+
if [ -s peer-deps-result.txt ]; then
108+
echo "output<<EOF" >> $GITHUB_OUTPUT
109+
echo "### ❗ peerDependencies changes detected:" >> $GITHUB_OUTPUT
110+
cat peer-deps-result.txt >> $GITHUB_OUTPUT
111+
echo "EOF" >> $GITHUB_OUTPUT
112+
else
113+
echo "output=No peerDependencies changes detected" >> $GITHUB_OUTPUT
114+
fi
115+
- name: Post PR comment if peerDependencies changed
116+
if: failure() && github.event.pull_request
117+
uses: actions/github-script@v7
118+
with:
119+
github-token: ${{ secrets.GITHUB_TOKEN }}
120+
script: |
121+
const fs = require('fs');
122+
const path = 'peer-deps-result.txt';
123+
124+
if (!fs.existsSync(path)) {
125+
console.log("No peer-deps result file found. Skipping comment.");
126+
return;
127+
}
128+
129+
const diff = fs.readFileSync(path, 'utf8').trim();
130+
if (!diff) {
131+
console.log("peer-deps result file is empty. Skipping comment.");
132+
return;
133+
}
134+
135+
const issue_number = context.payload.pull_request.number;
136+
const owner = context.repo.owner;
137+
const repo = context.repo.repo;
138+
const botUser = context.actor;
139+
140+
const commentHeader = "🚨 **PeerDependencies Change Detected** 🚨";
141+
142+
const body = `
143+
${commentHeader}
144+
145+
Your pull request includes modifications to \`peerDependencies\` in the following file(s):
146+
147+
\`\`\`diff
148+
${diff}
149+
\`\`\`
150+
151+
Please note: Changes to peerDependencies are **restricted** and only permitted during **framework update releases**, as they may introduce breaking changes for customer's applications.
152+
If you believe this change is necessary, please reach out to the Asterix team for further assistance.
153+
`;
154+
155+
await github.rest.issues.createComment({
156+
issue_number,
157+
owner,
158+
repo,
159+
body
160+
});
161+
90162
ci_result:
91-
needs: [unit_tests, sonarqube_scan, linting]
163+
needs: [unit_tests, sonarqube_scan, linting, check_peer_dependencies]
92164
name: CI - Result
93165
runs-on: ubuntu-latest
94166
if: ${{ always() }}

ci-scripts/check-peer-deps.sh

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/bash
2+
3+
# Origin is passed as an argument to the script, defaulting to 'develop' if not provided.
4+
BASE_BRANCH=${1:-develop}
5+
6+
git fetch origin "$BASE_BRANCH:$BASE_BRANCH"
7+
8+
echo "🔍 Checking for changes in peerDependencies compared to $BASE_BRANCH..."
9+
10+
# Variable holds the list of changed package.json files
11+
# between the current branch and the base branch.
12+
changed_files=$(git diff --name-only "$BASE_BRANCH" HEAD -- '**/package.json')
13+
14+
# If no package.json files have changed, exit the script.
15+
if [ -z "$changed_files" ]; then
16+
echo "✅ No package.json files changed."
17+
exit 0
18+
fi
19+
20+
echo "📦 Changed package.json files:"
21+
echo "$changed_files"
22+
23+
# Create a temporary file to store changed peerDependencies in diff format.
24+
# This file is used to post PR comment later.
25+
result_file="peer-deps-result.txt"
26+
27+
failed=0
28+
29+
for file in $changed_files; do
30+
echo ""
31+
echo "🔧 Checking file: $file"
32+
33+
# Check if file exists on base branch; skip if it doesn't
34+
if ! git ls-tree -r "$BASE_BRANCH" --name-only | grep -qx "$file"; then
35+
echo "Skipping new file: $file (doesn't exist on $BASE_BRANCH)"
36+
continue
37+
fi
38+
39+
git show "$BASE_BRANCH":"$file" 2>/dev/null | awk '/"peerDependencies": ?{/,/}/' >/tmp/base-peer-deps.txt
40+
awk '/"peerDependencies": ?{/,/}/' "$file" >/tmp/current-peer-deps.txt
41+
42+
diff_output=$(diff -u /tmp/base-peer-deps.txt /tmp/current-peer-deps.txt || true)
43+
44+
changed_lines=$(echo "$diff_output" | grep -E '^[-+]' | grep -vE '^[-+]{3}')
45+
46+
if [ -n "$changed_lines" ]; then
47+
echo "❌ peerDependencies changed in $file"
48+
echo "$changed_lines"
49+
50+
{
51+
echo "❌ peerDependencies changed in $file"
52+
echo "$changed_lines"
53+
echo ""
54+
} >>"$result_file"
55+
56+
failed=1
57+
else
58+
echo "✔️ No change in peerDependencies in $file"
59+
fi
60+
done
61+
62+
rm -f /tmp/base-peer-deps.txt /tmp/current-peer-deps.txt
63+
64+
echo ""
65+
if [ $failed -eq 1 ]; then
66+
echo "❌ Breaking change detected: peerDependencies modified."
67+
exit 1
68+
else
69+
echo "✅ No peerDependencies changes found across all files."
70+
exit 0
71+
fi

0 commit comments

Comments
 (0)