@adobe/helix-deploy 9.4.5 → 9.5.1

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/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## [9.5.1](https://github.com/adobe/helix-deploy/compare/v9.5.0...v9.5.1) (2024-01-06)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **deps:** update external fixes ([bbdc3d1](https://github.com/adobe/helix-deploy/commit/bbdc3d166ea14c26e386de7cac686aad0596ad01))
7
+
8
+ # [9.5.0](https://github.com/adobe/helix-deploy/compare/v9.4.5...v9.5.0) (2024-01-05)
9
+
10
+
11
+ ### Features
12
+
13
+ * cleanup ci and patch versions ([#632](https://github.com/adobe/helix-deploy/issues/632)) ([448f406](https://github.com/adobe/helix-deploy/commit/448f406e778a6f0704fc81054cd61dc728d62916))
14
+
1
15
  ## [9.4.5](https://github.com/adobe/helix-deploy/compare/v9.4.4...v9.4.5) (2023-12-30)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-deploy",
3
- "version": "9.4.5",
3
+ "version": "9.5.1",
4
4
  "description": "Library and Commandline Tools to build and deploy OpenWhisk Actions",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/adobe/helix-deploy#readme",
@@ -38,12 +38,13 @@
38
38
  "dependencies": {
39
39
  "@adobe/fastly-native-promises": "3.0.6",
40
40
  "@adobe/fetch": "4.1.1",
41
- "@aws-sdk/client-apigatewayv2": "3.484.0",
42
- "@aws-sdk/client-lambda": "3.484.0",
43
- "@aws-sdk/client-s3": "3.484.0",
44
- "@aws-sdk/client-secrets-manager": "3.484.0",
45
- "@aws-sdk/client-ssm": "3.484.0",
46
- "@aws-sdk/client-sts": "3.484.0",
41
+ "@adobe/helix-shared-process-queue": "3.0.0",
42
+ "@aws-sdk/client-apigatewayv2": "3.485.0",
43
+ "@aws-sdk/client-lambda": "3.485.0",
44
+ "@aws-sdk/client-s3": "3.485.0",
45
+ "@aws-sdk/client-secrets-manager": "3.485.0",
46
+ "@aws-sdk/client-ssm": "3.485.0",
47
+ "@aws-sdk/client-sts": "3.485.0",
47
48
  "@fastly/js-compute": "3.7.3",
48
49
  "@google-cloud/functions": "3.0.1",
49
50
  "@google-cloud/secret-manager": "5.0.1",
@@ -62,7 +63,7 @@
62
63
  "fs-extra": "11.2.0",
63
64
  "isomorphic-git": "1.25.2",
64
65
  "openwhisk": "3.21.8",
65
- "rollup": "4.9.2",
66
+ "rollup": "4.9.4",
66
67
  "semver": "7.5.4",
67
68
  "tar": "6.2.0",
68
69
  "webpack": "5.89.0",
@@ -11,6 +11,8 @@
11
11
  */
12
12
  /* eslint-disable no-await-in-loop,no-restricted-syntax */
13
13
  import chalk from 'chalk-template';
14
+ import processQueue from '@adobe/helix-shared-process-queue';
15
+
14
16
  import {
15
17
  DeleteObjectCommand,
16
18
  PutObjectCommand,
@@ -25,9 +27,10 @@ import {
25
27
  import {
26
28
  AddPermissionCommand,
27
29
  CreateAliasCommand,
28
- CreateFunctionCommand, GetAliasCommand,
30
+ CreateFunctionCommand, DeleteAliasCommand, DeleteFunctionCommand, GetAliasCommand,
29
31
  GetFunctionCommand,
30
- LambdaClient, PublishVersionCommand, UpdateAliasCommand, UpdateFunctionCodeCommand,
32
+ LambdaClient, ListAliasesCommand, ListVersionsByFunctionCommand,
33
+ PublishVersionCommand, UpdateAliasCommand, UpdateFunctionCodeCommand,
31
34
  UpdateFunctionConfigurationCommand,
32
35
  } from '@aws-sdk/client-lambda';
33
36
 
@@ -408,6 +411,34 @@ export default class AWSDeployer extends BaseDeployer {
408
411
  return authorizers;
409
412
  }
410
413
 
414
+ async listAliases(functionName) {
415
+ let nextMarker;
416
+ const aliases = [];
417
+ do {
418
+ const res = await this._lambda.send(new ListAliasesCommand({
419
+ FunctionName: functionName,
420
+ Marker: nextMarker,
421
+ }));
422
+ aliases.push(...res.Aliases);
423
+ nextMarker = res.NextMarker;
424
+ } while (nextMarker);
425
+ return aliases;
426
+ }
427
+
428
+ async listVersions(functionName) {
429
+ let nextMarker;
430
+ const versions = [];
431
+ do {
432
+ const res = await this._lambda.send(new ListVersionsByFunctionCommand({
433
+ FunctionName: functionName,
434
+ Marker: nextMarker,
435
+ }));
436
+ versions.push(...res.Versions);
437
+ nextMarker = res.NextMarker;
438
+ } while (nextMarker);
439
+ return versions;
440
+ }
441
+
411
442
  async createAPI() {
412
443
  const { cfg } = this;
413
444
  const { ApiId, ApiEndpoint } = await this.initApiId();
@@ -546,6 +577,63 @@ export default class AWSDeployer extends BaseDeployer {
546
577
  this.log.info(chalk`{green ok}: parameters updated.`);
547
578
  }
548
579
 
580
+ async cleanup() {
581
+ const { cfg, functionName } = this;
582
+ const cleanupMatchers = [{
583
+ name: 'CI',
584
+ property: 'cleanupCiAge',
585
+ match: (alias) => alias.match(/^ci(\d+)$/),
586
+ }, {
587
+ name: 'patch',
588
+ property: 'cleanupPatchAge',
589
+ match: (alias) => alias.match(/^(\d+)_(\d+)_(\d+)(-test)?$/),
590
+ }];
591
+
592
+ try {
593
+ this.log.info('Clean up old aliases and versions');
594
+ this.log.info(chalk`--: fetching aliases...`);
595
+ const aliases = await this.listAliases(functionName);
596
+ this.log.info(chalk`--: fetching versions...`);
597
+ const versions = (await this.listVersions(functionName))
598
+ .map((version) => ({
599
+ ...version,
600
+ Aliases: aliases
601
+ .filter(({ FunctionVersion }) => version.Version === FunctionVersion)
602
+ .map(({ Name }) => Name),
603
+ }));
604
+
605
+ for (const { name, property, match } of cleanupMatchers) {
606
+ if (cfg[property]) {
607
+ const cleanupBefore = Date.now() - (cfg[property] * 1000);
608
+ const oldVersions = versions
609
+ .filter(({ Aliases }) => Aliases.length > 0 && Aliases.every((alias) => match(alias)))
610
+ .filter(({ LastModified }) => Date.parse(LastModified) < cleanupBefore);
611
+ this.log.info(`Found ${oldVersions.length} old ${name} versions`);
612
+
613
+ if (oldVersions.length) {
614
+ this.log.info(chalk`--: deleting their aliases and versions...`);
615
+ const deleted = await processQueue(oldVersions, async ({ Aliases, Version }) => {
616
+ await Promise.all(Aliases.map(async (Name) => {
617
+ await this._lambda.send(new DeleteAliasCommand({
618
+ FunctionName: functionName,
619
+ Name,
620
+ }));
621
+ }));
622
+ await this._lambda.send(new DeleteFunctionCommand({
623
+ FunctionName: functionName,
624
+ Qualifier: Version,
625
+ }));
626
+ return Version;
627
+ }, 2);
628
+ this.log.info(chalk`{green ok}: deleted ${deleted.length} old ${name} versions.`);
629
+ }
630
+ }
631
+ }
632
+ } catch (e) {
633
+ this.log.error(chalk`{red error:} Cleanup failed, proceeding anyway.`, e);
634
+ }
635
+ }
636
+
549
637
  async cleanUpIntegrations(filter) {
550
638
  this.log.info('Clean up Integrations');
551
639
  const { ApiId } = await this.initApiId();