Skip to content

fix(scripts): push to repository #4847

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 3 commits into from
May 13, 2025
Merged
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
40 changes: 19 additions & 21 deletions scripts/ci/codegen/pushToRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ async function handleSpecFiles(spec: SpecsToPush, tempGitDir: string): Promise<v
await run(`cp ${toAbsolutePath('docs/versions-history-with-sla-and-support-policy.json')} ${output}`);
}

// adblock extensions ban words like `analytics` so we use a different file name just so the doc dans render it
if (spec.ext === 'yml') {
await run(`mv ${output}/analytics.yml ${output}/searchstats.yml`);
}

for (const client of CLIENTS) {
const pathToBundledSpec = toAbsolutePath(`docs/bundled/${client}.${spec.ext}`);

Expand All @@ -55,12 +50,17 @@ async function handleSpecFiles(spec: SpecsToPush, tempGitDir: string): Promise<v
let file = await fsp.readFile(outputFile, 'utf8');

for (const [k, v] of Object.entries(spec.placeholderVariables)) {
file = file.replace(k, v);
file = file.replaceAll(k, v);
}

await fsp.writeFile(outputFile, file);
}
}

// adblock extensions ban words like `analytics` so we use a different file name just so the doc dans render it
if (spec.ext === 'yml') {
await run(`mv ${output}/analytics.yml ${output}/searchstats.yml`);
}
}

async function handleGuideFiles(guide: GuidesToPush, tempGitDir: string): Promise<void> {
Expand Down Expand Up @@ -130,31 +130,35 @@ async function pushToRepository(repository: string, config: RepositoryConfigurat
await run(`gh repo clone ${OWNER}/${repository} ${tempGitDir}`);

for (const task of config.tasks) {
console.log(`Handling '${task.files.type}' file(s)`);

await run(`git checkout ${config.baseBranch}`, { cwd: tempGitDir });
await run(`git pull origin ${config.baseBranch}`, { cwd: tempGitDir });

if (await gitBranchExists(task.prBranch, tempGitDir)) {
await run(`git fetch origin ${task.prBranch}`, { cwd: tempGitDir });
await run(`git push -d origin ${task.prBranch}`, { cwd: tempGitDir });
}
await run(`git checkout -B ${task.prBranch}`, { cwd: tempGitDir });

console.log(`Handling '${task.files.type}' file(s)`);

if (task.files.type === 'specs') {
await handleSpecFiles(task.files, tempGitDir);
} else {
await handleGuideFiles(task.files, tempGitDir);
}

if (process.env.DRYRUN) {
console.log(`asked for a dry run, stopping before push and PR for '${repository}' on task '${task.prBranch}'`);

continue;
}

if (await gitBranchExists(task.prBranch, tempGitDir)) {
await run(`git fetch origin ${task.prBranch}`, { cwd: tempGitDir });
await run(`git push -d origin ${task.prBranch}`, { cwd: tempGitDir });
}

if ((await getNbGitDiff({ head: null, cwd: tempGitDir })) === 0) {
console.log(`❎ Skipping push to ${OWNER}/${repository} because there is no change.`);

continue;
}

console.log(`Pushing to '${task.prBranch}`);

await configureGitHubAuthor(tempGitDir);

await run('git add .', { cwd: tempGitDir });
Expand All @@ -164,12 +168,6 @@ async function pushToRepository(repository: string, config: RepositoryConfigurat
cwd: tempGitDir,
});

if (process.env.DRYRUN) {
console.log(`asked for a dry run, stopping before push and PR for '${repository}' on task '${task.prBranch}'`);

continue;
}

await run(`git push -f -u origin ${task.prBranch}`, { cwd: tempGitDir });

console.log(`Creating pull request on ${OWNER}/${repository}...`);
Expand Down
Loading