@treeseed/sdk 0.6.38 → 0.6.39

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.
@@ -2001,12 +2001,14 @@ async function syncTreeseedGitHubEnvironment({
2001
2001
  const githubClient = createGitHubApiClient({ env: ghEnv });
2002
2002
  const environment = scope === "prod" ? "production" : scope;
2003
2003
  const deploymentBranch = scope === "prod" ? PRODUCTION_BRANCH : scope === "staging" ? STAGING_BRANCH : null;
2004
+ const deploymentTag = scope === "prod" ? "*.*.*" : null;
2004
2005
  const progress = (message, stream = "stdout") => onProgress?.(message, stream);
2005
2006
  if (!dryRun) {
2006
2007
  progress(`[${scope}][github][environment] Ensuring GitHub environment ${environment} exists...`);
2007
2008
  await ensureGitHubActionsEnvironment(repository, environment, {
2008
2009
  client: githubClient,
2009
- branchName: deploymentBranch
2010
+ branchName: deploymentBranch,
2011
+ tagName: deploymentTag
2010
2012
  });
2011
2013
  }
2012
2014
  progress(`[${scope}][github][sync] Loading existing GitHub secrets and variables...`);
@@ -97,9 +97,10 @@ export declare function listGitHubRepositoryVariableNames(repository: string | {
97
97
  export declare function ensureGitHubActionsEnvironment(repository: string | {
98
98
  owner: string;
99
99
  name: string;
100
- }, environmentName: string, { client, branchName, }?: {
100
+ }, environmentName: string, { client, branchName, tagName, }?: {
101
101
  client?: GitHubApiClient;
102
102
  branchName?: string | null;
103
+ tagName?: string | null;
103
104
  }): Promise<{
104
105
  repository: string;
105
106
  environment: string;
@@ -223,27 +223,32 @@ async function listGitHubRepositoryVariableNames(repository, { client = createGi
223
223
  }
224
224
  async function ensureGitHubActionsEnvironment(repository, environmentName, {
225
225
  client = createGitHubApiClient(),
226
- branchName
226
+ branchName,
227
+ tagName
227
228
  } = {}) {
228
229
  const { owner, name: repo } = typeof repository === "string" ? parseGitHubRepositorySlug(repository) : repository;
230
+ const desiredPolicies = [
231
+ ...branchName ? [{ name: branchName, type: "branch" }] : [],
232
+ ...tagName ? [{ name: tagName, type: "tag" }] : []
233
+ ];
229
234
  try {
230
235
  await withGitHubApiRetries(() => client.request("PUT /repos/{owner}/{repo}/environments/{environment_name}", {
231
236
  owner,
232
237
  repo,
233
238
  environment_name: environmentName,
234
- ...branchName ? {
239
+ ...desiredPolicies.length > 0 ? {
235
240
  deployment_branch_policy: {
236
241
  protected_branches: false,
237
242
  custom_branch_policies: true
238
243
  }
239
244
  } : {}
240
245
  }));
241
- if (branchName) {
242
- await ensureGitHubEnvironmentBranchPolicy(client, {
246
+ if (desiredPolicies.length > 0) {
247
+ await ensureGitHubEnvironmentDeploymentPolicies(client, {
243
248
  owner,
244
249
  repo,
245
250
  environmentName,
246
- branchName
251
+ policies: desiredPolicies
247
252
  });
248
253
  }
249
254
  return { repository: `${owner}/${repo}`, environment: environmentName };
@@ -251,11 +256,11 @@ async function ensureGitHubActionsEnvironment(repository, environmentName, {
251
256
  throw normalizeGitHubApiError(error, `Unable to ensure GitHub environment ${environmentName} for ${owner}/${repo}`);
252
257
  }
253
258
  }
254
- async function ensureGitHubEnvironmentBranchPolicy(client, {
259
+ async function ensureGitHubEnvironmentDeploymentPolicies(client, {
255
260
  owner,
256
261
  repo,
257
262
  environmentName,
258
- branchName
263
+ policies: desiredPolicies
259
264
  }) {
260
265
  const response = await withGitHubApiRetries(() => client.request(
261
266
  "GET /repos/{owner}/{repo}/environments/{environment_name}/deployment-branch-policies",
@@ -267,9 +272,10 @@ async function ensureGitHubEnvironmentBranchPolicy(client, {
267
272
  }
268
273
  ));
269
274
  const policies = Array.isArray(response.data?.branch_policies) ? response.data.branch_policies : [];
270
- const desired = policies.find((policy) => policy.name === branchName && (policy.type ?? "branch") === "branch");
275
+ const desiredKey = (policy) => `${policy.type ?? "branch"}:${policy.name ?? ""}`;
276
+ const desiredKeys = new Set(desiredPolicies.map((policy) => desiredKey(policy)));
271
277
  for (const policy of policies) {
272
- if (!policy.id || policy.name === branchName && (policy.type ?? "branch") === "branch") {
278
+ if (!policy.id || desiredKeys.has(desiredKey(policy))) {
273
279
  continue;
274
280
  }
275
281
  await withGitHubApiRetries(() => client.request(
@@ -282,25 +288,28 @@ async function ensureGitHubEnvironmentBranchPolicy(client, {
282
288
  }
283
289
  ));
284
290
  }
285
- if (desired) {
286
- return;
287
- }
288
- try {
289
- await withGitHubApiRetries(() => client.request(
290
- "POST /repos/{owner}/{repo}/environments/{environment_name}/deployment-branch-policies",
291
- {
292
- owner,
293
- repo,
294
- environment_name: environmentName,
295
- name: branchName,
296
- type: "branch"
291
+ const existingKeys = new Set(policies.map((policy) => desiredKey(policy)));
292
+ for (const policy of desiredPolicies) {
293
+ if (existingKeys.has(desiredKey(policy))) {
294
+ continue;
295
+ }
296
+ try {
297
+ await withGitHubApiRetries(() => client.request(
298
+ "POST /repos/{owner}/{repo}/environments/{environment_name}/deployment-branch-policies",
299
+ {
300
+ owner,
301
+ repo,
302
+ environment_name: environmentName,
303
+ name: policy.name,
304
+ type: policy.type
305
+ }
306
+ ));
307
+ } catch (error) {
308
+ if (error && typeof error === "object" && error.status === 303) {
309
+ continue;
297
310
  }
298
- ));
299
- } catch (error) {
300
- if (error && typeof error === "object" && error.status === 303) {
301
- return;
311
+ throw error;
302
312
  }
303
- throw error;
304
313
  }
305
314
  }
306
315
  async function paginateGitHubEnvironmentNames(client, route, params) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@treeseed/sdk",
3
- "version": "0.6.38",
3
+ "version": "0.6.39",
4
4
  "description": "Shared Treeseed SDK for content-backed and D1-backed object models.",
5
5
  "license": "AGPL-3.0-only",
6
6
  "repository": {