-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
chore: Add worklow to check cyclic deps in a PR #33197
Changes from 10 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,106 @@ | ||
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 | ||
outputs: | ||
has_more_cyclic_deps: ${{ steps.check_cyclic_deps.outputs.has_more_cyclic_deps }} | ||
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 | ||
|
||
# In case this is second attempt try restoring status of the prior attempt from cache | ||
- name: Restore the previous run result | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/run_result | ||
key: ${{ github.run_id }}-${{ github.job }}-client | ||
|
||
# Fetch prior run result | ||
- name: Get the previous run result | ||
id: run_result | ||
run: cat ~/run_result 2>/dev/null || echo 'default' | ||
|
||
# In case of prior failure run the job | ||
- if: steps.run_result.outputs.run_result != 'success' | ||
run: echo "I'm alive!" && exit 0 | ||
|
||
- name: Use Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version-file: app/client/package.json | ||
|
||
# actions/setup-node@v3 doesn’t work properly with Yarn 3 | ||
# when the project lives in a subdirectory: https://github.com/actions/setup-node/issues/488 | ||
# Restoring the cache manually instead | ||
- name: Restore Yarn cache | ||
if: steps.run_result.outputs.run_result != 'success' | ||
uses: actions/cache@v3 | ||
with: | ||
path: app/client/.yarn/cache | ||
key: v1-yarn3-${{ hashFiles('app/client/yarn.lock') }} | ||
restore-keys: | | ||
v1-yarn3- | ||
|
||
# Install all the dependencies | ||
- name: Install dependencies | ||
if: steps.run_result.outputs.run_result != 'success' | ||
run: yarn install --immutable | ||
|
||
# Check for cyclic dependencies and save the output | ||
- name: Check for Cyclic Dependencies | ||
if: steps.run_result.outputs.run_result != 'success' | ||
id: check_cyclic_deps | ||
run: | | ||
OUTPUT=$(yarn check-cyclic-deps 2>&1) || true | ||
|
||
if [[ $OUTPUT == *"More deps than release!"* ]]; then | ||
echo "has_more_cyclic_deps=true" >> "$GITHUB_OUTPUT" | ||
fi | ||
|
||
# Comment on the PR if cyclic dependencies are found | ||
- name: Comment the result on PR | ||
if: steps.check_cyclic_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\nYou PR has more cyclic depdencies than the release branch.\n\nResolve any new cyclic dependencies your PR has introduced.\n`; | ||
riodeuno marked this conversation as resolved.
Show resolved
Hide resolved
|
||
github.issues.createComment({ | ||
...context.repo, | ||
issue_number: prNumber, | ||
body: message | ||
}); | ||
|
||
# Saving the cache to use it in subsequent runs | ||
- name: Save Yarn cache | ||
uses: actions/cache/save@v3 | ||
with: | ||
path: app/client/.yarn/cache | ||
key: v1-yarn3-${{ hashFiles('app/client/yarn.lock') }} | ||
|
||
# Set status = success | ||
- name: Save the status of the run | ||
run: echo "run_result=success" >> $GITHUB_OUTPUT > ~/run_result |
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; | ||||||||||||||||||||||||||||||||||
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 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. 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("More deps than release!"); | ||||||||||||||||||||||||||||||||||
riodeuno marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
console.log(prettyCircular(circulars)); | ||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||
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. Handle potential errors from the - parseDependencyTree("./src", {}).then((tree) => {
+ parseDependencyTree("./src", {}).then((tree) => {
const circulars = parseCircular(tree);
if (circulars.length > CIRCULAR_DEPS_IN_RELEASE) {
console.log("More deps than release!");
}
console.log(prettyCircular(circulars));
- });
+ }).catch(error => {
+ console.error("Failed to parse dependency tree:", error);
+ }); This modification ensures that any errors during the dependency tree parsing are caught and logged, preventing possible unhandled promise rejections. Committable suggestion
Suggested change
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Recommend removing these steps as it's not required in this particular job. We use this for long running jobs (like Cypress test etc) to prevent re-running of the same job after a failure. In this particular case, I don't think this is required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed them.