-
Notifications
You must be signed in to change notification settings - Fork 4.6k
chore: Add worklow to check cyclic deps in a PR #33197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 16 commits
d19df6d
25ac6be
3de556e
c9a02e4
ce600c7
de60770
54311e3
db18010
ebb099c
84850ab
1b29d6f
9362250
158cbbb
5db9cf7
514299a
d3ad2a1
b789cb8
29afe05
92b0db3
d8b8d19
0468373
62a85d1
c93f3e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| name: Cyclic Dependency Check | ||
|
|
||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| pr: | ||
| description: "This is the PR number in case the workflow is being called in a pull request" | ||
| required: false | ||
| type: number | ||
|
|
||
| jobs: | ||
| check-cyclic-dependencies: | ||
| runs-on: ubuntu-latest | ||
| defaults: | ||
| run: | ||
| working-directory: app/client | ||
| shell: bash | ||
|
|
||
| steps: | ||
| # The checkout steps MUST happen first because the default directory is set according to the code base. | ||
| # GitHub Action expects all future commands to be executed in the code directory. Hence, we need to check out | ||
| # the code before doing anything else. | ||
|
|
||
| # Check out merge commit with the base branch in case this workflow is invoked via pull request | ||
| - name: Checkout the merged commit from PR and base branch | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| ref: refs/pull/${{ inputs.pr }}/merge | ||
|
|
||
| - name: Count circular dependencies on PR branch | ||
| id: count-cyclic-deps-in-pr | ||
| run: | | ||
| npx dpdm ./src/* --circular --warning=false --tree=false > pr_circular_deps.txt | ||
| pr_count=$(cat pr_circular_deps.txt | wc -l) | ||
| echo "pr_count=$pr_count" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Checkout release branch | ||
| uses: actions/checkout@v3 | ||
| with: | ||
| ref: release | ||
|
|
||
| - name: Check release log | ||
| run: | | ||
| git log -1 | ||
|
|
||
| - name: Count circular dependencies on release branch | ||
| id: coun-cyclic-deps-in-release | ||
| run: | | ||
| npx dpdm ./src/* --circular --warning=false --tree=false > release_circular_deps.txt | ||
| release_count=$(cat release_circular_deps.txt | wc -l) | ||
| echo "release_count=$release_count" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Compare circular dependencies | ||
| id: compare-deps | ||
| run: | | ||
| release_count=${{ steps.coun-cyclic-deps-in-release.outputs.release_count }} | ||
| pr_count=${{ steps.count-cyclic-deps-in-pr.outputs.pr_count }} | ||
| diff=$((pr_count - release_count)) | ||
|
|
||
| if [ "$diff" -gt 0 ]; then | ||
| echo "has_more_cyclic_deps=true" >> "$GITHUB_OUTPUT" | ||
| echo "diff=$diff" >> "$GITHUB_OUTPUT" | ||
| fi | ||
|
|
||
| # Comment on the PR if cyclic dependencies are found | ||
| - name: Comment the result on PR | ||
| if: steps.compare-deps.outputs.has_more_cyclic_deps == 'true' | ||
| uses: actions/github-script@v3 | ||
| with: | ||
| github-token: ${{secrets.GITHUB_TOKEN}} | ||
| script: | | ||
| 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.`; | ||
| github.issues.createComment({ | ||
| ...context.repo, | ||
| issue_number: prNumber, | ||
| body: message | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| const { parseDependencyTree, parseCircular, prettyCircular } = require("dpdm"); | ||
|
|
||
| const CIRCULAR_DEPS_IN_RELEASE = 2965; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think having a constant will not be very convenient for us in the future. Especially when we start working on reducing the number of dependencies and we have to edit it manually every time. I think we could checkout to the
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @KelvinOm Understood. Let me update the PR.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| parseDependencyTree("./src", {}).then((tree) => { | ||
| const circulars = parseCircular(tree); | ||
| if (circulars.length > CIRCULAR_DEPS_IN_RELEASE) { | ||
| console.log("Failed!"); | ||
| } | ||
| console.log(prettyCircular(circulars)); | ||
| }); | ||
Uh oh!
There was an error while loading. Please reload this page.