@actions/artifact 1.1.2 → 2.0.0

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.
Files changed (125) hide show
  1. package/README.md +111 -174
  2. package/lib/artifact.d.ts +6 -0
  3. package/lib/artifact.js +23 -0
  4. package/lib/artifact.js.map +1 -0
  5. package/lib/generated/google/protobuf/timestamp.d.ts +145 -0
  6. package/lib/generated/google/protobuf/timestamp.js +136 -0
  7. package/lib/generated/google/protobuf/timestamp.js.map +1 -0
  8. package/lib/generated/google/protobuf/wrappers.d.ts +307 -0
  9. package/lib/generated/google/protobuf/wrappers.js +609 -0
  10. package/lib/generated/google/protobuf/wrappers.js.map +1 -0
  11. package/lib/generated/index.d.ts +4 -0
  12. package/lib/generated/index.js +21 -0
  13. package/lib/generated/index.js.map +1 -0
  14. package/lib/generated/results/api/v1/artifact.d.ts +286 -0
  15. package/lib/generated/results/api/v1/artifact.js +588 -0
  16. package/lib/generated/results/api/v1/artifact.js.map +1 -0
  17. package/lib/generated/results/api/v1/artifact.twirp.d.ts +43 -0
  18. package/lib/generated/results/api/v1/artifact.twirp.js +416 -0
  19. package/lib/generated/results/api/v1/artifact.twirp.js.map +1 -0
  20. package/lib/internal/client.d.ts +61 -0
  21. package/lib/internal/client.js +121 -0
  22. package/lib/internal/client.js.map +1 -0
  23. package/lib/internal/download/download-artifact.d.ts +3 -0
  24. package/lib/internal/download/download-artifact.js +168 -0
  25. package/lib/internal/download/download-artifact.js.map +1 -0
  26. package/lib/internal/find/get-artifact.d.ts +3 -0
  27. package/lib/internal/find/get-artifact.js +118 -0
  28. package/lib/internal/find/get-artifact.js.map +1 -0
  29. package/lib/internal/find/list-artifacts.d.ts +3 -0
  30. package/lib/internal/find/list-artifacts.js +139 -0
  31. package/lib/internal/find/list-artifacts.js.map +1 -0
  32. package/lib/internal/find/retry-options.d.ts +7 -0
  33. package/lib/internal/find/retry-options.js +50 -0
  34. package/lib/internal/find/retry-options.js.map +1 -0
  35. package/lib/internal/shared/artifact-twirp-client.d.ts +6 -0
  36. package/lib/internal/shared/artifact-twirp-client.js +153 -0
  37. package/lib/internal/shared/artifact-twirp-client.js.map +1 -0
  38. package/lib/internal/shared/config.d.ts +6 -0
  39. package/lib/internal/shared/config.js +55 -0
  40. package/lib/internal/shared/config.js.map +1 -0
  41. package/lib/internal/shared/errors.d.ts +22 -0
  42. package/lib/internal/shared/errors.js +70 -0
  43. package/lib/internal/shared/errors.js.map +1 -0
  44. package/lib/internal/shared/interfaces.d.ts +136 -0
  45. package/lib/internal/{contracts.js → shared/interfaces.js} +1 -1
  46. package/lib/internal/shared/interfaces.js.map +1 -0
  47. package/lib/internal/shared/user-agent.d.ts +4 -0
  48. package/lib/internal/shared/user-agent.js +13 -0
  49. package/lib/internal/shared/user-agent.js.map +1 -0
  50. package/lib/internal/shared/util.d.ts +5 -0
  51. package/lib/internal/shared/util.js +81 -0
  52. package/lib/internal/shared/util.js.map +1 -0
  53. package/lib/internal/upload/blob-upload.d.ts +12 -0
  54. package/lib/internal/upload/blob-upload.js +87 -0
  55. package/lib/internal/upload/blob-upload.js.map +1 -0
  56. package/lib/internal/upload/path-and-artifact-name-validation.d.ts +8 -0
  57. package/lib/internal/{path-and-artifact-name-validation.js → upload/path-and-artifact-name-validation.js} +11 -11
  58. package/lib/internal/upload/path-and-artifact-name-validation.js.map +1 -0
  59. package/lib/internal/upload/retention.d.ts +2 -0
  60. package/lib/internal/upload/retention.js +54 -0
  61. package/lib/internal/upload/retention.js.map +1 -0
  62. package/lib/internal/upload/upload-artifact.d.ts +2 -0
  63. package/lib/internal/upload/upload-artifact.js +103 -0
  64. package/lib/internal/upload/upload-artifact.js.map +1 -0
  65. package/lib/internal/upload/upload-zip-specification.d.ts +21 -0
  66. package/lib/internal/{upload-specification.js → upload/upload-zip-specification.js} +44 -36
  67. package/lib/internal/upload/upload-zip-specification.js.map +1 -0
  68. package/lib/internal/upload/zip.d.ts +9 -0
  69. package/lib/internal/upload/zip.js +113 -0
  70. package/lib/internal/upload/zip.js.map +1 -0
  71. package/package.json +25 -11
  72. package/lib/artifact-client.d.ts +0 -10
  73. package/lib/artifact-client.js +0 -12
  74. package/lib/artifact-client.js.map +0 -1
  75. package/lib/internal/artifact-client.d.ts +0 -41
  76. package/lib/internal/artifact-client.js +0 -182
  77. package/lib/internal/artifact-client.js.map +0 -1
  78. package/lib/internal/config-variables.d.ts +0 -12
  79. package/lib/internal/config-variables.js +0 -77
  80. package/lib/internal/config-variables.js.map +0 -1
  81. package/lib/internal/contracts.d.ts +0 -67
  82. package/lib/internal/contracts.js.map +0 -1
  83. package/lib/internal/crc64.d.ts +0 -21
  84. package/lib/internal/crc64.js +0 -303
  85. package/lib/internal/crc64.js.map +0 -1
  86. package/lib/internal/download-http-client.d.ts +0 -39
  87. package/lib/internal/download-http-client.js +0 -296
  88. package/lib/internal/download-http-client.js.map +0 -1
  89. package/lib/internal/download-options.d.ts +0 -7
  90. package/lib/internal/download-options.js +0 -3
  91. package/lib/internal/download-options.js.map +0 -1
  92. package/lib/internal/download-response.d.ts +0 -10
  93. package/lib/internal/download-response.js +0 -3
  94. package/lib/internal/download-response.js.map +0 -1
  95. package/lib/internal/download-specification.d.ts +0 -19
  96. package/lib/internal/download-specification.js +0 -78
  97. package/lib/internal/download-specification.js.map +0 -1
  98. package/lib/internal/http-manager.d.ts +0 -12
  99. package/lib/internal/http-manager.js +0 -32
  100. package/lib/internal/http-manager.js.map +0 -1
  101. package/lib/internal/path-and-artifact-name-validation.d.ts +0 -8
  102. package/lib/internal/path-and-artifact-name-validation.js.map +0 -1
  103. package/lib/internal/requestUtils.d.ts +0 -3
  104. package/lib/internal/requestUtils.js +0 -92
  105. package/lib/internal/requestUtils.js.map +0 -1
  106. package/lib/internal/status-reporter.d.ts +0 -21
  107. package/lib/internal/status-reporter.js +0 -52
  108. package/lib/internal/status-reporter.js.map +0 -1
  109. package/lib/internal/upload-gzip.d.ts +0 -14
  110. package/lib/internal/upload-gzip.js +0 -147
  111. package/lib/internal/upload-gzip.js.map +0 -1
  112. package/lib/internal/upload-http-client.d.ts +0 -48
  113. package/lib/internal/upload-http-client.js +0 -415
  114. package/lib/internal/upload-http-client.js.map +0 -1
  115. package/lib/internal/upload-options.d.ts +0 -34
  116. package/lib/internal/upload-options.js +0 -3
  117. package/lib/internal/upload-options.js.map +0 -1
  118. package/lib/internal/upload-response.d.ts +0 -19
  119. package/lib/internal/upload-response.js +0 -3
  120. package/lib/internal/upload-response.js.map +0 -1
  121. package/lib/internal/upload-specification.d.ts +0 -11
  122. package/lib/internal/upload-specification.js.map +0 -1
  123. package/lib/internal/utils.d.ts +0 -71
  124. package/lib/internal/utils.js +0 -292
  125. package/lib/internal/utils.js.map +0 -1
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.uploadZipToBlobStorage = void 0;
36
+ const storage_blob_1 = require("@azure/storage-blob");
37
+ const config_1 = require("../shared/config");
38
+ const core = __importStar(require("@actions/core"));
39
+ const crypto = __importStar(require("crypto"));
40
+ const stream = __importStar(require("stream"));
41
+ const errors_1 = require("../shared/errors");
42
+ function uploadZipToBlobStorage(authenticatedUploadURL, zipUploadStream) {
43
+ return __awaiter(this, void 0, void 0, function* () {
44
+ let uploadByteCount = 0;
45
+ const maxConcurrency = (0, config_1.getConcurrency)();
46
+ const bufferSize = (0, config_1.getUploadChunkSize)();
47
+ const blobClient = new storage_blob_1.BlobClient(authenticatedUploadURL);
48
+ const blockBlobClient = blobClient.getBlockBlobClient();
49
+ core.debug(`Uploading artifact zip to blob storage with maxConcurrency: ${maxConcurrency}, bufferSize: ${bufferSize}`);
50
+ const uploadCallback = (progress) => {
51
+ core.info(`Uploaded bytes ${progress.loadedBytes}`);
52
+ uploadByteCount = progress.loadedBytes;
53
+ };
54
+ const options = {
55
+ blobHTTPHeaders: { blobContentType: 'zip' },
56
+ onProgress: uploadCallback
57
+ };
58
+ let sha256Hash = undefined;
59
+ const uploadStream = new stream.PassThrough();
60
+ const hashStream = crypto.createHash('sha256');
61
+ zipUploadStream.pipe(uploadStream); // This stream is used for the upload
62
+ zipUploadStream.pipe(hashStream).setEncoding('hex'); // This stream is used to compute a hash of the zip content that gets used. Integrity check
63
+ core.info('Beginning upload of artifact content to blob storage');
64
+ try {
65
+ yield blockBlobClient.uploadStream(uploadStream, bufferSize, maxConcurrency, options);
66
+ }
67
+ catch (error) {
68
+ if (errors_1.NetworkError.isNetworkErrorCode(error === null || error === void 0 ? void 0 : error.code)) {
69
+ throw new errors_1.NetworkError(error === null || error === void 0 ? void 0 : error.code);
70
+ }
71
+ throw error;
72
+ }
73
+ core.info('Finished uploading artifact content to blob storage!');
74
+ hashStream.end();
75
+ sha256Hash = hashStream.read();
76
+ core.info(`SHA256 hash of uploaded artifact zip is ${sha256Hash}`);
77
+ if (uploadByteCount === 0) {
78
+ core.warning(`No data was uploaded to blob storage. Reported upload byte count is 0.`);
79
+ }
80
+ return {
81
+ uploadSize: uploadByteCount,
82
+ sha256Hash
83
+ };
84
+ });
85
+ }
86
+ exports.uploadZipToBlobStorage = uploadZipToBlobStorage;
87
+ //# sourceMappingURL=blob-upload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"blob-upload.js","sourceRoot":"","sources":["../../../src/internal/upload/blob-upload.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAA4E;AAG5E,6CAAmE;AACnE,oDAAqC;AACrC,+CAAgC;AAChC,+CAAgC;AAChC,6CAA6C;AAc7C,SAAsB,sBAAsB,CAC1C,sBAA8B,EAC9B,eAAgC;;QAEhC,IAAI,eAAe,GAAG,CAAC,CAAA;QAEvB,MAAM,cAAc,GAAG,IAAA,uBAAc,GAAE,CAAA;QACvC,MAAM,UAAU,GAAG,IAAA,2BAAkB,GAAE,CAAA;QACvC,MAAM,UAAU,GAAG,IAAI,yBAAU,CAAC,sBAAsB,CAAC,CAAA;QACzD,MAAM,eAAe,GAAG,UAAU,CAAC,kBAAkB,EAAE,CAAA;QAEvD,IAAI,CAAC,KAAK,CACR,+DAA+D,cAAc,iBAAiB,UAAU,EAAE,CAC3G,CAAA;QAED,MAAM,cAAc,GAAG,CAAC,QAA+B,EAAQ,EAAE;YAC/D,IAAI,CAAC,IAAI,CAAC,kBAAkB,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAA;YACnD,eAAe,GA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CAAA;AAjED,wDAiEC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Validates the name of the artifact to check to make sure there are no illegal characters
3
+ */
4
+ export declare function validateArtifactName(name: string): void;
5
+ /**
6
+ * Validates file paths to check for any illegal characters that can cause problems on different file systems
7
+ */
8
+ export declare function validateFilePath(path: string): void;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkArtifactFilePath = exports.checkArtifactName = void 0;
3
+ exports.validateFilePath = exports.validateArtifactName = void 0;
4
4
  const core_1 = require("@actions/core");
5
5
  /**
6
6
  * Invalid characters that cannot be in the artifact name or an uploaded file. Will be rejected
@@ -27,15 +27,15 @@ const invalidArtifactNameCharacters = new Map([
27
27
  ['/', ' Forward slash /']
28
28
  ]);
29
29
  /**
30
- * Scans the name of the artifact to make sure there are no illegal characters
30
+ * Validates the name of the artifact to check to make sure there are no illegal characters
31
31
  */
32
- function checkArtifactName(name) {
32
+ function validateArtifactName(name) {
33
33
  if (!name) {
34
- throw new Error(`Artifact name: ${name}, is incorrectly provided`);
34
+ throw new Error(`Provided artifact name input during validation is empty`);
35
35
  }
36
36
  for (const [invalidCharacterKey, errorMessageForCharacter] of invalidArtifactNameCharacters) {
37
37
  if (name.includes(invalidCharacterKey)) {
38
- throw new Error(`Artifact name is not valid: ${name}. Contains the following character: ${errorMessageForCharacter}
38
+ throw new Error(`The artifact name is not valid: ${name}. Contains the following character: ${errorMessageForCharacter}
39
39
 
40
40
  Invalid characters include: ${Array.from(invalidArtifactNameCharacters.values()).toString()}
41
41
 
@@ -44,17 +44,17 @@ These characters are not allowed in the artifact name due to limitations with ce
44
44
  }
45
45
  (0, core_1.info)(`Artifact name is valid!`);
46
46
  }
47
- exports.checkArtifactName = checkArtifactName;
47
+ exports.validateArtifactName = validateArtifactName;
48
48
  /**
49
- * Scans the name of the filePath used to make sure there are no illegal characters
49
+ * Validates file paths to check for any illegal characters that can cause problems on different file systems
50
50
  */
51
- function checkArtifactFilePath(path) {
51
+ function validateFilePath(path) {
52
52
  if (!path) {
53
- throw new Error(`Artifact path: ${path}, is incorrectly provided`);
53
+ throw new Error(`Provided file path input during validation is empty`);
54
54
  }
55
55
  for (const [invalidCharacterKey, errorMessageForCharacter] of invalidArtifactFilePathCharacters) {
56
56
  if (path.includes(invalidCharacterKey)) {
57
- throw new Error(`Artifact path is not valid: ${path}. Contains the following character: ${errorMessageForCharacter}
57
+ throw new Error(`The path for one of the files in artifact is not valid: ${path}. Contains the following character: ${errorMessageForCharacter}
58
58
 
59
59
  Invalid characters include: ${Array.from(invalidArtifactFilePathCharacters.values()).toString()}
60
60
 
@@ -63,5 +63,5 @@ The following characters are not allowed in files that are uploaded due to limit
63
63
  }
64
64
  }
65
65
  }
66
- exports.checkArtifactFilePath = checkArtifactFilePath;
66
+ exports.validateFilePath = validateFilePath;
67
67
  //# sourceMappingURL=path-and-artifact-name-validation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path-and-artifact-name-validation.js","sourceRoot":"","sources":["../../../src/internal/upload/path-and-artifact-name-validation.ts"],"names":[],"mappings":";;;AAAA,wCAAkC;AAElC;;;;;;;GAOG;AACH,MAAM,iCAAiC,GAAG,IAAI,GAAG,CAAiB;IAChE,CAAC,GAAG,EAAE,iBAAiB,CAAC;IACxB,CAAC,GAAG,EAAE,UAAU,CAAC;IACjB,CAAC,GAAG,EAAE,cAAc,CAAC;IACrB,CAAC,GAAG,EAAE,iBAAiB,CAAC;IACxB,CAAC,GAAG,EAAE,iBAAiB,CAAC;IACxB,CAAC,GAAG,EAAE,aAAa,CAAC;IACpB,CAAC,GAAG,EAAE,kBAAkB,CAAC;IACzB,CAAC,IAAI,EAAE,sBAAsB,CAAC;IAC9B,CAAC,IAAI,EAAE,gBAAgB,CAAC;CACzB,CAAC,CAAA;AAEF,MAAM,6BAA6B,GAAG,IAAI,GAAG,CAAiB;IAC5D,GAAG,iCAAiC;IACpC,CAAC,IAAI,EAAE,eAAe,CAAC;IACvB,CAAC,GAAG,EAAE,kBAAkB,CAAC;CAC1B,CAAC,CAAA;AAEF;;GAEG;AACH,SAAgB,oBAAoB,CAAC,IAAY;IAC/C,IAAI,CAAC,IAAI,EAAE;QACT,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC,CAAA;KAC3E;IAED,KAAK,MAAM,CACT,mBAAmB,EACnB,wBAAwB,CACzB,IAAI,6BAA6B,EAAE;QAClC,IAAI,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAC,EAAE;YACtC,MAAM,IAAI,KAAK,CACb,mCAAmC,IAAI,uCAAuC,wBAAwB;;8BAEhF,KAAK,CAAC,IAAI,CAC9B,6BAA6B,CAAC,MAAM,EAAE,CACvC,CAAC,QAAQ,EAAE;;mRAE+P,CAC5Q,CAAA;SACF;KACF;IAED,IAAA,WAAI,EAAC,yBAAyB,CAAC,CAAA;AACjC,CAAC;AAvBD,oDAuBC;AAED;;GAEG;AACH,SAAgB,gBAAgB,CAAC,IAAY;IAC3C,IAAI,CAAC,IAAI,EAAE;QACT,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAA;KACvE;IAED,KAAK,MAAM,CACT,mBAAmB,EACnB,wBAAwB,CACzB,IAAI,iCAAiC,EAAE;QACtC,IAAI,IAAI,CAAC,QAAQ,CAAC,mBAAmB,CAAC,EAAE;YACtC,MAAM,IAAI,KAAK,CACb,2DAA2D,IAAI,uCAAuC,wBAAwB;;8BAExG,KAAK,CAAC,IAAI,CAC9B,iCAAiC,CAAC,MAAM,EAAE,CAC3C,CAAC,QAAQ,EAAE;;;WAGT,CACJ,CAAA;SACF;KACF;AACH,CAAC;AAtBD,4CAsBC"}
@@ -0,0 +1,2 @@
1
+ import { Timestamp } from '../../generated';
2
+ export declare function getExpiration(retentionDays?: number): Timestamp | undefined;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.getExpiration = void 0;
27
+ const generated_1 = require("../../generated");
28
+ const core = __importStar(require("@actions/core"));
29
+ function getExpiration(retentionDays) {
30
+ if (!retentionDays) {
31
+ return undefined;
32
+ }
33
+ const maxRetentionDays = getRetentionDays();
34
+ if (maxRetentionDays && maxRetentionDays < retentionDays) {
35
+ core.warning(`Retention days cannot be greater than the maximum allowed retention set within the repository. Using ${maxRetentionDays} instead.`);
36
+ retentionDays = maxRetentionDays;
37
+ }
38
+ const expirationDate = new Date();
39
+ expirationDate.setDate(expirationDate.getDate() + retentionDays);
40
+ return generated_1.Timestamp.fromDate(expirationDate);
41
+ }
42
+ exports.getExpiration = getExpiration;
43
+ function getRetentionDays() {
44
+ const retentionDays = process.env['GITHUB_RETENTION_DAYS'];
45
+ if (!retentionDays) {
46
+ return undefined;
47
+ }
48
+ const days = parseInt(retentionDays);
49
+ if (isNaN(days)) {
50
+ return undefined;
51
+ }
52
+ return days;
53
+ }
54
+ //# sourceMappingURL=retention.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retention.js","sourceRoot":"","sources":["../../../src/internal/upload/retention.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAyC;AACzC,oDAAqC;AAErC,SAAgB,aAAa,CAAC,aAAsB;IAClD,IAAI,CAAC,aAAa,EAAE;QAClB,OAAO,SAAS,CAAA;KACjB;IAED,MAAM,gBAAgB,GAAG,gBAAgB,EAAE,CAAA;IAC3C,IAAI,gBAAgB,IAAI,gBAAgB,GAAG,aAAa,EAAE;QACxD,IAAI,CAAC,OAAO,CACV,wGAAwG,gBAAgB,WAAW,CACpI,CAAA;QACD,aAAa,GAAG,gBAAgB,CAAA;KACjC;IAED,MAAM,cAAc,GAAG,IAAI,IAAI,EAAE,CAAA;IACjC,cAAc,CAAC,OAAO,CAAC,cAAc,CAAC,OAAO,EAAE,GAAG,aAAa,CAAC,CAAA;IAEhE,OAAO,qBAAS,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAA;AAC3C,CAAC;AAjBD,sCAiBC;AAED,SAAS,gBAAgB;IACvB,MAAM,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAA;IAC1D,IAAI,CAAC,aAAa,EAAE;QAClB,OAAO,SAAS,CAAA;KACjB;IACD,MAAM,IAAI,GAAG,QAAQ,CAAC,aAAa,CAAC,CAAA;IACpC,IAAI,KAAK,CAAC,IAAI,CAAC,EAAE;QACf,OAAO,SAAS,CAAA;KACjB;IAED,OAAO,IAAI,CAAA;AACb,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { UploadArtifactOptions, UploadArtifactResponse } from '../shared/interfaces';
2
+ export declare function uploadArtifact(name: string, files: string[], rootDirectory: string, options?: UploadArtifactOptions | undefined): Promise<UploadArtifactResponse>;
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.uploadArtifact = void 0;
36
+ const core = __importStar(require("@actions/core"));
37
+ const retention_1 = require("./retention");
38
+ const path_and_artifact_name_validation_1 = require("./path-and-artifact-name-validation");
39
+ const artifact_twirp_client_1 = require("../shared/artifact-twirp-client");
40
+ const upload_zip_specification_1 = require("./upload-zip-specification");
41
+ const util_1 = require("../shared/util");
42
+ const blob_upload_1 = require("./blob-upload");
43
+ const zip_1 = require("./zip");
44
+ const generated_1 = require("../../generated");
45
+ const errors_1 = require("../shared/errors");
46
+ function uploadArtifact(name, files, rootDirectory, options) {
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ (0, path_and_artifact_name_validation_1.validateArtifactName)(name);
49
+ (0, upload_zip_specification_1.validateRootDirectory)(rootDirectory);
50
+ const zipSpecification = (0, upload_zip_specification_1.getUploadZipSpecification)(files, rootDirectory);
51
+ if (zipSpecification.length === 0) {
52
+ throw new errors_1.FilesNotFoundError(zipSpecification.flatMap(s => (s.sourcePath ? [s.sourcePath] : [])));
53
+ }
54
+ // get the IDs needed for the artifact creation
55
+ const backendIds = (0, util_1.getBackendIdsFromToken)();
56
+ // create the artifact client
57
+ const artifactClient = (0, artifact_twirp_client_1.internalArtifactTwirpClient)();
58
+ // create the artifact
59
+ const createArtifactReq = {
60
+ workflowRunBackendId: backendIds.workflowRunBackendId,
61
+ workflowJobRunBackendId: backendIds.workflowJobRunBackendId,
62
+ name,
63
+ version: 4
64
+ };
65
+ // if there is a retention period, add it to the request
66
+ const expiresAt = (0, retention_1.getExpiration)(options === null || options === void 0 ? void 0 : options.retentionDays);
67
+ if (expiresAt) {
68
+ createArtifactReq.expiresAt = expiresAt;
69
+ }
70
+ const createArtifactResp = yield artifactClient.CreateArtifact(createArtifactReq);
71
+ if (!createArtifactResp.ok) {
72
+ throw new errors_1.InvalidResponseError('CreateArtifact: response from backend was not ok');
73
+ }
74
+ const zipUploadStream = yield (0, zip_1.createZipUploadStream)(zipSpecification, options === null || options === void 0 ? void 0 : options.compressionLevel);
75
+ // Upload zip to blob storage
76
+ const uploadResult = yield (0, blob_upload_1.uploadZipToBlobStorage)(createArtifactResp.signedUploadUrl, zipUploadStream);
77
+ // finalize the artifact
78
+ const finalizeArtifactReq = {
79
+ workflowRunBackendId: backendIds.workflowRunBackendId,
80
+ workflowJobRunBackendId: backendIds.workflowJobRunBackendId,
81
+ name,
82
+ size: uploadResult.uploadSize ? uploadResult.uploadSize.toString() : '0'
83
+ };
84
+ if (uploadResult.sha256Hash) {
85
+ finalizeArtifactReq.hash = generated_1.StringValue.create({
86
+ value: `sha256:${uploadResult.sha256Hash}`
87
+ });
88
+ }
89
+ core.info(`Finalizing artifact upload`);
90
+ const finalizeArtifactResp = yield artifactClient.FinalizeArtifact(finalizeArtifactReq);
91
+ if (!finalizeArtifactResp.ok) {
92
+ throw new errors_1.InvalidResponseError('FinalizeArtifact: response from backend was not ok');
93
+ }
94
+ const artifactId = BigInt(finalizeArtifactResp.artifactId);
95
+ core.info(`Artifact ${name}.zip successfully finalized. Artifact ID ${artifactId}`);
96
+ return {
97
+ size: uploadResult.uploadSize,
98
+ id: Number(artifactId)
99
+ };
100
+ });
101
+ }
102
+ exports.uploadArtifact = uploadArtifact;
103
+ //# sourceMappingURL=upload-artifact.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upload-artifact.js","sourceRoot":"","sources":["../../../src/internal/upload/upload-artifact.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAqC;AAKrC,2CAAyC;AACzC,2FAAwE;AACxE,2EAA2E;AAC3E,yEAImC;AACnC,yCAAqD;AACrD,+CAAoD;AACpD,+BAA2C;AAC3C,+CAIwB;AACxB,6CAAyE;AAEzE,SAAsB,cAAc,CAClC,IAAY,EACZ,KAAe,EACf,aAAqB,EACrB,OAA2C;;QAE3C,IAAA,wDAAoB,EAAC,IAAI,CAAC,CAAA;QAC1B,IAAA,gDAAqB,EAAC,aAAa,CAAC,CAAA;QAEpC,MAAM,gBAAgB,GAA6B,IAAA,oDAAyB,EAC1E,KAAK,EACL,aAAa,CACd,CAAA;QACD,IAAI,gBAAgB,CAAC,MAAM,KAAK,CAAC,EAAE;YACjC,MAAM,IAAI,2BAAkB,CAC1B,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CACpE,CAAA;SACF;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GAAG,uBAAW,CAAC,MAAM,CAAC;gBAC5C,KAAK,EAAE,UAAU,YAAY,CAAC,UAAU,EAAE;aAC3C,CAAC,CAAA;SACH;QAED,IAAI,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAA;QAEvC,MAAM,oBAAoB,GACxB,MAAM,cAAc,CAAC,gBAAgB,CAAC,mBAAmB,CAAC,CAAA;QAC5D,IAAI,CAAC,oBAAoB,CAAC,EAAE,EAAE;YAC5B,MAAM,IAAI,6BAAoB,CAC5B,oDAAoD,CACrD,CAAA;SACF;QAED,MAAM,UAAU,GAAG,MAAM,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAA;QAC1D,IAAI,CAAC,IAAI,CACP,YAAY,IAAI,4CAA4C,UAAU,EAAE,CACzE,CAAA;QAED,OAAO;YACL,IAAI,EAAE,YAAY,CAAC,UAAU;YAC7B,EAAE,EAAE,MAAM,CAAC,UAAU,CAAC;SACvB,CAAA;IACH,CAAC;CAAA;AA3FD,wCA2FC"}
@@ -0,0 +1,21 @@
1
+ export interface UploadZipSpecification {
2
+ /**
3
+ * An absolute source path that points to a file that will be added to a zip. Null if creating a new directory
4
+ */
5
+ sourcePath: string | null;
6
+ /**
7
+ * The destination path in a zip for a file
8
+ */
9
+ destinationPath: string;
10
+ }
11
+ /**
12
+ * Checks if a root directory exists and is valid
13
+ * @param rootDirectory an absolute root directory path common to all input files that that will be trimmed from the final zip structure
14
+ */
15
+ export declare function validateRootDirectory(rootDirectory: string): void;
16
+ /**
17
+ * Creates a specification that describes how a zip file will be created for a set of input files
18
+ * @param filesToZip a list of file that should be included in the zip
19
+ * @param rootDirectory an absolute root directory path common to all input files that that will be trimmed from the final zip structure
20
+ */
21
+ export declare function getUploadZipSpecification(filesToZip: string[], rootDirectory: string): UploadZipSpecification[];
@@ -23,34 +23,39 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.getUploadSpecification = void 0;
26
+ exports.getUploadZipSpecification = exports.validateRootDirectory = void 0;
27
27
  const fs = __importStar(require("fs"));
28
28
  const core_1 = require("@actions/core");
29
29
  const path_1 = require("path");
30
30
  const path_and_artifact_name_validation_1 = require("./path-and-artifact-name-validation");
31
31
  /**
32
- * Creates a specification that describes how each file that is part of the artifact will be uploaded
33
- * @param artifactName the name of the artifact being uploaded. Used during upload to denote where the artifact is stored on the server
34
- * @param rootDirectory an absolute file path that denotes the path that should be removed from the beginning of each artifact file
35
- * @param artifactFiles a list of absolute file paths that denote what should be uploaded as part of the artifact
32
+ * Checks if a root directory exists and is valid
33
+ * @param rootDirectory an absolute root directory path common to all input files that that will be trimmed from the final zip structure
36
34
  */
37
- function getUploadSpecification(artifactName, rootDirectory, artifactFiles) {
38
- // artifact name was checked earlier on, no need to check again
39
- const specifications = [];
35
+ function validateRootDirectory(rootDirectory) {
40
36
  if (!fs.existsSync(rootDirectory)) {
41
- throw new Error(`Provided rootDirectory ${rootDirectory} does not exist`);
37
+ throw new Error(`The provided rootDirectory ${rootDirectory} does not exist`);
42
38
  }
43
39
  if (!fs.statSync(rootDirectory).isDirectory()) {
44
- throw new Error(`Provided rootDirectory ${rootDirectory} is not a valid directory`);
40
+ throw new Error(`The provided rootDirectory ${rootDirectory} is not a valid directory`);
45
41
  }
42
+ (0, core_1.info)(`Root directory input is valid!`);
43
+ }
44
+ exports.validateRootDirectory = validateRootDirectory;
45
+ /**
46
+ * Creates a specification that describes how a zip file will be created for a set of input files
47
+ * @param filesToZip a list of file that should be included in the zip
48
+ * @param rootDirectory an absolute root directory path common to all input files that that will be trimmed from the final zip structure
49
+ */
50
+ function getUploadZipSpecification(filesToZip, rootDirectory) {
51
+ const specification = [];
46
52
  // Normalize and resolve, this allows for either absolute or relative paths to be used
47
53
  rootDirectory = (0, path_1.normalize)(rootDirectory);
48
54
  rootDirectory = (0, path_1.resolve)(rootDirectory);
49
55
  /*
50
- Example to demonstrate behavior
56
+ Example
51
57
 
52
58
  Input:
53
- artifactName: my-artifact
54
59
  rootDirectory: '/home/user/files/plz-upload'
55
60
  artifactFiles: [
56
61
  '/home/user/files/plz-upload/file1.txt',
@@ -60,12 +65,20 @@ function getUploadSpecification(artifactName, rootDirectory, artifactFiles) {
60
65
 
61
66
  Output:
62
67
  specifications: [
63
- ['/home/user/files/plz-upload/file1.txt', 'my-artifact/file1.txt'],
64
- ['/home/user/files/plz-upload/file1.txt', 'my-artifact/file2.txt'],
65
- ['/home/user/files/plz-upload/file1.txt', 'my-artifact/dir/file3.txt']
68
+ ['/home/user/files/plz-upload/file1.txt', '/file1.txt'],
69
+ ['/home/user/files/plz-upload/file1.txt', '/file2.txt'],
70
+ ['/home/user/files/plz-upload/file1.txt', '/dir/file3.txt']
66
71
  ]
72
+
73
+ The final zip that is later uploaded will look like this:
74
+
75
+ my-artifact.zip
76
+ - file.txt
77
+ - file2.txt
78
+ - dir/
79
+ - file3.txt
67
80
  */
68
- for (let file of artifactFiles) {
81
+ for (let file of filesToZip) {
69
82
  if (!fs.existsSync(file)) {
70
83
  throw new Error(`File ${file} does not exist`);
71
84
  }
@@ -76,30 +89,25 @@ function getUploadSpecification(artifactName, rootDirectory, artifactFiles) {
76
89
  if (!file.startsWith(rootDirectory)) {
77
90
  throw new Error(`The rootDirectory: ${rootDirectory} is not a parent directory of the file: ${file}`);
78
91
  }
79
- // Check for forbidden characters in file paths that will be rejected during upload
92
+ // Check for forbidden characters in file paths that may cause ambiguous behavior if downloaded on different file systems
80
93
  const uploadPath = file.replace(rootDirectory, '');
81
- (0, path_and_artifact_name_validation_1.checkArtifactFilePath)(uploadPath);
82
- /*
83
- uploadFilePath denotes where the file will be uploaded in the file container on the server. During a run, if multiple artifacts are uploaded, they will all
84
- be saved in the same container. The artifact name is used as the root directory in the container to separate and distinguish uploaded artifacts
85
-
86
- path.join handles all the following cases and would return 'artifact-name/file-to-upload.txt
87
- join('artifact-name/', 'file-to-upload.txt')
88
- join('artifact-name/', '/file-to-upload.txt')
89
- join('artifact-name', 'file-to-upload.txt')
90
- join('artifact-name', '/file-to-upload.txt')
91
- */
92
- specifications.push({
93
- absoluteFilePath: file,
94
- uploadFilePath: (0, path_1.join)(artifactName, uploadPath)
94
+ (0, path_and_artifact_name_validation_1.validateFilePath)(uploadPath);
95
+ specification.push({
96
+ sourcePath: file,
97
+ destinationPath: uploadPath
95
98
  });
96
99
  }
97
100
  else {
98
- // Directories are rejected by the server during upload
99
- (0, core_1.debug)(`Removing ${file} from rawSearchResults because it is a directory`);
101
+ // Empty directory
102
+ const directoryPath = file.replace(rootDirectory, '');
103
+ (0, path_and_artifact_name_validation_1.validateFilePath)(directoryPath);
104
+ specification.push({
105
+ sourcePath: null,
106
+ destinationPath: directoryPath
107
+ });
100
108
  }
101
109
  }
102
- return specifications;
110
+ return specification;
103
111
  }
104
- exports.getUploadSpecification = getUploadSpecification;
105
- //# sourceMappingURL=upload-specification.js.map
112
+ exports.getUploadZipSpecification = getUploadZipSpecification;
113
+ //# sourceMappingURL=upload-zip-specification.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upload-zip-specification.js","sourceRoot":"","sources":["../../../src/internal/upload/upload-zip-specification.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAwB;AACxB,wCAAkC;AAClC,+BAAuC;AACvC,2FAAoE;AAcpE;;;GAGG;AACH,SAAgB,qBAAqB,CAAC,aAAqB;IACzD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC,EAAE;QACjC,MAAM,IAAI,KAAK,CACb,8BAA8B,aAAa,iBAAiB,CAC7D,CAAA;KACF;IACD,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,WAAW,EAAE,EAAE;QAC7C,MAAM,IAAI,KAAK,CACb,8BAA8B,aAAa,2BAA2B,CACvE,CAAA;KACF;IACD,IAAA,WAAI,EAAC,gCAAgC,CAAC,CAAA;AACxC,CAAC;AAZD,sDAYC;AAED;;;;GA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aAAa;aAC/B,CAAC,CAAA;SACH;KACF;IACD,OAAO,aAAa,CAAA;AACtB,CAAC;AAtED,8DAsEC"}
@@ -0,0 +1,9 @@
1
+ /// <reference types="node" />
2
+ import * as stream from 'stream';
3
+ import { UploadZipSpecification } from './upload-zip-specification';
4
+ export declare const DEFAULT_COMPRESSION_LEVEL = 6;
5
+ export declare class ZipUploadStream extends stream.Transform {
6
+ constructor(bufferSize: number);
7
+ _transform(chunk: any, enc: any, cb: any): void;
8
+ }
9
+ export declare function createZipUploadStream(uploadSpecification: UploadZipSpecification[], compressionLevel?: number): Promise<ZipUploadStream>;
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.createZipUploadStream = exports.ZipUploadStream = exports.DEFAULT_COMPRESSION_LEVEL = void 0;
36
+ const stream = __importStar(require("stream"));
37
+ const archiver = __importStar(require("archiver"));
38
+ const core = __importStar(require("@actions/core"));
39
+ const fs_1 = require("fs");
40
+ const config_1 = require("../shared/config");
41
+ exports.DEFAULT_COMPRESSION_LEVEL = 6;
42
+ // Custom stream transformer so we can set the highWaterMark property
43
+ // See https://github.com/nodejs/node/issues/8855
44
+ class ZipUploadStream extends stream.Transform {
45
+ constructor(bufferSize) {
46
+ super({
47
+ highWaterMark: bufferSize
48
+ });
49
+ }
50
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
51
+ _transform(chunk, enc, cb) {
52
+ cb(null, chunk);
53
+ }
54
+ }
55
+ exports.ZipUploadStream = ZipUploadStream;
56
+ function createZipUploadStream(uploadSpecification, compressionLevel = exports.DEFAULT_COMPRESSION_LEVEL) {
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ core.debug(`Creating Artifact archive with compressionLevel: ${compressionLevel}`);
59
+ const zip = archiver.create('zip', {
60
+ highWaterMark: (0, config_1.getUploadChunkSize)(),
61
+ zlib: { level: compressionLevel }
62
+ });
63
+ // register callbacks for various events during the zip lifecycle
64
+ zip.on('error', zipErrorCallback);
65
+ zip.on('warning', zipWarningCallback);
66
+ zip.on('finish', zipFinishCallback);
67
+ zip.on('end', zipEndCallback);
68
+ for (const file of uploadSpecification) {
69
+ if (file.sourcePath !== null) {
70
+ // Add a normal file to the zip
71
+ zip.append((0, fs_1.createReadStream)(file.sourcePath), {
72
+ name: file.destinationPath
73
+ });
74
+ }
75
+ else {
76
+ // Add a directory to the zip
77
+ zip.append('', { name: file.destinationPath });
78
+ }
79
+ }
80
+ const bufferSize = (0, config_1.getUploadChunkSize)();
81
+ const zipUploadStream = new ZipUploadStream(bufferSize);
82
+ core.debug(`Zip write high watermark value ${zipUploadStream.writableHighWaterMark}`);
83
+ core.debug(`Zip read high watermark value ${zipUploadStream.readableHighWaterMark}`);
84
+ zip.pipe(zipUploadStream);
85
+ zip.finalize();
86
+ return zipUploadStream;
87
+ });
88
+ }
89
+ exports.createZipUploadStream = createZipUploadStream;
90
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
91
+ const zipErrorCallback = (error) => {
92
+ core.error('An error has occurred while creating the zip file for upload');
93
+ core.info(error);
94
+ throw new Error('An error has occurred during zip creation for the artifact');
95
+ };
96
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
97
+ const zipWarningCallback = (error) => {
98
+ if (error.code === 'ENOENT') {
99
+ core.warning('ENOENT warning during artifact zip creation. No such file or directory');
100
+ core.info(error);
101
+ }
102
+ else {
103
+ core.warning(`A non-blocking warning has occurred during artifact zip creation: ${error.code}`);
104
+ core.info(error);
105
+ }
106
+ };
107
+ const zipFinishCallback = () => {
108
+ core.debug('Zip stream for upload has finished.');
109
+ };
110
+ const zipEndCallback = () => {
111
+ core.debug('Zip stream for upload has ended.');
112
+ };
113
+ //# sourceMappingURL=zip.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zip.js","sourceRoot":"","sources":["../../../src/internal/upload/zip.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAgC;AAChC,mDAAoC;AACpC,oDAAqC;AACrC,2BAAmC;AAEnC,6CAAmD;AAEtC,QAAA,yBAAyB,GAAG,CAAC,CAAA;AAE1C,qEAAqE;AACrE,iDAAiD;AACjD,MAAa,eAAgB,SAAQ,MAAM,CAAC,SAAS;IACnD,YAAY,UAAkB;QAC5B,KAAK,CAAC;YACJ,aAAa,EAAE,UAAU;SAC1B,CAAC,CAAA;IACJ,CA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