mirror of
https://code.forgejo.org/forgejo/download-artifact.git
synced 2024-12-12 17:27:39 +01:00
set new 'latest' attribute for list operations
This commit is contained in:
parent
5e4b342272
commit
0742efc19b
2 changed files with 67 additions and 22 deletions
84
dist/index.js
vendored
84
dist/index.js
vendored
|
@ -7041,7 +7041,8 @@ 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: 5, name: "size", kind: "scalar", T: 3 /*ScalarType.INT64*/ },
|
||||
{ no: 6, name: "created_at", kind: "message", T: () => timestamp_1.Timestamp }
|
||||
]);
|
||||
}
|
||||
create(value) {
|
||||
|
@ -7071,6 +7072,9 @@ 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")
|
||||
|
@ -7098,6 +7102,9 @@ 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);
|
||||
|
@ -7762,9 +7769,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);
|
||||
return (0, list_artifacts_1.listArtifactsPublic)(workflowRunId, repositoryOwner, repositoryName, token, options === null || options === void 0 ? void 0 : options.latest);
|
||||
}
|
||||
return (0, list_artifacts_1.listArtifactsInternal)();
|
||||
return (0, list_artifacts_1.listArtifactsInternal)(options === null || options === void 0 ? void 0 : options.latest);
|
||||
}
|
||||
catch (error) {
|
||||
(0, core_1.warning)(`Listing Artifacts failed with error: ${error}.
|
||||
|
@ -8062,15 +8069,18 @@ function getArtifactPublic(artifactName, workflowRunId, repositoryOwner, reposit
|
|||
success: false
|
||||
};
|
||||
}
|
||||
let artifact = getArtifactResp.data.artifacts[0];
|
||||
if (getArtifactResp.data.artifacts.length > 1) {
|
||||
core.warning('more than one artifact found for a single name, returning first');
|
||||
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})`);
|
||||
}
|
||||
return {
|
||||
success: true,
|
||||
artifact: {
|
||||
name: getArtifactResp.data.artifacts[0].name,
|
||||
id: getArtifactResp.data.artifacts[0].id,
|
||||
size: getArtifactResp.data.artifacts[0].size_in_bytes
|
||||
name: artifact.name,
|
||||
id: artifact.id,
|
||||
size: artifact.size_in_bytes,
|
||||
createdAt: artifact.created_at ? new Date(artifact.created_at) : undefined
|
||||
}
|
||||
};
|
||||
});
|
||||
|
@ -8092,19 +8102,20 @@ function getArtifactInternal(artifactName) {
|
|||
success: false
|
||||
};
|
||||
}
|
||||
let artifact = res.artifacts[0];
|
||||
if (res.artifacts.length > 1) {
|
||||
core.warning('more than one artifact found for a single name, returning first');
|
||||
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})`);
|
||||
}
|
||||
// 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)
|
||||
size: Number(artifact.size),
|
||||
createdAt: artifact.createdAt
|
||||
? generated_1.Timestamp.toDate(artifact.createdAt)
|
||||
: undefined
|
||||
}
|
||||
};
|
||||
});
|
||||
|
@ -8139,14 +8150,15 @@ 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) {
|
||||
function listArtifactsPublic(workflowRunId, repositoryOwner, repositoryName, token, latest = false) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
(0, core_1.info)(`Fetching artifact list for workflow run ${workflowRunId} in repository ${repositoryOwner}/${repositoryName}`);
|
||||
const artifacts = [];
|
||||
let artifacts = [];
|
||||
const [retryOpts, requestOpts] = (0, retry_options_1.getRetryOptions)(utils_1.defaults);
|
||||
const opts = {
|
||||
log: undefined,
|
||||
|
@ -8175,7 +8187,8 @@ function listArtifactsPublic(workflowRunId, repositoryOwner, repositoryName, tok
|
|||
artifacts.push({
|
||||
name: artifact.name,
|
||||
id: artifact.id,
|
||||
size: artifact.size_in_bytes
|
||||
size: artifact.size_in_bytes,
|
||||
createdAt: artifact.created_at ? new Date(artifact.created_at) : undefined
|
||||
});
|
||||
}
|
||||
// Iterate over any remaining pages
|
||||
|
@ -8193,10 +8206,16 @@ function listArtifactsPublic(workflowRunId, repositoryOwner, repositoryName, tok
|
|||
artifacts.push({
|
||||
name: artifact.name,
|
||||
id: artifact.id,
|
||||
size: artifact.size_in_bytes
|
||||
size: artifact.size_in_bytes,
|
||||
createdAt: artifact.created_at
|
||||
? new Date(artifact.created_at)
|
||||
: undefined
|
||||
});
|
||||
}
|
||||
}
|
||||
if (latest) {
|
||||
artifacts = filterLatest(artifacts);
|
||||
}
|
||||
(0, core_1.info)(`Found ${artifacts.length} artifact(s)`);
|
||||
return {
|
||||
artifacts
|
||||
|
@ -8204,7 +8223,7 @@ function listArtifactsPublic(workflowRunId, repositoryOwner, repositoryName, tok
|
|||
});
|
||||
}
|
||||
exports.listArtifactsPublic = listArtifactsPublic;
|
||||
function listArtifactsInternal() {
|
||||
function listArtifactsInternal(latest = false) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const artifactClient = (0, artifact_twirp_client_1.internalArtifactTwirpClient)();
|
||||
const { workflowRunBackendId, workflowJobRunBackendId } = (0, util_1.getBackendIdsFromToken)();
|
||||
|
@ -8213,11 +8232,17 @@ function listArtifactsInternal() {
|
|||
workflowJobRunBackendId
|
||||
};
|
||||
const res = yield artifactClient.ListArtifacts(req);
|
||||
const artifacts = res.artifacts.map(artifact => ({
|
||||
let artifacts = res.artifacts.map(artifact => ({
|
||||
name: artifact.name,
|
||||
id: Number(artifact.databaseId),
|
||||
size: Number(artifact.size)
|
||||
size: Number(artifact.size),
|
||||
createdAt: artifact.createdAt
|
||||
? generated_1.Timestamp.toDate(artifact.createdAt)
|
||||
: undefined
|
||||
}));
|
||||
if (latest) {
|
||||
artifacts = filterLatest(artifacts);
|
||||
}
|
||||
(0, core_1.info)(`Found ${artifacts.length} artifact(s)`);
|
||||
return {
|
||||
artifacts
|
||||
|
@ -8225,6 +8250,23 @@ function listArtifactsInternal() {
|
|||
});
|
||||
}
|
||||
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
|
||||
|
||||
/***/ }),
|
||||
|
@ -119384,7 +119426,7 @@ function run() {
|
|||
}
|
||||
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(options);
|
||||
const listArtifactResponse = yield artifactClient.listArtifacts(Object.assign({ latest: true }, options));
|
||||
if (listArtifactResponse.artifacts.length === 0) {
|
||||
throw new Error(`No artifacts found for run '${inputs.runID}' in '${inputs.repository}'`);
|
||||
}
|
||||
|
|
|
@ -76,7 +76,10 @@ async function run(): Promise<void> {
|
|||
`No input name specified, downloading all artifacts. Extra directory with the artifact name will be created for each download`
|
||||
)
|
||||
|
||||
const listArtifactResponse = await artifactClient.listArtifacts(options)
|
||||
const listArtifactResponse = await artifactClient.listArtifacts({
|
||||
latest: true,
|
||||
...options
|
||||
})
|
||||
|
||||
if (listArtifactResponse.artifacts.length === 0) {
|
||||
throw new Error(
|
||||
|
|
Loading…
Reference in a new issue