Compare commits

..

3 Commits

Author SHA1 Message Date
Rob Herley
ed25d4d912 more debug logs 2023-11-30 22:06:26 -05:00
Rob Herley
db146faf7b tsc & ncc 2023-11-30 21:37:48 -05:00
Rob Herley
6ee005d6b7 adopt new internal artifact api behavior 2023-11-30 21:37:06 -05:00
2 changed files with 36 additions and 95 deletions

105
dist/index.js vendored
View File

@@ -7041,8 +7041,7 @@ class ListArtifactsResponse_MonolithArtifact$Type extends runtime_5.MessageType
{ no: 2, name: "workflow_job_run_backend_id", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
{ no: 3, name: "database_id", kind: "scalar", T: 3 /*ScalarType.INT64*/ },
{ no: 4, name: "name", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
{ no: 5, name: "size", kind: "scalar", T: 3 /*ScalarType.INT64*/ },
{ no: 6, name: "created_at", kind: "message", T: () => timestamp_1.Timestamp }
{ no: 5, name: "size", kind: "scalar", T: 3 /*ScalarType.INT64*/ }
]);
}
create(value) {
@@ -7072,9 +7071,6 @@ class ListArtifactsResponse_MonolithArtifact$Type extends runtime_5.MessageType
case /* int64 size */ 5:
message.size = reader.int64().toString();
break;
case /* google.protobuf.Timestamp created_at */ 6:
message.createdAt = timestamp_1.Timestamp.internalBinaryRead(reader, reader.uint32(), options, message.createdAt);
break;
default:
let u = options.readUnknownField;
if (u === "throw")
@@ -7102,9 +7098,6 @@ class ListArtifactsResponse_MonolithArtifact$Type extends runtime_5.MessageType
/* int64 size = 5; */
if (message.size !== "0")
writer.tag(5, runtime_1.WireType.Varint).int64(message.size);
/* google.protobuf.Timestamp created_at = 6; */
if (message.createdAt)
timestamp_1.Timestamp.internalBinaryWrite(message.createdAt, writer.tag(6, runtime_1.WireType.LengthDelimited).fork(), options).join();
let u = options.writeUnknownFields;
if (u !== false)
(u == true ? runtime_2.UnknownFieldHandler.onWrite : u)(this.typeName, message, writer);
@@ -7741,7 +7734,7 @@ If the error persists, please check whether Actions is operating normally at [ht
const { findBy: { repositoryOwner, repositoryName, token } } = options, downloadOptions = __rest(options, ["findBy"]);
return (0, download_artifact_1.downloadArtifactPublic)(artifactId, repositoryOwner, repositoryName, token, downloadOptions);
}
return (0, download_artifact_1.downloadArtifactInternal)(artifactId, options);
return (0, download_artifact_1.downloadArtifactInternal)(artifactId);
}
catch (error) {
(0, core_1.warning)(`Artifact download failed with error: ${error}.
@@ -7769,9 +7762,9 @@ If the error persists, please check whether Actions and API requests are operati
try {
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);
return (0, list_artifacts_1.listArtifactsPublic)(workflowRunId, repositoryOwner, repositoryName, token);
}
return (0, list_artifacts_1.listArtifactsInternal)(options === null || options === void 0 ? void 0 : options.latest);
return (0, list_artifacts_1.listArtifactsInternal)();
}
catch (error) {
(0, core_1.warning)(`Listing Artifacts failed with error: ${error}.
@@ -7871,7 +7864,6 @@ const unzipper_1 = __importDefault(__nccwpck_require__(80686));
const user_agent_1 = __nccwpck_require__(79681);
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 scrubQueryParameters = (url) => {
const parsed = new URL(url);
@@ -7945,8 +7937,7 @@ function downloadArtifactInternal(artifactId, options) {
const { workflowRunBackendId, workflowJobRunBackendId } = (0, util_1.getBackendIdsFromToken)();
const listReq = {
workflowRunBackendId,
workflowJobRunBackendId,
idFilter: generated_1.Int64Value.create({ value: artifactId.toString() })
workflowJobRunBackendId
};
const { artifacts } = yield artifactClient.ListArtifacts(listReq);
if (artifacts.length === 0) {
@@ -8069,18 +8060,15 @@ function getArtifactPublic(artifactName, workflowRunId, repositoryOwner, reposit
success: false
};
}
let artifact = getArtifactResp.data.artifacts[0];
if (getArtifactResp.data.artifacts.length > 1) {
artifact = getArtifactResp.data.artifacts.sort((a, b) => b.id - a.id)[0];
core.debug(`More than one artifact found for a single name, returning newest (id: ${artifact.id})`);
core.warning('more than one artifact found for a single name, returning first');
}
return {
success: true,
artifact: {
name: artifact.name,
id: artifact.id,
size: artifact.size_in_bytes,
createdAt: artifact.created_at ? new Date(artifact.created_at) : undefined
name: getArtifactResp.data.artifacts[0].name,
id: getArtifactResp.data.artifacts[0].id,
size: getArtifactResp.data.artifacts[0].size_in_bytes
}
};
});
@@ -8102,20 +8090,19 @@ function getArtifactInternal(artifactName) {
success: false
};
}
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.warning('more than one artifact found for a single name, returning first');
}
// In the case of reruns, we may have artifacts with the same name scoped under the same workflow run.
// Let's prefer the artifact closest scoped to this run.
// If it doesn't exist (e.g. partial rerun) we'll use the first match.
const artifact = res.artifacts.find(artifact => artifact.workflowRunBackendId === workflowRunBackendId) || res.artifacts[0];
return {
success: true,
artifact: {
name: artifact.name,
id: Number(artifact.databaseId),
size: Number(artifact.size),
createdAt: artifact.createdAt
? generated_1.Timestamp.toDate(artifact.createdAt)
: undefined
size: Number(artifact.size)
}
};
});
@@ -8150,15 +8137,14 @@ const plugin_request_log_1 = __nccwpck_require__(73665);
const plugin_retry_1 = __nccwpck_require__(69980);
const artifact_twirp_client_1 = __nccwpck_require__(63550);
const util_1 = __nccwpck_require__(80565);
const generated_1 = __nccwpck_require__(90265);
// Limiting to 1000 for perf reasons
const maximumArtifactCount = 1000;
const paginationCount = 100;
const maxNumberOfPages = maximumArtifactCount / paginationCount;
function listArtifactsPublic(workflowRunId, repositoryOwner, repositoryName, token, latest = false) {
function listArtifactsPublic(workflowRunId, repositoryOwner, repositoryName, token) {
return __awaiter(this, void 0, void 0, function* () {
(0, core_1.info)(`Fetching artifact list for workflow run ${workflowRunId} in repository ${repositoryOwner}/${repositoryName}`);
let artifacts = [];
const artifacts = [];
const [retryOpts, requestOpts] = (0, retry_options_1.getRetryOptions)(utils_1.defaults);
const opts = {
log: undefined,
@@ -8187,8 +8173,7 @@ function listArtifactsPublic(workflowRunId, repositoryOwner, repositoryName, tok
artifacts.push({
name: artifact.name,
id: artifact.id,
size: artifact.size_in_bytes,
createdAt: artifact.created_at ? new Date(artifact.created_at) : undefined
size: artifact.size_in_bytes
});
}
// Iterate over any remaining pages
@@ -8206,16 +8191,10 @@ function listArtifactsPublic(workflowRunId, repositoryOwner, repositoryName, tok
artifacts.push({
name: artifact.name,
id: artifact.id,
size: artifact.size_in_bytes,
createdAt: artifact.created_at
? new Date(artifact.created_at)
: undefined
size: artifact.size_in_bytes
});
}
}
if (latest) {
artifacts = filterLatest(artifacts);
}
(0, core_1.info)(`Found ${artifacts.length} artifact(s)`);
return {
artifacts
@@ -8223,7 +8202,7 @@ function listArtifactsPublic(workflowRunId, repositoryOwner, repositoryName, tok
});
}
exports.listArtifactsPublic = listArtifactsPublic;
function listArtifactsInternal(latest = false) {
function listArtifactsInternal() {
return __awaiter(this, void 0, void 0, function* () {
const artifactClient = (0, artifact_twirp_client_1.internalArtifactTwirpClient)();
const { workflowRunBackendId, workflowJobRunBackendId } = (0, util_1.getBackendIdsFromToken)();
@@ -8232,17 +8211,11 @@ function listArtifactsInternal(latest = false) {
workflowJobRunBackendId
};
const res = yield artifactClient.ListArtifacts(req);
let artifacts = res.artifacts.map(artifact => ({
const artifacts = res.artifacts.map(artifact => ({
name: artifact.name,
id: Number(artifact.databaseId),
size: Number(artifact.size),
createdAt: artifact.createdAt
? generated_1.Timestamp.toDate(artifact.createdAt)
: undefined
size: Number(artifact.size)
}));
if (latest) {
artifacts = filterLatest(artifacts);
}
(0, core_1.info)(`Found ${artifacts.length} artifact(s)`);
return {
artifacts
@@ -8250,23 +8223,6 @@ function listArtifactsInternal(latest = false) {
});
}
exports.listArtifactsInternal = listArtifactsInternal;
/**
* Filters a list of artifacts to only include the latest artifact for each name
* @param artifacts The artifacts to filter
* @returns The filtered list of artifacts
*/
function filterLatest(artifacts) {
artifacts.sort((a, b) => b.id - a.id);
const latestArtifacts = [];
const seenArtifactNames = new Set();
for (const artifact of artifacts) {
if (!seenArtifactNames.has(artifact.name)) {
latestArtifacts.push(artifact);
seenArtifactNames.add(artifact.name);
}
}
return latestArtifacts;
}
//# sourceMappingURL=list-artifacts.js.map
/***/ }),
@@ -119397,7 +119353,6 @@ function run() {
if (inputs.path.startsWith(`~`)) {
inputs.path = inputs.path.replace('~', os.homedir());
}
const isSingleArtifactDownload = !!inputs.name;
const resolvedPath = path.resolve(inputs.path);
core.debug(`Resolved path is ${resolvedPath}`);
const options = {};
@@ -119415,27 +119370,25 @@ function run() {
}
const artifactClient = artifact.create();
let artifacts = [];
if (isSingleArtifactDownload) {
core.info(`Downloading single artifact`);
if (inputs.name) {
const { artifact: targetArtifact } = yield artifactClient.getArtifact(inputs.name, options);
if (!targetArtifact) {
throw new Error(`Artifact '${inputs.name}' not found`);
}
core.debug(`Found named artifact '${inputs.name}' (ID: ${targetArtifact.id}, Size: ${targetArtifact.size})`);
core.debug('Found named artifact:');
core.debug(JSON.stringify(targetArtifact, null, 2));
artifacts = [targetArtifact];
}
else {
core.info(`No input name specified, downloading all artifacts. Extra directory with the artifact name will be created for each download`);
const listArtifactResponse = yield artifactClient.listArtifacts(Object.assign({ latest: true }, options));
const listArtifactResponse = yield artifactClient.listArtifacts(options);
if (listArtifactResponse.artifacts.length === 0) {
throw new Error(`No artifacts found for run '${inputs.runID}' in '${inputs.repository}'`);
}
core.debug(`Found ${listArtifactResponse.artifacts.length} artifacts`);
core.debug(`Found ${listArtifactResponse.artifacts.length} artifacts:`);
core.debug(JSON.stringify(listArtifactResponse, null, 2));
artifacts = listArtifactResponse.artifacts;
}
const downloadPromises = artifacts.map(artifact => artifactClient.downloadArtifact(artifact.id, Object.assign(Object.assign({}, options), { path: isSingleArtifactDownload
? resolvedPath
: path.join(resolvedPath, artifact.name) })));
const downloadPromises = artifacts.map(artifact => artifactClient.downloadArtifact(artifact.id, Object.assign(Object.assign({}, options), { path: path.join(resolvedPath, artifact.name) })));
const chunkedPromises = exports.chunk(downloadPromises, PARALLEL_DOWNLOADS);
for (const chunk of chunkedPromises) {
yield Promise.all(chunk);

View File

@@ -30,7 +30,6 @@ async function run(): Promise<void> {
inputs.path = inputs.path.replace('~', os.homedir())
}
const isSingleArtifactDownload = !!inputs.name
const resolvedPath = path.resolve(inputs.path)
core.debug(`Resolved path is ${resolvedPath}`)
@@ -54,9 +53,7 @@ async function run(): Promise<void> {
const artifactClient = artifact.create()
let artifacts: artifact.Artifact[] = []
if (isSingleArtifactDownload) {
core.info(`Downloading single artifact`)
if (inputs.name) {
const {artifact: targetArtifact} = await artifactClient.getArtifact(
inputs.name,
options
@@ -66,20 +63,12 @@ async function run(): Promise<void> {
throw new Error(`Artifact '${inputs.name}' not found`)
}
core.debug(
`Found named artifact '${inputs.name}' (ID: ${targetArtifact.id}, Size: ${targetArtifact.size})`
)
core.debug('Found named artifact:')
core.debug(JSON.stringify(targetArtifact, null, 2))
artifacts = [targetArtifact]
} else {
core.info(
`No input name specified, downloading all artifacts. Extra directory with the artifact name will be created for each download`
)
const listArtifactResponse = await artifactClient.listArtifacts({
latest: true,
...options
})
const listArtifactResponse = await artifactClient.listArtifacts(options)
if (listArtifactResponse.artifacts.length === 0) {
throw new Error(
@@ -87,16 +76,15 @@ async function run(): Promise<void> {
)
}
core.debug(`Found ${listArtifactResponse.artifacts.length} artifacts`)
core.debug(`Found ${listArtifactResponse.artifacts.length} artifacts:`)
core.debug(JSON.stringify(listArtifactResponse, null, 2))
artifacts = listArtifactResponse.artifacts
}
const downloadPromises = artifacts.map(artifact =>
artifactClient.downloadArtifact(artifact.id, {
...options,
path: isSingleArtifactDownload
? resolvedPath
: path.join(resolvedPath, artifact.name)
path: path.join(resolvedPath, artifact.name)
})
)