Skip to content

Commit c702686

Browse files
authored
fix(scripts): prevent errors on push to docs (#3485)
1 parent 097849a commit c702686

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

scripts/ci/codegen/pushToAlgoliaDoc.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
configureGitHubAuthor,
1212
getOctokit,
1313
setVerbose,
14+
gitBranchExists,
1415
} from '../../common.js';
1516
import { getNbGitDiff } from '../utils.js';
1617

@@ -41,6 +42,10 @@ async function pushToAlgoliaDoc(): Promise<void> {
4142
);
4243
await fsp.rm(tempGitDir, { force: true, recursive: true });
4344
await run(`git clone --depth 1 ${githubURL} ${tempGitDir}`);
45+
if (await gitBranchExists(targetBranch, tempGitDir)) {
46+
await run(`git fetch origin ${targetBranch}`, { cwd: tempGitDir });
47+
await run(`git push -d origin ${targetBranch}`, { cwd: tempGitDir });
48+
}
4449
await run(`git checkout -B ${targetBranch}`, { cwd: tempGitDir });
4550

4651
const pathToSpecs = toAbsolutePath(`${tempGitDir}/app_data/api/specs`);
@@ -58,7 +63,7 @@ async function pushToAlgoliaDoc(): Promise<void> {
5863

5964
await configureGitHubAuthor(tempGitDir);
6065

61-
const message = 'feat(clients): automatic update from api-clients-automation repository';
66+
const message = 'feat: update specs and supported versions';
6267
await run('git add .', { cwd: tempGitDir });
6368
await gitCommit({
6469
message,
@@ -81,6 +86,15 @@ async function pushToAlgoliaDoc(): Promise<void> {
8186
head: targetBranch,
8287
});
8388

89+
await octokit.issues.createComment({
90+
owner: OWNER,
91+
repo: repository,
92+
issue_number: data.number,
93+
body: [
94+
`[**Preview SLA changes&rarr;**](https://deploy-preview-${data.number}--algolia-docs.netlify.app/doc/libraries/supported-versions/)`,
95+
].join('\n\n'),
96+
});
97+
8498
console.log(`Pull request created on ${OWNER}/${repository}`);
8599
console.log(` > ${data.url}`);
86100
}

scripts/common.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ async function buildCustomGenerators(): Promise<void> {
175175
spinner.succeed();
176176
}
177177

178-
export async function gitBranchExists(branchName: string): Promise<boolean> {
179-
return Boolean(await run(`git ls-remote --heads origin ${branchName}`));
178+
export async function gitBranchExists(branchName: string, cwd?: string): Promise<boolean> {
179+
return Boolean(await run(`git ls-remote --heads origin ${branchName}`, { cwd }));
180180
}
181181

182182
export async function emptyDirExceptForDotGit(dir: string): Promise<void> {

0 commit comments

Comments
 (0)