diff --git a/scripts/ci/codegen/pushGeneratedCode.ts b/scripts/ci/codegen/pushGeneratedCode.ts index 78dde3b53ad..b1c7f3bf558 100644 --- a/scripts/ci/codegen/pushGeneratedCode.ts +++ b/scripts/ci/codegen/pushGeneratedCode.ts @@ -20,7 +20,7 @@ export async function pushGeneratedCode(): Promise { console.log(`Checking codegen status on '${baseBranch}'.`); const nbDiff = await getNbGitDiff({ - branch: baseBranch, + branch: 'origin/generated/main', head: null, path: FOLDERS_TO_CHECK, }); @@ -59,7 +59,7 @@ export async function pushGeneratedCode(): Promise { } const commitMessage = - await run(`git show -s ${baseBranch} --format="Generated code for commit %H. + await run(`git show -s ${baseBranch} --format="chore: generated code for commit %H. Co-authored-by: %an <%ae>"`); diff --git a/scripts/ci/codegen/spreadGeneration.ts b/scripts/ci/codegen/spreadGeneration.ts index aca4ccd45c2..5157d0e5649 100644 --- a/scripts/ci/codegen/spreadGeneration.ts +++ b/scripts/ci/codegen/spreadGeneration.ts @@ -13,6 +13,7 @@ import { } from '../../common'; import { getLanguageFolder } from '../../config'; import { cloneRepository, configureGitHubAuthor } from '../../release/common'; +import { getNbGitDiff } from '../utils'; export function decideWhereToSpread(commitMessage: string): string[] { if (commitMessage.startsWith('chore: release')) { @@ -69,6 +70,16 @@ async function spreadGeneration(): Promise { await emptyDirExceptForDotGit(tempGitDir); await copy(clientPath, tempGitDir, { preserveTimestamps: true }); + if ( + (await getNbGitDiff({ + head: null, + cwd: tempGitDir, + })) === 0 + ) { + console.log(`Skipping ${lang} repository, because there is no change.`); + return; + } + await configureGitHubAuthor(tempGitDir); await run(`git add .`, { cwd: tempGitDir }); await gitCommit({ diff --git a/scripts/ci/utils.ts b/scripts/ci/utils.ts index d00c1a05768..4951f2aab9a 100644 --- a/scripts/ci/utils.ts +++ b/scripts/ci/utils.ts @@ -2,22 +2,32 @@ import { run } from '../common'; /** * Returns the number of diff between a `branch` and its `HEAD` for the given `path`. - * Head defaults to `HEAD`, providing `null` will check unstaged changes. + * + * @param opts - Parameters of the method. + * @param opts.branch - The branch to trigger the operation, defaults to '' (current branch). + * @param opts.head - The head to compare the operation, defaults to 'HEAD', providing 'null' will check for unstaged changes. + * @param opts.path - The path to look for changes in, defaults to '.' (current directory). + * @param opts.cwd - The path to run the command, defaults to current directory. */ export async function getNbGitDiff({ - branch, + branch = '', head = 'HEAD', - path, -}: { + path = '.', + cwd, +}: Partial<{ branch: string; - head?: string | null; + head: string | null; path: string; -}): Promise { + cwd: string; +}>): Promise { const checkHead = head === null ? '' : `...${head}`; return parseInt( ( - await run(`git diff --shortstat ${branch}${checkHead} -- ${path} | wc -l`) + await run( + `git diff --shortstat ${branch}${checkHead} -- ${path} | wc -l`, + { cwd } + ) ).trim(), 10 ); diff --git a/scripts/release/create-release-issue.ts b/scripts/release/create-release-issue.ts index 99785d6e99f..1089a9757f7 100755 --- a/scripts/release/create-release-issue.ts +++ b/scripts/release/create-release-issue.ts @@ -2,6 +2,7 @@ import dotenv from 'dotenv'; import semver from 'semver'; +import { getNbGitDiff } from '../ci/utils'; import { LANGUAGES, ROOT_ENV_PATH, @@ -161,7 +162,11 @@ async function createReleaseIssue(): Promise { ); } - if (await run('git status --porcelain')) { + if ( + (await getNbGitDiff({ + head: null, + })) !== 0 + ) { throw new Error( 'Working directory is not clean. Commit all the changes first.' );