Skip to content

Commit 84fc7c2

Browse files
chore(ci): skip spreading if there is no change (#353)
Co-authored-by: Clément Vannicatte <[email protected]> Co-authored-by: Clément Vannicatte <[email protected]>
1 parent 97c1aaf commit 84fc7c2

File tree

4 files changed

+36
-10
lines changed

4 files changed

+36
-10
lines changed

scripts/ci/codegen/pushGeneratedCode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export async function pushGeneratedCode(): Promise<void> {
2020
console.log(`Checking codegen status on '${baseBranch}'.`);
2121

2222
const nbDiff = await getNbGitDiff({
23-
branch: baseBranch,
23+
branch: 'origin/generated/main',
2424
head: null,
2525
path: FOLDERS_TO_CHECK,
2626
});
@@ -59,7 +59,7 @@ export async function pushGeneratedCode(): Promise<void> {
5959
}
6060

6161
const commitMessage =
62-
await run(`git show -s ${baseBranch} --format="Generated code for commit %H.
62+
await run(`git show -s ${baseBranch} --format="chore: generated code for commit %H.
6363
6464
Co-authored-by: %an <%ae>"`);
6565

scripts/ci/codegen/spreadGeneration.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
} from '../../common';
1414
import { getLanguageFolder } from '../../config';
1515
import { cloneRepository, configureGitHubAuthor } from '../../release/common';
16+
import { getNbGitDiff } from '../utils';
1617

1718
export function decideWhereToSpread(commitMessage: string): string[] {
1819
if (commitMessage.startsWith('chore: release')) {
@@ -69,6 +70,16 @@ async function spreadGeneration(): Promise<void> {
6970
await emptyDirExceptForDotGit(tempGitDir);
7071
await copy(clientPath, tempGitDir, { preserveTimestamps: true });
7172

73+
if (
74+
(await getNbGitDiff({
75+
head: null,
76+
cwd: tempGitDir,
77+
})) === 0
78+
) {
79+
console.log(`Skipping ${lang} repository, because there is no change.`);
80+
return;
81+
}
82+
7283
await configureGitHubAuthor(tempGitDir);
7384
await run(`git add .`, { cwd: tempGitDir });
7485
await gitCommit({

scripts/ci/utils.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,32 @@ import { run } from '../common';
22

33
/**
44
* Returns the number of diff between a `branch` and its `HEAD` for the given `path`.
5-
* Head defaults to `HEAD`, providing `null` will check unstaged changes.
5+
*
6+
* @param opts - Parameters of the method.
7+
* @param opts.branch - The branch to trigger the operation, defaults to '' (current branch).
8+
* @param opts.head - The head to compare the operation, defaults to 'HEAD', providing 'null' will check for unstaged changes.
9+
* @param opts.path - The path to look for changes in, defaults to '.' (current directory).
10+
* @param opts.cwd - The path to run the command, defaults to current directory.
611
*/
712
export async function getNbGitDiff({
8-
branch,
13+
branch = '',
914
head = 'HEAD',
10-
path,
11-
}: {
15+
path = '.',
16+
cwd,
17+
}: Partial<{
1218
branch: string;
13-
head?: string | null;
19+
head: string | null;
1420
path: string;
15-
}): Promise<number> {
21+
cwd: string;
22+
}>): Promise<number> {
1623
const checkHead = head === null ? '' : `...${head}`;
1724

1825
return parseInt(
1926
(
20-
await run(`git diff --shortstat ${branch}${checkHead} -- ${path} | wc -l`)
27+
await run(
28+
`git diff --shortstat ${branch}${checkHead} -- ${path} | wc -l`,
29+
{ cwd }
30+
)
2131
).trim(),
2232
10
2333
);

scripts/release/create-release-issue.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import dotenv from 'dotenv';
33
import semver from 'semver';
44

5+
import { getNbGitDiff } from '../ci/utils';
56
import {
67
LANGUAGES,
78
ROOT_ENV_PATH,
@@ -161,7 +162,11 @@ async function createReleaseIssue(): Promise<void> {
161162
);
162163
}
163164

164-
if (await run('git status --porcelain')) {
165+
if (
166+
(await getNbGitDiff({
167+
head: null,
168+
})) !== 0
169+
) {
165170
throw new Error(
166171
'Working directory is not clean. Commit all the changes first.'
167172
);

0 commit comments

Comments
 (0)