Skip to content
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

Merged
merged 23 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
106 changes: 106 additions & 0 deletions .github/workflows/ci-client-cyclic-deps-check.yml
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
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed them.


- 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
9 changes: 9 additions & 0 deletions .github/workflows/quality-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ jobs:
with:
pr: ${{ github.event.pull_request.number }}

client-check-cyclic-deps:
name: client-check-cyclic-deps
needs: path-filter
if: needs.path-filter.outputs.client == 'true'
uses: ./.github/workflows/ci-client-cyclic-deps-check.yml
secrets: inherit
with:
pr: ${{ github.event.pull_request.number }}

qc-result:
name: qc-result
needs:
Expand Down
3 changes: 2 additions & 1 deletion app/client/.eslintrc.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"jest.config.js",
"jest.setup.ts",
"rollup.config.js",
".eslintrc.js"
".eslintrc.js",
"scripts/circular_deps_check.js"
],
"plugins": [
"react",
Expand Down
4 changes: 3 additions & 1 deletion app/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
"prettier:ci": "yarn workspaces foreach -ptv run prettier",
"check-types": "yarn tsc --noEmit",
"init-husky": "cd ../.. && husky install app/client/.husky",
"clean:workspaces": "yarn workspaces foreach -pAv exec rm -rf node_modules"
"clean:workspaces": "yarn workspaces foreach -pAv exec rm -rf node_modules",
"check-cyclic-deps": "node scripts/circular_deps_check.js"
},
"dependencies": {
"@aws-sdk/client-s3": "^3.441.0",
Expand Down Expand Up @@ -322,6 +323,7 @@
"cypress-xpath": "^1.6.0",
"diff": "^5.0.0",
"dotenv": "^8.1.0",
"dpdm": "^3.14.0",
"eslint": "^8.51.0",
"eslint-config-prettier": "^9.0.0",
"eslint-import-resolver-babel-module": "^5.3.2",
Expand Down
11 changes: 11 additions & 0 deletions app/client/scripts/circular_deps_check.js
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;
Copy link
Collaborator

Choose a reason for hiding this comment

The 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 release branch to get the number of dependencies and then compare them with the number of dependencies in the current branch. WDYT?

@dvj1988 @riodeuno

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KelvinOm Understood. Let me update the PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KelvinOm Please re-review. This workflow checks out the release branch and compares the cyclic dependencies with the current branch.

This is the sample comment.


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));
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handle potential errors from the parseDependencyTree function.

- 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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
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));
});
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);
});

112 changes: 75 additions & 37 deletions app/client/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1205,11 +1205,11 @@ __metadata:
linkType: hard

"@babel/parser@npm:^7.1.0, @babel/parser@npm:^7.14.7, @babel/parser@npm:^7.20.7, @babel/parser@npm:^7.23.0, @babel/parser@npm:^7.24.0, @babel/parser@npm:^7.24.1, @babel/parser@npm:^7.24.4":
version: 7.24.4
resolution: "@babel/parser@npm:7.24.4"
version: 7.24.5
resolution: "@babel/parser@npm:7.24.5"
bin:
parser: ./bin/babel-parser.js
checksum: 94c9e3e592894cd6fc57c519f4e06b65463df9be5f01739bb0d0bfce7ffcf99b3c2fdadd44dc59cc858ba2739ce6e469813a941c2f2dfacf333a3b2c9c5c8465
checksum: a251ea41bf8b5f61048beb320d43017aff68af5a3506bd2ef392180f5fa32c1061513171d582bb3d46ea48e3659dece8b3ba52511a2566066e58abee300ce2a0
languageName: node
linkType: hard

Expand Down Expand Up @@ -13139,6 +13139,7 @@ __metadata:
diff: ^5.0.0
dotenv: ^8.1.0
downloadjs: ^1.4.7
dpdm: ^3.14.0
echarts: ^5.4.2
eslint: ^8.51.0
eslint-config-prettier: ^9.0.0
Expand Down Expand Up @@ -17691,6 +17692,23 @@ __metadata:
languageName: node
linkType: hard

"dpdm@npm:^3.14.0":
version: 3.14.0
resolution: "dpdm@npm:3.14.0"
dependencies:
chalk: ^4.1.2
fs-extra: ^11.1.1
glob: ^10.3.4
ora: ^5.4.1
tslib: ^2.6.2
typescript: ^5.2.2
yargs: ^17.7.2
bin:
dpdm: lib/bin/dpdm.js
checksum: 86870216326db1b5d714d8297271e7cbafb0bb4e4e60b7c8eeffd22cab8cf8a1464b66db5ce62a4ba9ddb4efdba25b7903b8932b5aeb97df0e89374651c77c11
languageName: node
linkType: hard

"duck@npm:^0.1.12":
version: 0.1.12
resolution: "duck@npm:0.1.12"
Expand Down Expand Up @@ -17946,12 +17964,12 @@ __metadata:
linkType: hard

"enhanced-resolve@npm:^5.0.0, enhanced-resolve@npm:^5.10.0, enhanced-resolve@npm:^5.7.0":
version: 5.12.0
resolution: "enhanced-resolve@npm:5.12.0"
version: 5.16.0
resolution: "enhanced-resolve@npm:5.16.0"
dependencies:
graceful-fs: ^4.2.4
tapable: ^2.2.0
checksum: bf3f787facaf4ce3439bef59d148646344e372bef5557f0d37ea8aa02c51f50a925cd1f07b8d338f18992c29f544ec235a8c64bcdb56030196c48832a5494174
checksum: ccfd01850ecf2aa51e8554d539973319ff7d8a539ef1e0ba3460a0ccad6223c4ef6e19165ee64161b459cd8a48df10f52af4434c60023c65fde6afa32d475f7e
languageName: node
linkType: hard

Expand Down Expand Up @@ -19865,7 +19883,7 @@ __metadata:
languageName: node
linkType: hard

"fs-extra@npm:^11.1.0, fs-extra@npm:^11.2.0":
"fs-extra@npm:^11.1.0, fs-extra@npm:^11.1.1, fs-extra@npm:^11.2.0":
version: 11.2.0
resolution: "fs-extra@npm:11.2.0"
dependencies:
Expand Down Expand Up @@ -20235,18 +20253,18 @@ __metadata:
languageName: node
linkType: hard

"glob@npm:^10.0.0":
version: 10.3.3
resolution: "glob@npm:10.3.3"
"glob@npm:^10.0.0, glob@npm:^10.3.4":
version: 10.3.12
resolution: "glob@npm:10.3.12"
dependencies:
foreground-child: ^3.1.0
jackspeak: ^2.0.3
jackspeak: ^2.3.6
minimatch: ^9.0.1
minipass: ^5.0.0 || ^6.0.2 || ^7.0.0
path-scurry: ^1.10.1
minipass: ^7.0.4
path-scurry: ^1.10.2
bin:
glob: dist/cjs/src/bin.js
checksum: 29190d3291f422da0cb40b77a72fc8d2c51a36524e99b8bf412548b7676a6627489528b57250429612b6eec2e6fe7826d328451d3e694a9d15e575389308ec53
glob: dist/esm/bin.mjs
checksum: 2b0949d6363021aaa561b108ac317bf5a97271b8a5d7a5fac1a176e40e8068ecdcccc992f8a7e958593d501103ac06d673de92adc1efcbdab45edefe35f8d7c6
languageName: node
linkType: hard

Expand Down Expand Up @@ -22217,16 +22235,16 @@ __metadata:
languageName: node
linkType: hard

"jackspeak@npm:^2.0.3":
version: 2.2.2
resolution: "jackspeak@npm:2.2.2"
"jackspeak@npm:^2.3.6":
version: 2.3.6
resolution: "jackspeak@npm:2.3.6"
dependencies:
"@isaacs/cliui": ^8.0.2
"@pkgjs/parseargs": ^0.11.0
dependenciesMeta:
"@pkgjs/parseargs":
optional: true
checksum: 7b1468dd910afc00642db87448f24b062346570b8b47531409aa9012bcb95fdf7ec2b1c48edbb8b57a938c08391f8cc01b5034fc335aa3a2e74dbcc0ee5c555a
checksum: 57d43ad11eadc98cdfe7496612f6bbb5255ea69fe51ea431162db302c2a11011642f50cfad57288bd0aea78384a0612b16e131944ad8ecd09d619041c8531b54
languageName: node
linkType: hard

Expand Down Expand Up @@ -24274,6 +24292,13 @@ __metadata:
languageName: node
linkType: hard

"lru-cache@npm:^10.2.0":
version: 10.2.2
resolution: "lru-cache@npm:10.2.2"
checksum: 98e8fc93691c546f719a76103ef2bee5a3ac823955c755a47641ec41f8c7fafa1baeaba466937cc1cbfa9cfd47e03536d10e2db3158a64ad91ff3a58a32c893e
languageName: node
linkType: hard

"lru-cache@npm:^4.1.5":
version: 4.1.5
resolution: "lru-cache@npm:4.1.5"
Expand Down Expand Up @@ -24309,13 +24334,6 @@ __metadata:
languageName: node
linkType: hard

"lru-cache@npm:^9.1.1 || ^10.0.0":
version: 10.0.0
resolution: "lru-cache@npm:10.0.0"
checksum: 18f101675fe283bc09cda0ef1e3cc83781aeb8373b439f086f758d1d91b28730950db785999cd060d3c825a8571c03073e8c14512b6655af2188d623031baf50
languageName: node
linkType: hard

"lz-string@npm:^1.5.0":
version: 1.5.0
resolution: "lz-string@npm:1.5.0"
Expand Down Expand Up @@ -24854,10 +24872,10 @@ __metadata:
languageName: node
linkType: hard

"minipass@npm:^5.0.0 || ^6.0.2 || ^7.0.0":
version: 7.0.2
resolution: "minipass@npm:7.0.2"
checksum: 46776de732eb7cef2c7404a15fb28c41f5c54a22be50d47b03c605bf21f5c18d61a173c0a20b49a97e7a65f78d887245066410642551e45fffe04e9ac9e325bc
"minipass@npm:^5.0.0 || ^6.0.2 || ^7.0.0, minipass@npm:^7.0.4":
version: 7.1.0
resolution: "minipass@npm:7.1.0"
checksum: c057d4b1d7fdb35b8f4b9d8f627b1f6832c441cd7dff9304ee5efef68abb3b460309bf97b1b0ce5b960e259caa53c724f609d058e4dc12d547e2a074aaae2cd6
languageName: node
linkType: hard

Expand Down Expand Up @@ -26136,13 +26154,13 @@ __metadata:
languageName: node
linkType: hard

"path-scurry@npm:^1.10.1":
version: 1.10.1
resolution: "path-scurry@npm:1.10.1"
"path-scurry@npm:^1.10.2":
version: 1.10.2
resolution: "path-scurry@npm:1.10.2"
dependencies:
lru-cache: ^9.1.1 || ^10.0.0
lru-cache: ^10.2.0
minipass: ^5.0.0 || ^6.0.2 || ^7.0.0
checksum: e2557cff3a8fb8bc07afdd6ab163a92587884f9969b05bbbaf6fe7379348bfb09af9ed292af12ed32398b15fb443e81692047b786d1eeb6d898a51eb17ed7d90
checksum: 6739b4290f7d1a949c61c758b481c07ac7d1a841964c68cf5e1fa153d7e18cbde4872b37aadf9c5173c800d627f219c47945859159de36c977dd82419997b9b8
languageName: node
linkType: hard

Expand Down Expand Up @@ -33229,7 +33247,7 @@ __metadata:
languageName: node
linkType: hard

"tslib@npm:^2.0.0, tslib@npm:^2.0.1, tslib@npm:^2.0.3, tslib@npm:^2.1.0, tslib@npm:^2.3.0, tslib@npm:^2.3.1, tslib@npm:^2.4.0, tslib@npm:^2.5.0, tslib@npm:^2.6.0":
"tslib@npm:^2.0.0, tslib@npm:^2.0.1, tslib@npm:^2.0.3, tslib@npm:^2.1.0, tslib@npm:^2.3.0, tslib@npm:^2.3.1, tslib@npm:^2.4.0, tslib@npm:^2.5.0, tslib@npm:^2.6.0, tslib@npm:^2.6.2":
version: 2.6.2
resolution: "tslib@npm:2.6.2"
checksum: 329ea56123005922f39642318e3d1f0f8265d1e7fcb92c633e0809521da75eeaca28d2cf96d7248229deb40e5c19adf408259f4b9640afd20d13aecc1430f3ad
Expand Down Expand Up @@ -33488,6 +33506,16 @@ __metadata:
languageName: node
linkType: hard

"typescript@npm:^5.2.2":
version: 5.4.5
resolution: "typescript@npm:5.4.5"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 53c879c6fa1e3bcb194b274d4501ba1985894b2c2692fa079db03c5a5a7140587a1e04e1ba03184605d35f439b40192d9e138eb3279ca8eee313c081c8bcd9b0
languageName: node
linkType: hard

"typescript@patch:typescript@4.5.5#~builtin<compat/typescript>":
version: 4.5.5
resolution: "typescript@patch:typescript@npm%3A4.5.5#~builtin<compat/typescript>::version=4.5.5&hash=bcec9a"
Expand All @@ -33508,6 +33536,16 @@ __metadata:
languageName: node
linkType: hard

"typescript@patch:typescript@^5.2.2#~builtin<compat/typescript>":
version: 5.4.5
resolution: "typescript@patch:typescript@npm%3A5.4.5#~builtin<compat/typescript>::version=5.4.5&hash=77c9e2"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 2373c693f3b328f3b2387c3efafe6d257b057a142f9a79291854b14ff4d5367d3d730810aee981726b677ae0fd8329b23309da3b6aaab8263dbdccf1da07a3ba
languageName: node
linkType: hard

"ua-parser-js@npm:1.0.33":
version: 1.0.33
resolution: "ua-parser-js@npm:1.0.33"
Expand Down Expand Up @@ -35254,7 +35292,7 @@ __metadata:
languageName: node
linkType: hard

"yargs@npm:^17.2.1, yargs@npm:^17.3.1":
"yargs@npm:^17.2.1, yargs@npm:^17.3.1, yargs@npm:^17.7.2":
version: 17.7.2
resolution: "yargs@npm:17.7.2"
dependencies:
Expand Down