Skip to content

Commit abdfc7a

Browse files
committed
Implement main standalone and monorepo flows
1 parent 8956b13 commit abdfc7a

13 files changed

Lines changed: 599 additions & 333 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ retain report artifacts for 30 days:
8080

8181
Some outputs are set in case you want to add further steps to your workflow.
8282

83-
| Name | Description |
84-
| :------------ | :------------------------------- |
85-
| `artifact-id` | ID of uploaded report artifact |
86-
| `comment-id` | ID of created/updated PR comment |
83+
| Name | Description |
84+
| :------------ | :---------------------------------------------------- |
85+
| `artifact-id` | ID of uploaded report artifact (N/A in monorepo mode) |
86+
| `comment-id` | ID of created/updated PR comment |
8787

8888
Example of using step outputs:
8989

dist/index.js

Lines changed: 295 additions & 180 deletions
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/artifact.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,33 @@ import {
66
import * as core from '@actions/core'
77
import * as github from '@actions/github'
88
import fs from 'node:fs/promises'
9+
import {
10+
findPersistedFiles,
11+
projectToFilename,
12+
type PersistedCliFiles
13+
} from './cli'
914
import type { ActionInputs } from './inputs'
10-
import { findPersistedFiles, type PersistedCliFiles } from './persist'
11-
12-
export const REPORT_ARTIFACT_NAME = 'code-pushup-report'
13-
export const DIFF_ARTIFACT_NAME = 'code-pushup-report-diff'
1415

16+
const REPORT_ARTIFACT_NAME = 'code-pushup-report'
17+
const DIFF_ARTIFACT_NAME = 'code-pushup-report-diff'
1518
const ARTIFACT_DIR = 'tmp'
1619

20+
export function createReportArtifactName(project?: string): string {
21+
return createArtifactName(REPORT_ARTIFACT_NAME, project)
22+
}
23+
24+
export function createDiffArtifactName(project?: string): string {
25+
return createArtifactName(DIFF_ARTIFACT_NAME, project)
26+
}
27+
28+
function createArtifactName(base: string, project: string | undefined): string {
29+
if (!project) {
30+
return base
31+
}
32+
const suffix = projectToFilename(project)
33+
return `${base}-${suffix}`
34+
}
35+
1736
export async function downloadReportArtifact(
1837
artifact: ArtifactClient,
1938
branch: { ref: string; sha: string },
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
import { exec } from '@actions/exec'
2-
import type { ActionInputs } from './inputs'
2+
import type { CommandContext } from '../context'
33
import {
44
persistCliOptions,
55
persistedCliFiles,
66
type PersistedCliFiles
7-
} from './persist'
7+
} from '../persist'
88

99
export async function collect({
1010
bin,
1111
config,
1212
directory,
13-
silent
14-
}: ActionInputs): Promise<PersistedCliFiles> {
13+
silent,
14+
project
15+
}: CommandContext): Promise<PersistedCliFiles> {
1516
await exec(
1617
bin,
17-
[...(config ? [`--config=${config}`] : []), ...persistCliOptions()],
18+
[...(config ? [`--config=${config}`] : []), ...persistCliOptions(project)],
1819
{ cwd: directory, silent }
1920
)
2021

21-
return persistedCliFiles({ directory })
22+
return persistedCliFiles({ directory, project })
2223
}
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
11
import { exec } from '@actions/exec'
2-
import type { ActionInputs } from './inputs'
2+
import type { CommandContext } from '../context'
33
import {
44
persistCliOptions,
55
persistedCliFiles,
66
type PersistedCliFiles
7-
} from './persist'
7+
} from '../persist'
88

99
type CompareOptions = {
1010
before: string
1111
after: string
12+
label?: string
1213
}
1314

1415
export async function compare(
15-
{ before, after }: CompareOptions,
16-
{ bin, config, directory, silent }: ActionInputs
16+
{ before, after, label }: CompareOptions,
17+
{ bin, config, directory, silent, project }: CommandContext
1718
): Promise<PersistedCliFiles> {
1819
await exec(
1920
bin,
2021
[
2122
'compare',
2223
`--before=${before}`,
2324
`--after=${after}`,
25+
...(label ? [`--label=${label}`] : []),
2426
...(config ? [`--config=${config}`] : []),
25-
...persistCliOptions()
27+
...persistCliOptions(project)
2628
],
2729
{ cwd: directory, silent }
2830
)
2931

30-
return persistedCliFiles({ directory, isDiff: true })
32+
return persistedCliFiles({ directory, isDiff: true, project })
3133
}

src/cli/commands/merge-diffs.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { exec } from '@actions/exec'
2+
import type { CommandContext } from '../context'
3+
import {
4+
persistCliOptions,
5+
persistedCliFiles,
6+
type PersistedCliFiles
7+
} from '../persist'
8+
9+
export async function mergeDiffs(
10+
files: string[],
11+
{ bin, config, directory, silent }: CommandContext
12+
): Promise<PersistedCliFiles<'md'>> {
13+
await exec(
14+
bin,
15+
[
16+
'merge-diffs',
17+
...files.map(file => `--files=${file}`),
18+
...(config ? [`--config=${config}`] : []),
19+
...persistCliOptions()
20+
],
21+
{ cwd: directory, silent }
22+
)
23+
24+
return persistedCliFiles({ directory, isDiff: true, formats: ['md'] })
25+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { exec } from '@actions/exec'
2-
import type { ActionInputs } from './inputs'
2+
import type { CommandContext } from '../context'
33

44
export async function printConfig({
55
bin,
66
config,
77
directory,
88
silent
9-
}: ActionInputs): Promise<void> {
9+
}: CommandContext): Promise<void> {
1010
await exec(bin, [...(config ? [`--config=${config}`] : []), 'print-config'], {
1111
cwd: directory,
1212
silent

src/cli/context.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import type { ActionInputs } from '../inputs'
2+
3+
export type CommandContext = Pick<
4+
ActionInputs,
5+
'bin' | 'config' | 'directory' | 'silent'
6+
> & {
7+
project?: string
8+
}

src/cli/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export { collect } from './commands/collect'
2+
export { compare } from './commands/compare'
3+
export { mergeDiffs } from './commands/merge-diffs'
4+
export { printConfig } from './commands/print-config'
5+
export type { CommandContext } from './context'
6+
export {
7+
findPersistedFiles,
8+
projectToFilename,
9+
type PersistedCliFiles
10+
} from './persist'

0 commit comments

Comments
 (0)