Skip to content

Commit 9598b26

Browse files
authored
fix: write with retry fails with separate repository (#216)
* remove the cloned directory when push fails so that next clone will work
1 parent 18a7953 commit 9598b26

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/write.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,8 @@ async function writeBenchmarkToGitHubPagesWithRetry(
383383
skipFetchGhPages,
384384
maxItemsInChart,
385385
} = config;
386+
const rollbackActions = new Array<() => Promise<void>>();
387+
386388
// FIXME: This payload is not available on `schedule:` or `workflow_dispatch:` events.
387389
const isPrivateRepo = github.context.payload.repository?.private ?? false;
388390

@@ -392,6 +394,9 @@ async function writeBenchmarkToGitHubPagesWithRetry(
392394
if (githubToken && !skipFetchGhPages && ghRepository) {
393395
benchmarkBaseDir = './benchmark-data-repository';
394396
await git.clone(githubToken, ghRepository, benchmarkBaseDir);
397+
rollbackActions.push(async () => {
398+
await io.rmRF(benchmarkBaseDir);
399+
});
395400
extraGitArguments = [`--work-tree=${benchmarkBaseDir}`, `--git-dir=${benchmarkBaseDir}/.git`];
396401
await git.checkout(ghPagesBranch, extraGitArguments);
397402
} else if (!skipFetchGhPages && (!isPrivateRepo || githubToken)) {
@@ -446,6 +451,11 @@ async function writeBenchmarkToGitHubPagesWithRetry(
446451
core.debug('Rollback the auto-generated commit before retry');
447452
await git.cmd(extraGitArguments, 'reset', '--hard', 'HEAD~1');
448453

454+
// we need to rollback actions in order so not running them concurrently
455+
for (const action of rollbackActions) {
456+
await action();
457+
}
458+
449459
core.warning(
450460
`Retrying to generate a commit and push to remote ${ghPagesBranch} with retry count ${retry}...`,
451461
);

0 commit comments

Comments
 (0)