chore: make cyclic deps check an error (#38543)

This commit is contained in:
Diljit 2025-01-09 11:07:37 +05:30 committed by GitHub
parent 5978a96e76
commit 46623172c4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 46 additions and 10 deletions

View File

@ -34,12 +34,32 @@ jobs:
files: | files: |
app/client/src/** app/client/src/**
- name: Use Node.js
if: steps.changed-files.outputs.any_changed == 'true'
uses: actions/setup-node@v4
with:
node-version-file: app/client/package.json
# Globally install the npm package
- name: Install dpdm globally
if: steps.changed-files.outputs.any_changed == 'true'
run: npm install -g dpdm@3.14
# Install all the dependencies
- name: Install dependencies
if: steps.changed-files.outputs.any_changed == 'true'
run: |
yarn install --immutable
- name: Count circular dependencies on PR branch - name: Count circular dependencies on PR branch
id: count-cyclic-deps-in-pr id: count-cyclic-deps-in-pr
if: steps.changed-files.outputs.any_changed == 'true' if: steps.changed-files.outputs.any_changed == 'true'
run: | run: |
npx dpdm ./src/* --circular --warning=false --tree=false > pr_circular_deps.txt dpdm "./src/**/*.{js,jsx,ts,tsx}" --circular --warning=false --tree=false > pr_circular_deps.txt
pr_count=$(cat pr_circular_deps.txt | wc -l) # awk 'NF' pr_circular_deps.txt: Filter out empty lines from the file
# wc -l: Count the number of lines in the file
# awk '{print $1 - 1}': Subtract 1 from the count because the first line is the header 'Circular Dependencies'
pr_count="$(awk 'NF' pr_circular_deps.txt | wc -l | awk '{print $1 - 1}')"
echo "pr_count=$pr_count" >> $GITHUB_OUTPUT echo "pr_count=$pr_count" >> $GITHUB_OUTPUT
cat pr_circular_deps.txt cat pr_circular_deps.txt
@ -49,12 +69,21 @@ jobs:
with: with:
ref: release ref: release
- name: Count circular dependencies on release branch # Install all the dependencies
id: coun-cyclic-deps-in-release - name: Install dependencies
if: steps.changed-files.outputs.any_changed == 'true' if: steps.changed-files.outputs.any_changed == 'true'
run: | run: |
npx dpdm ./src/* --circular --warning=false --tree=false > release_circular_deps.txt yarn install --immutable
release_count=$(cat release_circular_deps.txt | wc -l)
- name: Count circular dependencies on release branch
id: count-cyclic-deps-in-release
if: steps.changed-files.outputs.any_changed == 'true'
run: |
dpdm "./src/**/*.{js,jsx,ts,tsx}" --circular --warning=false --tree=false > release_circular_deps.txt
# awk 'NF' release_circular_deps.txt: Filter out empty lines from the file
# wc -l: Count the number of lines in the file
# awk '{print $1 - 1}': Subtract 1 from the count because the first line is the header 'Circular Dependencies'
release_count="$(awk 'NF' release_circular_deps.txt | wc -l | awk '{print $1 - 1}')"
echo "release_count=$release_count" >> $GITHUB_OUTPUT echo "release_count=$release_count" >> $GITHUB_OUTPUT
cat release_circular_deps.txt cat release_circular_deps.txt
@ -62,9 +91,9 @@ jobs:
id: compare-deps id: compare-deps
if: steps.changed-files.outputs.any_changed == 'true' if: steps.changed-files.outputs.any_changed == 'true'
run: | run: |
release_count=${{ steps.coun-cyclic-deps-in-release.outputs.release_count }} release_count="${{ steps.count-cyclic-deps-in-release.outputs.release_count }}"
pr_count=${{ steps.count-cyclic-deps-in-pr.outputs.pr_count }} pr_count="${{ steps.count-cyclic-deps-in-pr.outputs.pr_count }}"
diff=$((pr_count - release_count)) diff="$((pr_count - release_count))"
if [ "$diff" -gt 0 ]; then if [ "$diff" -gt 0 ]; then
echo "has_more_cyclic_deps=true" >> "$GITHUB_OUTPUT" echo "has_more_cyclic_deps=true" >> "$GITHUB_OUTPUT"
@ -79,9 +108,14 @@ jobs:
github-token: ${{secrets.GITHUB_TOKEN}} github-token: ${{secrets.GITHUB_TOKEN}}
script: | script: |
const prNumber = context.payload.pull_request.number; const prNumber = context.payload.pull_request.number;
const message = `⚠️ Cyclic Dependency Check:\n\nThis PR has increased the number of cyclic dependencies by ${{steps.compare-deps.outputs.diff}}, when compared with the release branch.\n\nRefer [this document](https://appsmith.notion.site/How-to-check-cyclic-dependencies-c47b08fe5f2f4261a3a234b19e13f2db) to identify the cyclic dependencies introduced by this PR.`; const message = `🔴🔴🔴 Cyclic Dependency Check:\n\nThis PR has increased the number of cyclic dependencies by ${{steps.compare-deps.outputs.diff}}, when compared with the release branch.\n\nRefer [this document](https://appsmith.notion.site/How-to-check-cyclic-dependencies-c47b08fe5f2f4261a3a234b19e13f2db) to identify the cyclic dependencies introduced by this PR.`;
github.issues.createComment({ github.issues.createComment({
...context.repo, ...context.repo,
issue_number: prNumber, issue_number: prNumber,
body: message body: message
}); });
# Fail the workflow if cyclic dependencies are found
- name: Fail the workflow if cyclic dependencies are found
if: steps.compare-deps.outputs.has_more_cyclic_deps == 'true' && steps.changed-files.outputs.any_changed == 'true'
run: exit 1

View File

@ -102,6 +102,7 @@ jobs:
client-prettier, client-prettier,
client-unit-tests, client-unit-tests,
client-lint, client-lint,
client-check-cyclic-deps,
] ]
if: always() if: always()
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -116,6 +117,7 @@ jobs:
"${{ needs.client-build.result }}" == "failure" || \ "${{ needs.client-build.result }}" == "failure" || \
"${{ needs.client-prettier.result }}" == "failure" || \ "${{ needs.client-prettier.result }}" == "failure" || \
"${{ needs.client-unit-tests.result }}" == "failure" || \ "${{ needs.client-unit-tests.result }}" == "failure" || \
"${{ needs.client-check-cyclic-deps.result }}" == "failure" || \
"${{ needs.client-lint.result }}" == "failure" ]]; then "${{ needs.client-lint.result }}" == "failure" ]]; then
echo "Quality checks failed"; echo "Quality checks failed";
exit 1; exit 1;