Skip to content

Commit

Permalink
fix: write with retry fails with separate repository (#216)
Browse files Browse the repository at this point in the history
* remove the cloned directory when push fails so that next clone will work
  • Loading branch information
ktrz authored Jan 25, 2024
1 parent 18a7953 commit 9598b26
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,8 @@ async function writeBenchmarkToGitHubPagesWithRetry(
skipFetchGhPages,
maxItemsInChart,
} = config;
const rollbackActions = new Array<() => Promise<void>>();

// FIXME: This payload is not available on `schedule:` or `workflow_dispatch:` events.
const isPrivateRepo = github.context.payload.repository?.private ?? false;

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

// we need to rollback actions in order so not running them concurrently
for (const action of rollbackActions) {
await action();
}

core.warning(
`Retrying to generate a commit and push to remote ${ghPagesBranch} with retry count ${retry}...`,
);
Expand Down

0 comments on commit 9598b26

Please sign in to comment.