@tahminator/pipeline 1.0.97 → 1.0.98

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -327,6 +327,8 @@ await client.updateK8sTagWithPR({
327
327
  environment: "production",
328
328
  originRepo: ["tahminator", "pipeline"],
329
329
  manifestRepo: ["tahminator", "infra"],
330
+ // optional: max PR merge attempts (2s apart) before throwing; defaults to 10
331
+ mergeAttempts: 10,
330
332
  });
331
333
 
332
334
  await client.sendPrMessage({
@@ -51,13 +51,19 @@ export declare class GitHubPRManager {
51
51
  private readonly client;
52
52
  constructor(client: Octokit);
53
53
  uploadDirectoryContents({ owner, repository, sourceDirectory, directory, message, branch, }: UploadDirectoryContentsArgs): Promise<void>;
54
- updateK8sTagWithPR({ newTag, imageName, kustomizationFilePath, environment, originRepo, manifestRepo, }: {
54
+ updateK8sTagWithPR({ newTag, imageName, kustomizationFilePath, environment, originRepo, manifestRepo, mergeAttempts, }: {
55
55
  newTag: string;
56
56
  imageName: string;
57
57
  kustomizationFilePath: string;
58
58
  environment: Environment;
59
59
  originRepo: [OwnerString, RepoString];
60
60
  manifestRepo: [OwnerString, RepoString];
61
+ /**
62
+ * max number of times to try merging the created PR before failing
63
+ *
64
+ * @default 10
65
+ */
66
+ mergeAttempts?: number;
61
67
  }): Promise<void>;
62
68
  mergePr({ prId, owner, repository, mergeMethod, }: {
63
69
  prId: number;
@@ -49,7 +49,7 @@ export class GitHubPRManager {
49
49
  sha: commit.sha,
50
50
  });
51
51
  }
52
- async updateK8sTagWithPR({ newTag, imageName, kustomizationFilePath, environment, originRepo, manifestRepo, }) {
52
+ async updateK8sTagWithPR({ newTag, imageName, kustomizationFilePath, environment, originRepo, manifestRepo, mergeAttempts = 10, }) {
53
53
  const [manifestOwner, manifestRepository] = manifestRepo;
54
54
  const [originOwner, originRepository] = originRepo;
55
55
  const newBranchName = `${imageName}-${newTag}-${Utils.generateShortId()}`;
@@ -111,11 +111,29 @@ export class GitHubPRManager {
111
111
  base: baseBranch,
112
112
  body: `Automated image tag change to ${newTag} for ${imageName} in ${environment} triggered by [${originOwner}/${originRepository}](https://github.com/${originOwner}/${originRepository}).`,
113
113
  });
114
- await this.mergePr({
115
- prId: pr.number,
116
- owner: manifestOwner,
117
- repository: manifestRepository,
114
+ let lastMergeError;
115
+ const merged = await Utils.waitUntil({
116
+ attempts: mergeAttempts,
117
+ intervalMs: 2000,
118
+ predicate: async (attempt) => {
119
+ try {
120
+ await this.mergePr({
121
+ prId: pr.number,
122
+ owner: manifestOwner,
123
+ repository: manifestRepository,
124
+ });
125
+ return true;
126
+ }
127
+ catch (e) {
128
+ lastMergeError = e;
129
+ console.warn(`Failed to merge PR #${pr.number} (${attempt}/${mergeAttempts}):`, e);
130
+ return false;
131
+ }
132
+ },
118
133
  });
134
+ if (!merged) {
135
+ throw new Error(`Failed to merge PR #${pr.number} after ${mergeAttempts} attempts`, { cause: lastMergeError });
136
+ }
119
137
  }
120
138
  async mergePr({ prId, owner, repository, mergeMethod = "squash", }) {
121
139
  await this.client.rest.pulls.merge({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tahminator/pipeline",
3
- "version": "1.0.97",
3
+ "version": "1.0.98",
4
4
  "description": "A collection of Bun shell scripts that can be re-used in various CICD pipelines.",
5
5
  "author": "Tahmid Ahmed",
6
6
  "repository": {