Skip to content

Commit d90d851

Browse files
committed
feat: report is generated separately for each workingDirectory
1 parent e13ae4a commit d90d851

File tree

10 files changed

+52
-9
lines changed

10 files changed

+52
-9
lines changed

action.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@ runs:
3434
INPUT_TARGET_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
3535
INPUT_CONFIG_FILE: ${{ inputs.config-file }}
3636
INPUT_CRUISE_SCRIPT: ${{ inputs.cruise-script }}
37+
INPUT_WORKING_DIRECTORY: ${{ inputs.working-directory }}

dist/index.js

Lines changed: 12 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/options.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const getSha = (): string =>
2323

2424
export const getOptions = (): Promise<Options> => {
2525
const token = core.getInput('github_token', { required: true })
26+
const workingDirectory = core.getInput('working_directory', { required: true })
2627
const changedFiles = core.getInput('target_files', { required: false }).split(' ')
2728
const targetFiles = filterSupportedFiles(changedFiles)
2829
const focus = formatFocusOption(targetFiles)
@@ -31,6 +32,7 @@ export const getOptions = (): Promise<Options> => {
3132
const pr = context.payload.pull_request
3233
const options = {
3334
token,
35+
workingDirectory,
3436
owner: context.repo.owner,
3537
repo: context.repo.repo,
3638
issueNumber: pr?.number,

src/options/validateOptions.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const baseOptions: Options = {
1515
focus: `"^test/runDepcruise/sample/__mocks__/test/fixtures/cjs/root_one.js|^test/runDepcruise/sample/__mocks__/test/fixtures/cjs/root_two.js"`,
1616
depcruiseConfigFilePath: `test/runDepcruise/.dependency-cruiser.js`,
1717
cruiseScript: 'yarn run -s depcruise',
18+
workingDirectory: 'test/runDepcruise',
1819
}
1920

2021
describe('validateOptions', () => {

src/options/validateOptions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const optionsSchema = object({
1616
focus: string().required(),
1717
depcruiseConfigFilePath: string().required(),
1818
cruiseScript: string().required(),
19+
workingDirectory: string().required(),
1920
})
2021

2122
export type Options = InferType<typeof optionsSchema>

src/report/body/reportBody.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ describe('reportBody', () => {
88
owner: 'octocat',
99
repo: 'hello-world',
1010
issueNumber: 1,
11+
workingDirectory: 'src',
1112
sha: '8ef39983ce21a9c80821addbeb63bfe4d4068f9a',
1213
mermaidText: 'flowchart LR\n\nA ---> B',
1314
cmdText:
1415
'yarn -s depcruise --output-type mermaid --config .dependency-cruiser.js dist/index.js src/options.ts',
1516
}
16-
const expected = `<!-- This comment was generated by dependency-cruiser-report-action. id: ab9d1a5ad3256cbba8c22a27e3c4ef3dabb0f0289ea1f3505ac4537afb1e92bf -->
17+
const expected = `<!-- This comment was generated by dependency-cruiser-report-action. id: 793d8403dad1436f27f87c9ec99a41239c663150857545f16267c67caf0731f1 -->
1718
# dependency-cruiser report
1819
1920
visualize dependenices of changed files.
@@ -28,6 +29,8 @@ Report generated by <a href="https://github.com/MH4GF/dependency-cruiser-report-
2829
2930
---
3031
32+
working directory: \`src\`
33+
3134
<details>
3235
<summary>execute command</summary>
3336
@@ -45,11 +48,12 @@ yarn -s depcruise --output-type mermaid --config .dependency-cruiser.js dist/ind
4548
owner: 'octocat',
4649
repo: 'hello-world',
4750
issueNumber: 1,
51+
workingDirectory: 'src',
4852
sha: '8ef39983ce21a9c80821addbeb63bfe4d4068f9a',
4953
mermaidText: 'flowchart LR\n\n\n\n',
5054
cmdText: 'yarn -s depcruise --output-type mermaid --config .dependency-cruiser.js docs',
5155
}
52-
const expected = `<!-- This comment was generated by dependency-cruiser-report-action. id: ab9d1a5ad3256cbba8c22a27e3c4ef3dabb0f0289ea1f3505ac4537afb1e92bf -->
56+
const expected = `<!-- This comment was generated by dependency-cruiser-report-action. id: 793d8403dad1436f27f87c9ec99a41239c663150857545f16267c67caf0731f1 -->
5357
# dependency-cruiser report
5458
5559
visualize dependenices of changed files.
@@ -60,6 +64,8 @@ Report generated by <a href="https://github.com/MH4GF/dependency-cruiser-report-
6064
6165
---
6266
67+
working directory: \`src\`
68+
6369
<details>
6470
<summary>execute command</summary>
6571

src/report/body/reportBody.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ type Params = {
77
sha: string
88
cmdText: string
99
mermaidText: string
10+
workingDirectory: string
1011
}
1112

1213
const NO_OUTPUT_TEXT = 'flowchart LR\n\n\n\n'
@@ -24,7 +25,12 @@ ${text}
2425
export const reportBody = (params: Params) => {
2526
const url = 'https://github.com/MH4GF/dependency-cruiser-report-action'
2627

27-
return `${uniqueTag({ owner: params.owner, repo: params.repo, issueNumber: params.issueNumber })}
28+
return `${uniqueTag({
29+
owner: params.owner,
30+
repo: params.repo,
31+
issueNumber: params.issueNumber,
32+
workingDirectory: params.workingDirectory,
33+
})}
2834
# dependency-cruiser report
2935
3036
visualize dependenices of changed files.
@@ -35,6 +41,8 @@ Report generated by <a href="${url}">dependency-cruiser report action</a> ${para
3541
3642
---
3743
44+
working directory: \`${params.workingDirectory}\`
45+
3846
<details>
3947
<summary>execute command</summary>
4048

src/report/body/uniqueTag.test.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,26 @@ import { uniqueTag } from './uniqueTag'
44

55
describe('uniqueTag', () => {
66
it('should return tag with hashed id describing the workflow generated', () => {
7-
const context = { owner: 'octocat', repo: 'hello-world', issueNumber: 1 }
8-
const hashedId = 'ab9d1a5ad3256cbba8c22a27e3c4ef3dabb0f0289ea1f3505ac4537afb1e92bf'
7+
const context = {
8+
owner: 'octocat',
9+
repo: 'hello-world',
10+
issueNumber: 1,
11+
workingDirectory: 'src',
12+
}
13+
const hashedId = '793d8403dad1436f27f87c9ec99a41239c663150857545f16267c67caf0731f1'
914
const tag = `<!-- This comment was generated by dependency-cruiser-report-action. id: ${hashedId} -->`
1015
expect(uniqueTag(context)).toBe(tag)
1116
})
1217

1318
it('should work with extra key/value of passed object', () => {
14-
const context = { owner: 'octocat', repo: 'hello-world', issueNumber: 1, extra: 'foo' }
15-
const hashedId = 'ab9d1a5ad3256cbba8c22a27e3c4ef3dabb0f0289ea1f3505ac4537afb1e92bf'
19+
const context = {
20+
owner: 'octocat',
21+
repo: 'hello-world',
22+
issueNumber: 1,
23+
workingDirectory: 'src',
24+
extra: 'foo',
25+
}
26+
const hashedId = '793d8403dad1436f27f87c9ec99a41239c663150857545f16267c67caf0731f1'
1627
const tag = `<!-- This comment was generated by dependency-cruiser-report-action. id: ${hashedId} -->`
1728
expect(uniqueTag(context)).toBe(tag)
1829
})

src/report/body/uniqueTag.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ type Context = {
44
owner: string
55
repo: string
66
issueNumber: number
7+
workingDirectory: string
78
}
89

910
const hashedContext = (context: Context) => {
@@ -12,6 +13,7 @@ const hashedContext = (context: Context) => {
1213
owner: context.owner,
1314
repo: context.repo,
1415
issueNumber: context.issueNumber,
16+
workingDirectory: context.workingDirectory,
1517
}
1618
hash.update(JSON.stringify(json))
1719
return hash.digest('hex')

0 commit comments

Comments
 (0)