consume latest @actions/toolkit (#461)

This commit is contained in:
Rob Herley 2023-12-07 14:53:07 -05:00 committed by GitHub
parent 500e175644
commit eba2a242da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 115 additions and 154 deletions

229
dist/index.js vendored

@ -3153,16 +3153,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.create = void 0;
const client_1 = __nccwpck_require__(23955);
/**
* Exported functionality that we want to expose for any users of @actions/artifact
*/
__exportStar(__nccwpck_require__(2538), exports);
function create() {
return client_1.Client.create();
}
exports.create = create;
__exportStar(__nccwpck_require__(69398), exports);
__exportStar(__nccwpck_require__(23955), exports);
const client = new client_1.DefaultArtifactClient();
exports["default"] = client;
//# sourceMappingURL=artifact.js.map
/***/ }),
@ -4998,32 +4994,24 @@ var __rest = (this && this.__rest) || function (s, e) {
return t;
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.Client = void 0;
exports.DefaultArtifactClient = void 0;
const core_1 = __nccwpck_require__(66526);
const config_1 = __nccwpck_require__(95042);
const upload_artifact_1 = __nccwpck_require__(86278);
const download_artifact_1 = __nccwpck_require__(17306);
const get_artifact_1 = __nccwpck_require__(56218);
const list_artifacts_1 = __nccwpck_require__(64033);
class Client {
/**
* Constructs a Client
*/
static create() {
return new Client();
}
/**
* Upload Artifact
const errors_1 = __nccwpck_require__(69398);
/**
* The default artifact client that is used by the artifact action(s).
*/
class DefaultArtifactClient {
uploadArtifact(name, files, rootDirectory, options) {
return __awaiter(this, void 0, void 0, function* () {
if ((0, config_1.isGhes)()) {
(0, core_1.warning)(`@actions/artifact v2.0.0+ and upload-artifact@v4+ are not currently supported on GHES.`);
return {
success: false
};
}
try {
if ((0, config_1.isGhes)()) {
throw new errors_1.GHESNotSupportedError();
}
return (0, upload_artifact_1.uploadArtifact)(name, files, rootDirectory, options);
}
catch (error) {
@ -5032,24 +5020,16 @@ class Client {
Errors can be temporary, so please try again and optionally run the action with debug mode enabled for more information.
If the error persists, please check whether Actions is operating normally at [https://githubstatus.com](https://www.githubstatus.com).`);
return {
success: false
};
throw error;
}
});
}
/**
* Download Artifact
*/
downloadArtifact(artifactId, options) {
return __awaiter(this, void 0, void 0, function* () {
if ((0, config_1.isGhes)()) {
(0, core_1.warning)(`@actions/artifact v2.0.0+ and download-artifact@v4+ are not currently supported on GHES.`);
return {
success: false
};
}
try {
if ((0, config_1.isGhes)()) {
throw new errors_1.GHESNotSupportedError();
}
if (options === null || options === void 0 ? void 0 : options.findBy) {
const { findBy: { repositoryOwner, repositoryName, token } } = options, downloadOptions = __rest(options, ["findBy"]);
return (0, download_artifact_1.downloadArtifactPublic)(artifactId, repositoryOwner, repositoryName, token, downloadOptions);
@ -5057,29 +5037,21 @@ If the error persists, please check whether Actions is operating normally at [ht
return (0, download_artifact_1.downloadArtifactInternal)(artifactId, options);
}
catch (error) {
(0, core_1.warning)(`Artifact download failed with error: ${error}.
(0, core_1.warning)(`Download Artifact failed with error: ${error}.
Errors can be temporary, so please try again and optionally run the action with debug mode enabled for more information.
If the error persists, please check whether Actions and API requests are operating normally at [https://githubstatus.com](https://www.githubstatus.com).`);
return {
success: false
};
throw error;
}
});
}
/**
* List Artifacts
*/
listArtifacts(options) {
return __awaiter(this, void 0, void 0, function* () {
if ((0, config_1.isGhes)()) {
(0, core_1.warning)(`@actions/artifact v2.0.0+ and download-artifact@v4+ are not currently supported on GHES.`);
return {
artifacts: []
};
}
try {
if ((0, config_1.isGhes)()) {
throw new errors_1.GHESNotSupportedError();
}
if (options === null || options === void 0 ? void 0 : options.findBy) {
const { findBy: { workflowRunId, repositoryOwner, repositoryName, token } } = options;
return (0, list_artifacts_1.listArtifactsPublic)(workflowRunId, repositoryOwner, repositoryName, token, options === null || options === void 0 ? void 0 : options.latest);
@ -5092,24 +5064,16 @@ If the error persists, please check whether Actions and API requests are operati
Errors can be temporary, so please try again and optionally run the action with debug mode enabled for more information.
If the error persists, please check whether Actions and API requests are operating normally at [https://githubstatus.com](https://www.githubstatus.com).`);
return {
artifacts: []
};
throw error;
}
});
}
/**
* Get Artifact
*/
getArtifact(artifactName, options) {
return __awaiter(this, void 0, void 0, function* () {
if ((0, config_1.isGhes)()) {
(0, core_1.warning)(`@actions/artifact v2.0.0+ and download-artifact@v4+ are not currently supported on GHES.`);
return {
success: false
};
}
try {
if ((0, config_1.isGhes)()) {
throw new errors_1.GHESNotSupportedError();
}
if (options === null || options === void 0 ? void 0 : options.findBy) {
const { findBy: { workflowRunId, repositoryOwner, repositoryName, token } } = options;
return (0, get_artifact_1.getArtifactPublic)(artifactName, workflowRunId, repositoryOwner, repositoryName, token);
@ -5117,19 +5081,17 @@ If the error persists, please check whether Actions and API requests are operati
return (0, get_artifact_1.getArtifactInternal)(artifactName);
}
catch (error) {
(0, core_1.warning)(`Fetching Artifact failed with error: ${error}.
(0, core_1.warning)(`Get Artifact failed with error: ${error}.
Errors can be temporary, so please try again and optionally run the action with debug mode enabled for more information.
If the error persists, please check whether Actions and API requests are operating normally at [https://githubstatus.com](https://www.githubstatus.com).`);
return {
success: false
};
throw error;
}
});
}
}
exports.Client = Client;
exports.DefaultArtifactClient = DefaultArtifactClient;
//# sourceMappingURL=client.js.map
/***/ }),
@ -5186,6 +5148,7 @@ const config_1 = __nccwpck_require__(95042);
const artifact_twirp_client_1 = __nccwpck_require__(63550);
const generated_1 = __nccwpck_require__(90265);
const util_1 = __nccwpck_require__(80565);
const errors_1 = __nccwpck_require__(69398);
const scrubQueryParameters = (url) => {
const parsed = new URL(url);
parsed.search = '';
@ -5247,7 +5210,7 @@ function downloadArtifactPublic(artifactId, repositoryOwner, repositoryName, tok
catch (error) {
throw new Error(`Unable to download and extract artifact: ${error.message}`);
}
return { success: true, downloadPath };
return { downloadPath };
});
}
exports.downloadArtifactPublic = downloadArtifactPublic;
@ -5263,8 +5226,7 @@ function downloadArtifactInternal(artifactId, options) {
};
const { artifacts } = yield artifactClient.ListArtifacts(listReq);
if (artifacts.length === 0) {
core.warning(`No artifacts found for ID: ${artifactId}\nAre you trying to download from a different run? Try specifying a github-token with \`actions:read\` scope.`);
return { success: false };
throw new errors_1.ArtifactNotFoundError(`No artifacts found for ID: ${artifactId}\nAre you trying to download from a different run? Try specifying a github-token with \`actions:read\` scope.`);
}
if (artifacts.length > 1) {
core.warning('Multiple artifacts found, defaulting to first.');
@ -5284,7 +5246,7 @@ function downloadArtifactInternal(artifactId, options) {
catch (error) {
throw new Error(`Unable to download and extract artifact: ${error.message}`);
}
return { success: true, downloadPath };
return { downloadPath };
});
}
exports.downloadArtifactInternal = downloadArtifactInternal;
@ -5353,7 +5315,9 @@ const util_1 = __nccwpck_require__(80565);
const user_agent_1 = __nccwpck_require__(79681);
const artifact_twirp_client_1 = __nccwpck_require__(63550);
const generated_1 = __nccwpck_require__(90265);
const errors_1 = __nccwpck_require__(69398);
function getArtifactPublic(artifactName, workflowRunId, repositoryOwner, repositoryName, token) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const [retryOpts, requestOpts] = (0, retry_options_1.getRetryOptions)(utils_1.defaults);
const opts = {
@ -5371,16 +5335,10 @@ function getArtifactPublic(artifactName, workflowRunId, repositoryOwner, reposit
name: artifactName
});
if (getArtifactResp.status !== 200) {
core.warning(`non-200 response from GitHub API: ${getArtifactResp.status}`);
return {
success: false
};
throw new errors_1.InvalidResponseError(`Invalid response from GitHub API: ${getArtifactResp.status} (${(_a = getArtifactResp === null || getArtifactResp === void 0 ? void 0 : getArtifactResp.headers) === null || _a === void 0 ? void 0 : _a['x-github-request-id']})`);
}
if (getArtifactResp.data.artifacts.length === 0) {
core.warning('no artifacts found');
return {
success: false
};
throw new errors_1.ArtifactNotFoundError(`Artifact not found for name: ${artifactName}`);
}
let artifact = getArtifactResp.data.artifacts[0];
if (getArtifactResp.data.artifacts.length > 1) {
@ -5388,7 +5346,6 @@ function getArtifactPublic(artifactName, workflowRunId, repositoryOwner, reposit
core.debug(`More than one artifact found for a single name, returning newest (id: ${artifact.id})`);
}
return {
success: true,
artifact: {
name: artifact.name,
id: artifact.id,
@ -5410,18 +5367,14 @@ function getArtifactInternal(artifactName) {
};
const res = yield artifactClient.ListArtifacts(req);
if (res.artifacts.length === 0) {
core.warning('no artifacts found');
return {
success: false
};
throw new errors_1.ArtifactNotFoundError(`Artifact not found for name: ${artifactName}`);
}
let artifact = res.artifacts[0];
if (res.artifacts.length > 1) {
artifact = res.artifacts.sort((a, b) => Number(b.databaseId) - Number(a.databaseId))[0];
core.debug(`more than one artifact found for a single name, returning newest (id: ${artifact.databaseId})`);
core.debug(`More than one artifact found for a single name, returning newest (id: ${artifact.databaseId})`);
}
return {
success: true,
artifact: {
name: artifact.name,
id: Number(artifact.databaseId),
@ -5693,8 +5646,7 @@ class ArtifactHttpClient {
'Content-Type': contentType
};
try {
const response = yield this.retryableRequest(() => __awaiter(this, void 0, void 0, function* () { return this.httpClient.post(url, JSON.stringify(data), headers); }));
const body = yield response.readBody();
const { body } = yield this.retryableRequest(() => __awaiter(this, void 0, void 0, function* () { return this.httpClient.post(url, JSON.stringify(data), headers); }));
return JSON.parse(body);
}
catch (error) {
@ -5711,10 +5663,12 @@ class ArtifactHttpClient {
try {
const response = yield operation();
const statusCode = response.message.statusCode;
(0, core_1.debug)(`[Response] ${response.message.statusCode}`);
(0, core_1.debug)(JSON.stringify(response.message.headers, null, 2));
const body = yield response.readBody();
(0, core_1.debug)(`[Response] - ${response.message.statusCode}`);
(0, core_1.debug)(`Headers: ${JSON.stringify(response.message.headers, null, 2)}`);
(0, core_1.debug)(`Body: ${body}`);
if (this.isSuccessStatusCode(statusCode)) {
return response;
return { response, body };
}
isRetryable = this.isRetryableHttpStatusCode(statusCode);
errorMessage = `Failed request: (${statusCode}) ${response.message.statusMessage}`;
@ -5844,6 +5798,50 @@ exports.getConcurrency = getConcurrency;
/***/ }),
/***/ 69398:
/***/ ((__unused_webpack_module, exports) => {
"use strict";
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.GHESNotSupportedError = exports.ArtifactNotFoundError = exports.InvalidResponseError = exports.FilesNotFoundError = void 0;
class FilesNotFoundError extends Error {
constructor(files = []) {
let message = 'No files were found to upload';
if (files.length > 0) {
message += `: ${files.join(', ')}`;
}
super(message);
this.files = files;
this.name = 'FilesNotFoundError';
}
}
exports.FilesNotFoundError = FilesNotFoundError;
class InvalidResponseError extends Error {
constructor(message) {
super(message);
this.name = 'InvalidResponseError';
}
}
exports.InvalidResponseError = InvalidResponseError;
class ArtifactNotFoundError extends Error {
constructor(message = 'Artifact not found') {
super(message);
this.name = 'ArtifactNotFoundError';
}
}
exports.ArtifactNotFoundError = ArtifactNotFoundError;
class GHESNotSupportedError extends Error {
constructor(message = '@actions/artifact v2.0.0+, upload-artifact@v4+ and download-artifact@v4+ are not currently supported on GHES.') {
super(message);
this.name = 'GHESNotSupportedError';
}
}
exports.GHESNotSupportedError = GHESNotSupportedError;
//# sourceMappingURL=errors.js.map
/***/ }),
/***/ 2538:
/***/ ((__unused_webpack_module, exports) => {
@ -6027,28 +6025,16 @@ function uploadZipToBlobStorage(authenticatedUploadURL, zipUploadStream) {
const hashStream = crypto.createHash('sha256');
zipUploadStream.pipe(uploadStream); // This stream is used for the upload
zipUploadStream.pipe(hashStream).setEncoding('hex'); // This stream is used to compute a hash of the zip content that gets used. Integrity check
try {
core.info('Beginning upload of artifact content to blob storage');
yield blockBlobClient.uploadStream(uploadStream, bufferSize, maxConcurrency, options);
core.info('Finished uploading artifact content to blob storage!');
hashStream.end();
sha256Hash = hashStream.read();
core.info(`SHA256 hash of uploaded artifact zip is ${sha256Hash}`);
}
catch (error) {
core.warning(`Failed to upload artifact zip to blob storage, error: ${error}`);
return {
isSuccess: false
};
}
if (uploadByteCount === 0) {
core.warning(`No data was uploaded to blob storage. Reported upload byte count is 0`);
return {
isSuccess: false
};
core.warning(`No data was uploaded to blob storage. Reported upload byte count is 0.`);
}
return {
isSuccess: true,
uploadSize: uploadByteCount,
sha256Hash
};
@ -6242,18 +6228,15 @@ const util_1 = __nccwpck_require__(80565);
const blob_upload_1 = __nccwpck_require__(63311);
const zip_1 = __nccwpck_require__(6180);
const generated_1 = __nccwpck_require__(90265);
const errors_1 = __nccwpck_require__(69398);
function uploadArtifact(name, files, rootDirectory, options) {
return __awaiter(this, void 0, void 0, function* () {
(0, path_and_artifact_name_validation_1.validateArtifactName)(name);
(0, upload_zip_specification_1.validateRootDirectory)(rootDirectory);
const zipSpecification = (0, upload_zip_specification_1.getUploadZipSpecification)(files, rootDirectory);
if (zipSpecification.length === 0) {
core.warning(`No files were found to upload`);
return {
success: false
};
throw new errors_1.FilesNotFoundError(zipSpecification.flatMap(s => (s.sourcePath ? [s.sourcePath] : [])));
}
const zipUploadStream = yield (0, zip_1.createZipUploadStream)(zipSpecification, options === null || options === void 0 ? void 0 : options.compressionLevel);
// get the IDs needed for the artifact creation
const backendIds = (0, util_1.getBackendIdsFromToken)();
// create the artifact client
@ -6272,18 +6255,11 @@ function uploadArtifact(name, files, rootDirectory, options) {
}
const createArtifactResp = yield artifactClient.CreateArtifact(createArtifactReq);
if (!createArtifactResp.ok) {
core.warning(`Failed to create artifact`);
return {
success: false
};
throw new errors_1.InvalidResponseError('CreateArtifact: response from backend was not ok');
}
const zipUploadStream = yield (0, zip_1.createZipUploadStream)(zipSpecification, options === null || options === void 0 ? void 0 : options.compressionLevel);
// Upload zip to blob storage
const uploadResult = yield (0, blob_upload_1.uploadZipToBlobStorage)(createArtifactResp.signedUploadUrl, zipUploadStream);
if (uploadResult.isSuccess === false) {
return {
success: false
};
}
// finalize the artifact
const finalizeArtifactReq = {
workflowRunBackendId: backendIds.workflowRunBackendId,
@ -6299,15 +6275,11 @@ function uploadArtifact(name, files, rootDirectory, options) {
core.info(`Finalizing artifact upload`);
const finalizeArtifactResp = yield artifactClient.FinalizeArtifact(finalizeArtifactReq);
if (!finalizeArtifactResp.ok) {
core.warning(`Failed to finalize artifact`);
return {
success: false
};
throw new errors_1.InvalidResponseError('FinalizeArtifact: response from backend was not ok');
}
const artifactId = BigInt(finalizeArtifactResp.artifactId);
core.info(`Artifact ${name}.zip successfully finalized. Artifact ID ${artifactId}`);
return {
success: true,
size: uploadResult.uploadSize,
id: Number(artifactId)
};
@ -122076,9 +122048,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
const core = __importStar(__nccwpck_require__(42186));
const artifact_1 = __nccwpck_require__(99860);
const artifact_1 = __importDefault(__nccwpck_require__(99860));
const search_1 = __nccwpck_require__(13930);
const input_helper_1 = __nccwpck_require__(46455);
const constants_1 = __nccwpck_require__(69042);
@ -122108,7 +122083,6 @@ function run() {
const s = searchResult.filesToUpload.length === 1 ? '' : 's';
core.info(`With the provided path, there will be ${searchResult.filesToUpload.length} file${s} uploaded`);
core.debug(`Root artifact directory is ${searchResult.rootDirectory}`);
const artifactClient = (0, artifact_1.create)();
const options = {};
if (inputs.retentionDays) {
options.retentionDays = inputs.retentionDays;
@ -122116,16 +122090,11 @@ function run() {
if (typeof inputs.compressionLevel !== 'undefined') {
options.compressionLevel = inputs.compressionLevel;
}
const uploadResponse = yield artifactClient.uploadArtifact(inputs.artifactName, searchResult.filesToUpload, searchResult.rootDirectory, options);
if (uploadResponse.success === false) {
core.setFailed(`An error was encountered when uploading ${inputs.artifactName}.`);
}
else {
const uploadResponse = yield artifact_1.default.uploadArtifact(inputs.artifactName, searchResult.filesToUpload, searchResult.rootDirectory, options);
core.info(`Artifact ${inputs.artifactName} has been successfully uploaded! Final size is ${uploadResponse.size} bytes. Artifact ID is ${uploadResponse.id}`);
core.setOutput('artifact-id', uploadResponse.id);
}
}
}
catch (error) {
core.setFailed(error.message);
}

@ -1,7 +1,6 @@
import * as core from '../node_modules/@actions/core/'
import {
UploadArtifactOptions,
create
import artifact, {
UploadArtifactOptions
} from '../node_modules/@actions/artifact/lib/artifact'
import {findFilesToUpload} from './search'
import {getInputs} from './input-helper'
@ -40,7 +39,6 @@ async function run(): Promise<void> {
)
core.debug(`Root artifact directory is ${searchResult.rootDirectory}`)
const artifactClient = create()
const options: UploadArtifactOptions = {}
if (inputs.retentionDays) {
options.retentionDays = inputs.retentionDays
@ -50,24 +48,18 @@ async function run(): Promise<void> {
options.compressionLevel = inputs.compressionLevel
}
const uploadResponse = await artifactClient.uploadArtifact(
const uploadResponse = await artifact.uploadArtifact(
inputs.artifactName,
searchResult.filesToUpload,
searchResult.rootDirectory,
options
)
if (uploadResponse.success === false) {
core.setFailed(
`An error was encountered when uploading ${inputs.artifactName}.`
)
} else {
core.info(
`Artifact ${inputs.artifactName} has been successfully uploaded! Final size is ${uploadResponse.size} bytes. Artifact ID is ${uploadResponse.id}`
)
core.setOutput('artifact-id', uploadResponse.id)
}
}
} catch (error) {
core.setFailed((error as Error).message)
}