From 89948b2bfdddc705c7266f8c94f20ffa09352523 Mon Sep 17 00:00:00 2001 From: Bogdan Nechyporenko Date: Fri, 14 Mar 2025 21:33:27 +0100 Subject: [PATCH] Made "github:repo:push" action idempotent Signed-off-by: Bogdan Nechyporenko --- .changeset/odd-seas-switch.md | 5 ++ .../src/actions/githubRepoPush.ts | 62 ++++++++++--------- 2 files changed, 39 insertions(+), 28 deletions(-) create mode 100644 .changeset/odd-seas-switch.md diff --git a/.changeset/odd-seas-switch.md b/.changeset/odd-seas-switch.md new file mode 100644 index 0000000000..31bbde8d09 --- /dev/null +++ b/.changeset/odd-seas-switch.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-scaffolder-backend-module-github': patch +--- + +Made "github:repo:push" action idempotent diff --git a/plugins/scaffolder-backend-module-github/src/actions/githubRepoPush.ts b/plugins/scaffolder-backend-module-github/src/actions/githubRepoPush.ts index dcb159806c..1923a0bd35 100644 --- a/plugins/scaffolder-backend-module-github/src/actions/githubRepoPush.ts +++ b/plugins/scaffolder-backend-module-github/src/actions/githubRepoPush.ts @@ -165,34 +165,40 @@ export function createGithubRepoPushAction(options: { const remoteUrl = targetRepo.data.clone_url; const repoContentsUrl = `${targetRepo.data.html_url}/blob/${defaultBranch}`; - const { commitHash } = await initRepoPushAndProtect( - remoteUrl, - octokitOptions.auth, - ctx.workspacePath, - ctx.input.sourcePath, - defaultBranch, - protectDefaultBranch, - protectEnforceAdmins, - owner, - client, - repo, - requireCodeOwnerReviews, - bypassPullRequestAllowances, - requiredApprovingReviewCount, - restrictions, - requiredStatusCheckContexts, - requireBranchesToBeUpToDate, - requiredConversationResolution, - requireLastPushApproval, - config, - ctx.logger, - gitCommitMessage, - gitAuthorName, - gitAuthorEmail, - dismissStaleReviews, - requiredCommitSigning, - requiredLinearHistory, - ); + const commitHash = await ctx.checkpoint({ + key: `init.repo.publish.${owner}.${client}.${repo}`, + fn: async () => { + const { commitHash: hash } = await initRepoPushAndProtect( + remoteUrl, + octokitOptions.auth, + ctx.workspacePath, + ctx.input.sourcePath, + defaultBranch, + protectDefaultBranch, + protectEnforceAdmins, + owner, + client, + repo, + requireCodeOwnerReviews, + bypassPullRequestAllowances, + requiredApprovingReviewCount, + restrictions, + requiredStatusCheckContexts, + requireBranchesToBeUpToDate, + requiredConversationResolution, + requireLastPushApproval, + config, + ctx.logger, + gitCommitMessage, + gitAuthorName, + gitAuthorEmail, + dismissStaleReviews, + requiredCommitSigning, + requiredLinearHistory, + ); + return hash; + }, + }); ctx.output('remoteUrl', remoteUrl); ctx.output('repoContentsUrl', repoContentsUrl);