Skip to content

Commit

Permalink
chore(ci): adds diff graph to the github actions summary (#704)
Browse files Browse the repository at this point in the history
  • Loading branch information
sverweij committed Dec 23, 2022
1 parent 3911345 commit 745ca87
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 11 deletions.
1 change: 0 additions & 1 deletion .dependency-cruiser.json
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@
]
},
"exoticRequireStrings": ["tryRequire", "requireJSON"],
"highlight": ["src/cache/"],
"reporterOptions": {
"archi": {
"collapsePattern": ["^(src|test)/[^/]+", "^bin/", "node_modules/[^/]+"]
Expand Down
25 changes: 25 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ jobs:
runs-on: ${{matrix.platform}}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 2
if: github.event_name == 'pull_request' && matrix.node-version == env.NODE_LATEST
- uses: actions/checkout@v3
with:
fetch-depth: 1
if: github.event_name != 'pull_request' || matrix.node-version != env.NODE_LATEST
- uses: actions/cache@v3
with:
path: node_modules
Expand Down Expand Up @@ -57,6 +64,24 @@ jobs:
echo '## Code coverage' >> $GITHUB_STEP_SUMMARY
node tools/istanbul-json-summary-to-markdown.mjs < coverage/coverage-summary.json >> $GITHUB_STEP_SUMMARY
yarn --silent depcruise --output-type markdown >> $GITHUB_STEP_SUMMARY
- name: on pushes to the default branch emit graph to the step summary
if: always() && matrix.node-version == env.NODE_LATEST && github.event_name == 'push' && github.ref_name == github.event.repository.default_branch
run: |
echo '## Visual overview' >> $GITHUB_STEP_SUMMARY
echo '```mermaid' >> $GITHUB_STEP_SUMMARY
yarn --silent depcruise:graph:mermaid >> $GITHUB_STEP_SUMMARY
echo '' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
- name: on pull requests emit depcruise graph to step summary with changed modules highlighted
if: always() && matrix.node-version == env.NODE_LATEST && github.event_name == 'pull_request' && github.ref_name != github.event.repository.default_branch
run: |
echo '## Visual diff' >> $GITHUB_STEP_SUMMARY
echo Modules changed in this PR have a fluorescent green color. All other modules in the graph are those directly or indirectly affected by changes in the green modules. >> $GITHUB_STEP_SUMMARY
echo '```mermaid' >> $GITHUB_STEP_SUMMARY
SHA=${{github.event.pull_request.base.sha}} yarn --silent depcruise:graph:mermaid:diff >> $GITHUB_STEP_SUMMARY
echo '' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
- name: regular test (run on node != ${{env.NODE_LATEST}} only)
if: matrix.node-version != env.NODE_LATEST
run: npm test
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@
"depcruise:graph:doc:samples": "sh tools/generate-samples.sh",
"depcruise:graph:dot": "node ./bin/dependency-cruise.js bin src --config --output-type dot | dot -T svg > tmp_deps.svg",
"depcruise:graph:fdp": "node ./bin/dependency-cruise.js bin src --config --output-type dot | fdp -GK=0.1 -Gsplines=true -T svg > tmp_deps.svg",
"depcruise:graph:mermaid": "node ./bin/dependency-cruise.js bin src --include-only ^src/ --config --output-type mermaid",
"depcruise:graph:mermaid:diff": "node ./bin/dependency-cruise.js bin src test --config configs/.dependency-cruiser-unlimited.json --output-type mermaid --reaches \"$(watskeburt $SHA)\"",
"depcruise:graph:osage": "node ./bin/dependency-cruise.js bin src --config --output-type dot | osage -Gpack=32 -GpackMode=array2 -T svg > tmp_deps.svg",
"depcruise:graph:view": "node ./bin/dependency-cruise.js bin src --prefix vscode://file/$(pwd)/ --config configs/.dependency-cruiser-show-metrics-config.json --output-type dot --progress cli-feedback --highlight \"$(watskeburt develop)\" | dot -T svg | node ./bin/wrap-stream-in-html.js | browser",
"depcruise:graph:view:diff": "node ./bin/dependency-cruise.js bin src test --prefix vscode://file/$(pwd)/ --config configs/.dependency-cruiser-unlimited.json --output-type dot --progress cli-feedback --reaches \"$(watskeburt develop)\" | dot -T svg | node ./bin/wrap-stream-in-html.js | browser",
Expand Down
8 changes: 4 additions & 4 deletions src/cache/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function writeCache(pCacheFolder, pCruiseResult) {
/**
*
* @param {string} pCacheFolder
* @returns {import("../../types/cruise-result").ICruiseResult}
* @returns {import("../..").ICruiseResult}
*/
function readCache(pCacheFolder) {
try {
Expand All @@ -36,11 +36,11 @@ function readCache(pCacheFolder) {
/**
*
* @param {import("../../types/strict-options").IStrictCruiseOptions} pOptions
* @param {import("../../types/cruise-result").IRevisionData} pRevisionData
* @returns
* @param {import("../..").IRevisionData} pRevisionData
* @returns {boolean}
*/
function canServeFromCache(pOptions, pRevisionData) {
/** @type {import("../../types/cruise-result").ICruiseResult} */
/** @type {import("../..").ICruiseResult} */
const lCachedResults = readCache(pOptions.cache);

return (
Expand Down
19 changes: 13 additions & 6 deletions src/cache/revision-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,18 @@ function isInterestingChangeType(pInterestingChangeTypes) {
return (pChange) => pInterestingChangeTypes.has(pChange.changeType);
}

/**
* @param {string} pString
* @returns {string}
*/
function hash(pString) {
return createHash("sha1").update(pString).digest("base64");
}

/**
* @param {import("fs").PathOrFileDescriptor} pFileName
* @returns {string}
*/
function getFileHash(pFileName) {
try {
return hash(readFileSync(pFileName, "utf8"));
Expand All @@ -50,7 +58,7 @@ function getFileHash(pFileName) {

/**
* @param {import("watskeburt").IChange} pChange
* @param {import("../../types/cruise-result").IRevisionChange}
* @param {import("../..").IRevisionChange}
*/
function addChecksum(pChange) {
return {
Expand All @@ -66,8 +74,8 @@ function addChecksum(pChange) {
* @param {Object} pOptions
* @param {() => string} pOptions.shaRetrievalFn
* @param {(pString:string) => Array<import("watskeburt").IChange>} pOptions.diffListFn
* @param {(import("watskeburt").IChange) => import("../../types/cruise-result").IRevisionChange} pOptions.checkSumFn
* @returns {import("../../types/cruise-result").IRevisionData}
* @param {(import("watskeburt").IChange) => import("../..").IRevisionChange} pOptions.checkSumFn
* @returns {import("../..").IRevisionData}
*/
function getRevisionData(
pExtensions,
Expand Down Expand Up @@ -100,9 +108,8 @@ function getRevisionData(
}

/**
*
* @param {import("../../types/cruise-result").IRevisionData} pExistingRevisionData
* @param {import("../../types/cruise-result").IRevisionData} pNewRevisionData
* @param {import("../..").IRevisionData} pExistingRevisionData
* @param {import("../..").IRevisionData} pNewRevisionData
* @returns {boolean}
*/
function revisionDataEqual(pExistingRevisionData, pNewRevisionData) {
Expand Down

0 comments on commit 745ca87

Please sign in to comment.