-
Notifications
You must be signed in to change notification settings - Fork 525
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add depcheck for CI step to check for unused dependencies (#1677)
## Which problem is this PR solving? - Fixes #1672 ## Description of the changes - This PR adds a step in the unit-test workflow to check for unused dependencies using the depcheck package. - Certain dependencies which are installed but still being given in the output are put into `.depcheckrc.json` file to be ignored. - The `--skip-missing` flag is also added to ignore the missing deps warning ## How was this change tested? - The `ignores` array without any dep in `.depcheckrc.json` file was pushed to the branch for testing, and it was observed that the CI failed, which is the required behaviour: Workflow Run: https://github.com/anshgoyalevil/jaeger-ui/actions/runs/5854765474/job/15871258991 - The `ignores` array with all unused deps was pushed for CI testing, and the CI passed the Depcheck flow. Workflow Run: https://github.com/anshgoyalevil/jaeger-ui/actions/runs/5854816286/job/15871414318#step:6:10 (Ignore the Lint fail error, as it is resolved in this PR, but workflow run is not available because target push branch was changed to `main` in that commit, and thus workflow run is not available to be shared) ## Notes: Before merging this PR, all the unused deps which are neither added to the `ignores` array, not have been removed need to be removed. Thus PR #1675 needs to be merged before this one. After that, this PR's branch needs to be updated with that code so that the Depcheck doesn't fail in CI for this or for upcoming PRs. ## Checklist - [x] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [x] I have signed all commits - [x] I have added unit tests for the new functionality - [x] I have run lint and test steps successfully - for `jaeger`: `make lint test` - for `jaeger-ui`: `yarn lint` and `yarn test` --------- Signed-off-by: Ansh Goyal <[email protected]> Signed-off-by: dependabot[bot] <[email protected]> Signed-off-by: Pavol Loffay <[email protected]> Signed-off-by: wck-iipi <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Pavol Loffay <[email protected]> Co-authored-by: Yuri Shkuro <[email protected]> Co-authored-by: Wck-iipi <[email protected]>
- Loading branch information
1 parent
662a148
commit 85a2080
Showing
8 changed files
with
131 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) 2023 The Jaeger Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
/* eslint-disable import/no-extraneous-dependencies */ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const { babelConfiguration } = require('../packages/jaeger-ui/test/babel-transform'); | ||
|
||
const packageNames = [ | ||
...babelConfiguration.presets.flatMap(preset => { | ||
if (Array.isArray(preset)) { | ||
return [preset[0]]; | ||
} | ||
return [preset]; | ||
}), | ||
...babelConfiguration.plugins, | ||
]; | ||
|
||
const otherPackages = ['jest-environment-jsdom']; | ||
|
||
// Use the selected targetPackage for generating depcheckrcContent | ||
const depcheckrcContent = { | ||
ignores: [...packageNames, ...otherPackages], | ||
'ignore-dirs': ['build'], | ||
}; | ||
|
||
// Use the argument provided to the script as the output file path | ||
const outputFile = process.argv[2]; | ||
|
||
if (!outputFile) { | ||
process.exit(1); | ||
} | ||
|
||
const depcheckrcPath = path.resolve(__dirname, outputFile); | ||
|
||
fs.writeFileSync(depcheckrcPath, JSON.stringify(depcheckrcContent, null, 2)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright (c) 2023 The Jaeger Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
/* eslint-disable import/no-extraneous-dependencies */ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const getBabelConfig = require('../packages/plexus/babel.config'); | ||
|
||
const babelConfiguration = getBabelConfig({ | ||
env: () => { | ||
'development'; | ||
}, | ||
}); | ||
|
||
const packageNames = [ | ||
...babelConfiguration.presets.flatMap(preset => { | ||
if (Array.isArray(preset)) { | ||
return [preset[0]]; | ||
} | ||
return [preset]; | ||
}), | ||
...babelConfiguration.plugins.flatMap(plugin => { | ||
if (Array.isArray(plugin)) { | ||
return [plugin[0]]; | ||
} | ||
return [plugin]; | ||
}), | ||
]; | ||
|
||
const otherPackages = ['rimraf', 'webpack-cli']; | ||
|
||
// Use the selected targetPackage for generating depcheckrcContent | ||
const depcheckrcContent = { | ||
ignores: [...packageNames, ...otherPackages], | ||
}; | ||
|
||
// Use the argument provided to the script as the output file path | ||
const outputFile = process.argv[2]; | ||
|
||
if (!outputFile) { | ||
process.exit(1); | ||
} | ||
|
||
const depcheckrcPath = path.resolve(__dirname, outputFile); | ||
|
||
fs.writeFileSync(depcheckrcPath, JSON.stringify(depcheckrcContent, null, 2)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/sh | ||
set -ex | ||
|
||
# Create a temporary depcheckrc file for 'jaeger-ui' | ||
tempfile_jaeger=$(mktemp /tmp/depcheckrc.XXXXXX.json) | ||
node scripts/generateDepcheckrcJaegerUI.js "$tempfile_jaeger" | ||
depcheck packages/jaeger-ui --config "$tempfile_jaeger" | ||
|
||
# Create a temporary depcheckrc file for 'plexus' | ||
tempfile_plexus=$(mktemp /tmp/depcheckrc.XXXXXX.json) | ||
node scripts/generateDepcheckrcPlexus.js "$tempfile_plexus" | ||
depcheck packages/plexus --config "$tempfile_plexus" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters