Skip to content

Commit a292828

Browse files
authored
fix(scripts): push to repository (#4847)
1 parent 7bb14f3 commit a292828

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

scripts/ci/codegen/pushToRepository.ts

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ async function handleSpecFiles(spec: SpecsToPush, tempGitDir: string): Promise<v
3535
await run(`cp ${toAbsolutePath('docs/versions-history-with-sla-and-support-policy.json')} ${output}`);
3636
}
3737

38-
// adblock extensions ban words like `analytics` so we use a different file name just so the doc dans render it
39-
if (spec.ext === 'yml') {
40-
await run(`mv ${output}/analytics.yml ${output}/searchstats.yml`);
41-
}
42-
4338
for (const client of CLIENTS) {
4439
const pathToBundledSpec = toAbsolutePath(`docs/bundled/${client}.${spec.ext}`);
4540

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

5752
for (const [k, v] of Object.entries(spec.placeholderVariables)) {
58-
file = file.replace(k, v);
53+
file = file.replaceAll(k, v);
5954
}
6055

6156
await fsp.writeFile(outputFile, file);
6257
}
6358
}
59+
60+
// adblock extensions ban words like `analytics` so we use a different file name just so the doc dans render it
61+
if (spec.ext === 'yml') {
62+
await run(`mv ${output}/analytics.yml ${output}/searchstats.yml`);
63+
}
6464
}
6565

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

132132
for (const task of config.tasks) {
133+
console.log(`Handling '${task.files.type}' file(s)`);
134+
133135
await run(`git checkout ${config.baseBranch}`, { cwd: tempGitDir });
134136
await run(`git pull origin ${config.baseBranch}`, { cwd: tempGitDir });
135-
136-
if (await gitBranchExists(task.prBranch, tempGitDir)) {
137-
await run(`git fetch origin ${task.prBranch}`, { cwd: tempGitDir });
138-
await run(`git push -d origin ${task.prBranch}`, { cwd: tempGitDir });
139-
}
140137
await run(`git checkout -B ${task.prBranch}`, { cwd: tempGitDir });
141138

142-
console.log(`Handling '${task.files.type}' file(s)`);
143-
144139
if (task.files.type === 'specs') {
145140
await handleSpecFiles(task.files, tempGitDir);
146141
} else {
147142
await handleGuideFiles(task.files, tempGitDir);
148143
}
149144

145+
if (process.env.DRYRUN) {
146+
console.log(`asked for a dry run, stopping before push and PR for '${repository}' on task '${task.prBranch}'`);
147+
148+
continue;
149+
}
150+
151+
if (await gitBranchExists(task.prBranch, tempGitDir)) {
152+
await run(`git fetch origin ${task.prBranch}`, { cwd: tempGitDir });
153+
await run(`git push -d origin ${task.prBranch}`, { cwd: tempGitDir });
154+
}
155+
150156
if ((await getNbGitDiff({ head: null, cwd: tempGitDir })) === 0) {
151157
console.log(`❎ Skipping push to ${OWNER}/${repository} because there is no change.`);
152158

153159
continue;
154160
}
155161

156-
console.log(`Pushing to '${task.prBranch}`);
157-
158162
await configureGitHubAuthor(tempGitDir);
159163

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

167-
if (process.env.DRYRUN) {
168-
console.log(`asked for a dry run, stopping before push and PR for '${repository}' on task '${task.prBranch}'`);
169-
170-
continue;
171-
}
172-
173171
await run(`git push -f -u origin ${task.prBranch}`, { cwd: tempGitDir });
174172

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

0 commit comments

Comments
 (0)