Skip to content

Commit b47aa6a

Browse files
committed
ci(local-action): separate standalone and monorepo code-pushup jobs
1 parent 138fe3d commit b47aa6a

File tree

4 files changed

+88
-22
lines changed

4 files changed

+88
-22
lines changed

.github/actions/code-pushup/action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ inputs:
66
description: GitHub token for API access
77
required: true
88
default: ${{ github.token }}
9+
mode:
10+
description: Is `standalone` or `monorepo` mode?
11+
required: true
912

1013
runs:
1114
using: composite
@@ -16,3 +19,4 @@ runs:
1619
env:
1720
TSX_TSCONFIG_PATH: .github/actions/code-pushup/tsconfig.json
1821
GH_TOKEN: ${{ inputs.token }}
22+
MODE: ${{ inputs.mode }}

.github/actions/code-pushup/src/runner.ts

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function createAnnotationsFromIssues(issues: SourceFileIssue[]): void {
8787
}
8888

8989
function createGitHubApiClient(): ProviderAPIClient {
90-
const token = process.env.GH_TOKEN;
90+
const token = process.env['GH_TOKEN'];
9191

9292
if (!token) {
9393
throw new Error('No GitHub token found');
@@ -135,23 +135,32 @@ async function run(): Promise<void> {
135135
logger.setVerbose(true);
136136
}
137137

138-
const options: Options = {
139-
monorepo: true,
140-
configPatterns: {
141-
persist: {
142-
...DEFAULT_PERSIST_CONFIG,
143-
outputDir: '.code-pushup/{projectName}',
144-
},
145-
...(process.env['CP_API_KEY'] && {
146-
upload: {
147-
server: 'https://api.staging.code-pushup.dev/graphql',
148-
apiKey: process.env['CP_API_KEY'],
149-
organization: 'code-pushup',
150-
project: 'cli-{projectName}',
138+
const isMonorepo = process.env['MODE'] === 'monorepo';
139+
140+
const options: Options = isMonorepo
141+
? {
142+
jobId: 'monorepo-mode',
143+
monorepo: 'nx',
144+
nxProjectsFilter: '--with-target=code-pushup --exclude=workspace',
145+
configPatterns: {
146+
persist: {
147+
...DEFAULT_PERSIST_CONFIG,
148+
outputDir: '.code-pushup/{projectName}',
149+
},
150+
...(process.env['CP_API_KEY'] && {
151+
upload: {
152+
server: 'https://api.staging.code-pushup.dev/graphql',
153+
apiKey: process.env['CP_API_KEY'],
154+
organization: 'code-pushup',
155+
project: 'cli-{projectName}',
156+
},
157+
}),
151158
},
152-
}),
153-
},
154-
};
159+
}
160+
: {
161+
jobId: 'standalone-mode',
162+
bin: 'npx nx code-pushup --',
163+
};
155164

156165
const gitRefs = parseGitRefs();
157166

.github/workflows/code-pushup-fork.yml

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Code PushUp - Standalone Mode (fork)
1+
name: Code PushUp (fork)
22

33
# separated from code-pushup.yml for security reasons
44
# => requires permissions to create PR comment
@@ -18,9 +18,9 @@ permissions:
1818
pull-requests: write
1919

2020
jobs:
21-
code-pushup:
21+
standalone:
2222
runs-on: ubuntu-latest
23-
name: Run Code PushUp (fork)
23+
name: Standalone mode (fork)
2424
if: github.event.pull_request.head.repo.fork
2525
steps:
2626
- name: Checkout repository
@@ -40,3 +40,28 @@ jobs:
4040
uses: ./.github/actions/code-pushup
4141
with:
4242
token: ${{ secrets.GITHUB_TOKEN }}
43+
mode: standalone
44+
45+
monorepo:
46+
runs-on: ubuntu-latest
47+
name: Monorepo mode (fork)
48+
if: github.event.pull_request.head.repo.fork
49+
steps:
50+
- name: Checkout repository
51+
uses: actions/checkout@v4
52+
with:
53+
fetch-depth: 0
54+
- name: Set up Node.js
55+
uses: actions/setup-node@v4
56+
with:
57+
node-version-file: .node-version
58+
cache: npm
59+
- name: Set base and head for Nx affected commands
60+
uses: nrwl/nx-set-shas@v4
61+
- name: Install dependencies
62+
run: npm ci
63+
- name: Run Code PushUp action
64+
uses: ./.github/actions/code-pushup
65+
with:
66+
token: ${{ secrets.GITHUB_TOKEN }}
67+
mode: monorepo

.github/workflows/code-pushup.yml

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ permissions:
1414
pull-requests: write
1515

1616
jobs:
17-
code-pushup:
17+
standalone:
1818
runs-on: ubuntu-latest
19-
name: Run Code PushUp
19+
name: Standalone mode
2020
# ignore PRs from forks, handled by code-pushup-fork.yml
2121
if: ${{ !github.event.pull_request.head.repo.fork }}
2222
env:
@@ -39,3 +39,31 @@ jobs:
3939
uses: ./.github/actions/code-pushup
4040
with:
4141
token: ${{ secrets.GITHUB_TOKEN }}
42+
mode: standalone
43+
44+
monorepo:
45+
runs-on: ubuntu-latest
46+
name: Monorepo mode
47+
# ignore PRs from forks, handled by code-pushup-fork.yml
48+
if: ${{ !github.event.pull_request.head.repo.fork }}
49+
env:
50+
CP_API_KEY: ${{ secrets.CP_API_KEY }}
51+
steps:
52+
- name: Checkout repository
53+
uses: actions/checkout@v4
54+
with:
55+
fetch-depth: 0
56+
- name: Set up Node.js
57+
uses: actions/setup-node@v4
58+
with:
59+
node-version-file: .node-version
60+
cache: npm
61+
- name: Set base and head for Nx affected commands
62+
uses: nrwl/nx-set-shas@v4
63+
- name: Install dependencies
64+
run: npm ci
65+
- name: Run Code PushUp action
66+
uses: ./.github/actions/code-pushup
67+
with:
68+
token: ${{ secrets.GITHUB_TOKEN }}
69+
mode: monorepo

0 commit comments

Comments
 (0)