Skip to content

fix(scripts): prevent errors on push to docs #3485

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion scripts/ci/codegen/pushToAlgoliaDoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
configureGitHubAuthor,
getOctokit,
setVerbose,
gitBranchExists,
} from '../../common.js';
import { getNbGitDiff } from '../utils.js';

Expand Down Expand Up @@ -41,6 +42,10 @@ async function pushToAlgoliaDoc(): Promise<void> {
);
await fsp.rm(tempGitDir, { force: true, recursive: true });
await run(`git clone --depth 1 ${githubURL} ${tempGitDir}`);
if (await gitBranchExists(targetBranch, tempGitDir)) {
await run(`git fetch origin ${targetBranch}`, { cwd: tempGitDir });
await run(`git push -d origin ${targetBranch}`, { cwd: tempGitDir });
}
await run(`git checkout -B ${targetBranch}`, { cwd: tempGitDir });

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

await configureGitHubAuthor(tempGitDir);

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

await octokit.issues.createComment({
owner: OWNER,
repo: repository,
issue_number: data.number,
body: [
`[**Preview SLA changes&rarr;**](https://deploy-preview-${data.number}--algolia-docs.netlify.app/doc/libraries/supported-versions/)`,
].join('\n\n'),
});

console.log(`Pull request created on ${OWNER}/${repository}`);
console.log(` > ${data.url}`);
}
Expand Down
4 changes: 2 additions & 2 deletions scripts/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ async function buildCustomGenerators(): Promise<void> {
spinner.succeed();
}

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

export async function emptyDirExceptForDotGit(dir: string): Promise<void> {
Expand Down
Loading