From 5e4b342272a20ab3b4de8489f14874f935768500 Mon Sep 17 00:00:00 2001 From: Rob Herley Date: Fri, 1 Dec 2023 13:20:09 -0500 Subject: [PATCH 1/2] consume latest @actions/artifact --- action.yml | 10 +- dist/index.js | 843 ++++++++++++++++++++++++++++++++++----- src/download-artifact.ts | 51 ++- 3 files changed, 778 insertions(+), 126 deletions(-) diff --git a/action.yml b/action.yml index 0fd14b9..7b37ab7 100644 --- a/action.yml +++ b/action.yml @@ -9,16 +9,18 @@ inputs: description: 'Destination path' required: false github-token: - description: The GitHub token used to download the artifact - default: ${{ github.token }} + description: 'The GitHub token used to authenticate with the GitHub API. + This is required when downloading artifacts from a different repository or from a different workflow run. + If this is not specified, the action will attempt to download artifacts from the current repository and the current workflow run.' required: false repository: description: 'The repository owner and the repository name joined together by "/". - This specifies the repository that artifacts will be downloaded from. If downloading artifacts from external workflow runs or repositories then the above download-token must be permissions to this repository.' + If github-token is specified, this is the repository that artifacts will be downloaded from.' required: false default: ${{ github.repository }} run-id: - description: 'The id of the workflow run where the desired download artifact was uploaded from. If downloading artifacts from anything other than the current workflow run then this needs to be overwritten.' + description: 'The id of the workflow run where the desired download artifact was uploaded from. + If github-token is specified, this is the run that artifacts will be downloaded from.' required: false default: ${{ github.run_id }} outputs: diff --git a/dist/index.js b/dist/index.js index 3ea158e..18f2555 100644 --- a/dist/index.js +++ b/dist/index.js @@ -6647,7 +6647,7 @@ __exportStar(__nccwpck_require__(84701), exports); "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.ArtifactService = exports.FinalizeArtifactResponse = exports.FinalizeArtifactRequest = exports.CreateArtifactResponse = exports.CreateArtifactRequest = void 0; +exports.ArtifactService = exports.GetSignedArtifactURLResponse = exports.GetSignedArtifactURLRequest = exports.ListArtifactsResponse_MonolithArtifact = exports.ListArtifactsResponse = exports.ListArtifactsRequest = exports.FinalizeArtifactResponse = exports.FinalizeArtifactRequest = exports.CreateArtifactResponse = exports.CreateArtifactRequest = void 0; // @generated by protobuf-ts 2.9.1 with parameter long_type_string,client_none,generate_dependencies // @generated from protobuf file "results/api/v1/artifact.proto" (package "github.actions.results.api.v1", syntax proto3) // tslint:disable @@ -6658,6 +6658,7 @@ const runtime_3 = __nccwpck_require__(90076); const runtime_4 = __nccwpck_require__(90076); const runtime_5 = __nccwpck_require__(90076); const wrappers_1 = __nccwpck_require__(97610); +const wrappers_2 = __nccwpck_require__(97610); const timestamp_1 = __nccwpck_require__(68066); // @generated message type with reflection information, may provide speed optimized methods class CreateArtifactRequest$Type extends runtime_5.MessageType { @@ -6796,7 +6797,7 @@ class FinalizeArtifactRequest$Type extends runtime_5.MessageType { { no: 2, name: "workflow_job_run_backend_id", kind: "scalar", T: 9 /*ScalarType.STRING*/ }, { no: 3, name: "name", kind: "scalar", T: 9 /*ScalarType.STRING*/ }, { no: 4, name: "size", kind: "scalar", T: 3 /*ScalarType.INT64*/ }, - { no: 5, name: "hash", kind: "message", T: () => wrappers_1.StringValue } + { no: 5, name: "hash", kind: "message", T: () => wrappers_2.StringValue } ]); } create(value) { @@ -6824,7 +6825,7 @@ class FinalizeArtifactRequest$Type extends runtime_5.MessageType { message.size = reader.int64().toString(); break; case /* google.protobuf.StringValue hash */ 5: - message.hash = wrappers_1.StringValue.internalBinaryRead(reader, reader.uint32(), options, message.hash); + message.hash = wrappers_2.StringValue.internalBinaryRead(reader, reader.uint32(), options, message.hash); break; default: let u = options.readUnknownField; @@ -6852,7 +6853,7 @@ class FinalizeArtifactRequest$Type extends runtime_5.MessageType { writer.tag(4, runtime_1.WireType.Varint).int64(message.size); /* google.protobuf.StringValue hash = 5; */ if (message.hash) - wrappers_1.StringValue.internalBinaryWrite(message.hash, writer.tag(5, runtime_1.WireType.LengthDelimited).fork(), options).join(); + wrappers_2.StringValue.internalBinaryWrite(message.hash, writer.tag(5, 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); @@ -6917,12 +6918,312 @@ class FinalizeArtifactResponse$Type extends runtime_5.MessageType { * @generated MessageType for protobuf message github.actions.results.api.v1.FinalizeArtifactResponse */ exports.FinalizeArtifactResponse = new FinalizeArtifactResponse$Type(); +// @generated message type with reflection information, may provide speed optimized methods +class ListArtifactsRequest$Type extends runtime_5.MessageType { + constructor() { + super("github.actions.results.api.v1.ListArtifactsRequest", [ + { no: 1, name: "workflow_run_backend_id", kind: "scalar", T: 9 /*ScalarType.STRING*/ }, + { no: 2, name: "workflow_job_run_backend_id", kind: "scalar", T: 9 /*ScalarType.STRING*/ }, + { no: 3, name: "name_filter", kind: "message", T: () => wrappers_2.StringValue }, + { no: 4, name: "id_filter", kind: "message", T: () => wrappers_1.Int64Value } + ]); + } + create(value) { + const message = { workflowRunBackendId: "", workflowJobRunBackendId: "" }; + globalThis.Object.defineProperty(message, runtime_4.MESSAGE_TYPE, { enumerable: false, value: this }); + if (value !== undefined) + (0, runtime_3.reflectionMergePartial)(this, message, value); + return message; + } + internalBinaryRead(reader, length, options, target) { + let message = target !== null && target !== void 0 ? target : this.create(), end = reader.pos + length; + while (reader.pos < end) { + let [fieldNo, wireType] = reader.tag(); + switch (fieldNo) { + case /* string workflow_run_backend_id */ 1: + message.workflowRunBackendId = reader.string(); + break; + case /* string workflow_job_run_backend_id */ 2: + message.workflowJobRunBackendId = reader.string(); + break; + case /* google.protobuf.StringValue name_filter */ 3: + message.nameFilter = wrappers_2.StringValue.internalBinaryRead(reader, reader.uint32(), options, message.nameFilter); + break; + case /* google.protobuf.Int64Value id_filter */ 4: + message.idFilter = wrappers_1.Int64Value.internalBinaryRead(reader, reader.uint32(), options, message.idFilter); + break; + default: + let u = options.readUnknownField; + if (u === "throw") + throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); + let d = reader.skip(wireType); + if (u !== false) + (u === true ? runtime_2.UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); + } + } + return message; + } + internalBinaryWrite(message, writer, options) { + /* string workflow_run_backend_id = 1; */ + if (message.workflowRunBackendId !== "") + writer.tag(1, runtime_1.WireType.LengthDelimited).string(message.workflowRunBackendId); + /* string workflow_job_run_backend_id = 2; */ + if (message.workflowJobRunBackendId !== "") + writer.tag(2, runtime_1.WireType.LengthDelimited).string(message.workflowJobRunBackendId); + /* google.protobuf.StringValue name_filter = 3; */ + if (message.nameFilter) + wrappers_2.StringValue.internalBinaryWrite(message.nameFilter, writer.tag(3, runtime_1.WireType.LengthDelimited).fork(), options).join(); + /* google.protobuf.Int64Value id_filter = 4; */ + if (message.idFilter) + wrappers_1.Int64Value.internalBinaryWrite(message.idFilter, writer.tag(4, 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); + return writer; + } +} +/** + * @generated MessageType for protobuf message github.actions.results.api.v1.ListArtifactsRequest + */ +exports.ListArtifactsRequest = new ListArtifactsRequest$Type(); +// @generated message type with reflection information, may provide speed optimized methods +class ListArtifactsResponse$Type extends runtime_5.MessageType { + constructor() { + super("github.actions.results.api.v1.ListArtifactsResponse", [ + { no: 1, name: "artifacts", kind: "message", repeat: 1 /*RepeatType.PACKED*/, T: () => exports.ListArtifactsResponse_MonolithArtifact } + ]); + } + create(value) { + const message = { artifacts: [] }; + globalThis.Object.defineProperty(message, runtime_4.MESSAGE_TYPE, { enumerable: false, value: this }); + if (value !== undefined) + (0, runtime_3.reflectionMergePartial)(this, message, value); + return message; + } + internalBinaryRead(reader, length, options, target) { + let message = target !== null && target !== void 0 ? target : this.create(), end = reader.pos + length; + while (reader.pos < end) { + let [fieldNo, wireType] = reader.tag(); + switch (fieldNo) { + case /* repeated github.actions.results.api.v1.ListArtifactsResponse.MonolithArtifact artifacts */ 1: + message.artifacts.push(exports.ListArtifactsResponse_MonolithArtifact.internalBinaryRead(reader, reader.uint32(), options)); + break; + default: + let u = options.readUnknownField; + if (u === "throw") + throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); + let d = reader.skip(wireType); + if (u !== false) + (u === true ? runtime_2.UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); + } + } + return message; + } + internalBinaryWrite(message, writer, options) { + /* repeated github.actions.results.api.v1.ListArtifactsResponse.MonolithArtifact artifacts = 1; */ + for (let i = 0; i < message.artifacts.length; i++) + exports.ListArtifactsResponse_MonolithArtifact.internalBinaryWrite(message.artifacts[i], writer.tag(1, 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); + return writer; + } +} +/** + * @generated MessageType for protobuf message github.actions.results.api.v1.ListArtifactsResponse + */ +exports.ListArtifactsResponse = new ListArtifactsResponse$Type(); +// @generated message type with reflection information, may provide speed optimized methods +class ListArtifactsResponse_MonolithArtifact$Type extends runtime_5.MessageType { + constructor() { + super("github.actions.results.api.v1.ListArtifactsResponse.MonolithArtifact", [ + { no: 1, name: "workflow_run_backend_id", kind: "scalar", T: 9 /*ScalarType.STRING*/ }, + { 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*/ } + ]); + } + create(value) { + const message = { workflowRunBackendId: "", workflowJobRunBackendId: "", databaseId: "0", name: "", size: "0" }; + globalThis.Object.defineProperty(message, runtime_4.MESSAGE_TYPE, { enumerable: false, value: this }); + if (value !== undefined) + (0, runtime_3.reflectionMergePartial)(this, message, value); + return message; + } + internalBinaryRead(reader, length, options, target) { + let message = target !== null && target !== void 0 ? target : this.create(), end = reader.pos + length; + while (reader.pos < end) { + let [fieldNo, wireType] = reader.tag(); + switch (fieldNo) { + case /* string workflow_run_backend_id */ 1: + message.workflowRunBackendId = reader.string(); + break; + case /* string workflow_job_run_backend_id */ 2: + message.workflowJobRunBackendId = reader.string(); + break; + case /* int64 database_id */ 3: + message.databaseId = reader.int64().toString(); + break; + case /* string name */ 4: + message.name = reader.string(); + break; + case /* int64 size */ 5: + message.size = reader.int64().toString(); + break; + default: + let u = options.readUnknownField; + if (u === "throw") + throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); + let d = reader.skip(wireType); + if (u !== false) + (u === true ? runtime_2.UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); + } + } + return message; + } + internalBinaryWrite(message, writer, options) { + /* string workflow_run_backend_id = 1; */ + if (message.workflowRunBackendId !== "") + writer.tag(1, runtime_1.WireType.LengthDelimited).string(message.workflowRunBackendId); + /* string workflow_job_run_backend_id = 2; */ + if (message.workflowJobRunBackendId !== "") + writer.tag(2, runtime_1.WireType.LengthDelimited).string(message.workflowJobRunBackendId); + /* int64 database_id = 3; */ + if (message.databaseId !== "0") + writer.tag(3, runtime_1.WireType.Varint).int64(message.databaseId); + /* string name = 4; */ + if (message.name !== "") + writer.tag(4, runtime_1.WireType.LengthDelimited).string(message.name); + /* int64 size = 5; */ + if (message.size !== "0") + writer.tag(5, runtime_1.WireType.Varint).int64(message.size); + let u = options.writeUnknownFields; + if (u !== false) + (u == true ? runtime_2.UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); + return writer; + } +} +/** + * @generated MessageType for protobuf message github.actions.results.api.v1.ListArtifactsResponse.MonolithArtifact + */ +exports.ListArtifactsResponse_MonolithArtifact = new ListArtifactsResponse_MonolithArtifact$Type(); +// @generated message type with reflection information, may provide speed optimized methods +class GetSignedArtifactURLRequest$Type extends runtime_5.MessageType { + constructor() { + super("github.actions.results.api.v1.GetSignedArtifactURLRequest", [ + { no: 1, name: "workflow_run_backend_id", kind: "scalar", T: 9 /*ScalarType.STRING*/ }, + { no: 2, name: "workflow_job_run_backend_id", kind: "scalar", T: 9 /*ScalarType.STRING*/ }, + { no: 3, name: "name", kind: "scalar", T: 9 /*ScalarType.STRING*/ } + ]); + } + create(value) { + const message = { workflowRunBackendId: "", workflowJobRunBackendId: "", name: "" }; + globalThis.Object.defineProperty(message, runtime_4.MESSAGE_TYPE, { enumerable: false, value: this }); + if (value !== undefined) + (0, runtime_3.reflectionMergePartial)(this, message, value); + return message; + } + internalBinaryRead(reader, length, options, target) { + let message = target !== null && target !== void 0 ? target : this.create(), end = reader.pos + length; + while (reader.pos < end) { + let [fieldNo, wireType] = reader.tag(); + switch (fieldNo) { + case /* string workflow_run_backend_id */ 1: + message.workflowRunBackendId = reader.string(); + break; + case /* string workflow_job_run_backend_id */ 2: + message.workflowJobRunBackendId = reader.string(); + break; + case /* string name */ 3: + message.name = reader.string(); + break; + default: + let u = options.readUnknownField; + if (u === "throw") + throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); + let d = reader.skip(wireType); + if (u !== false) + (u === true ? runtime_2.UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); + } + } + return message; + } + internalBinaryWrite(message, writer, options) { + /* string workflow_run_backend_id = 1; */ + if (message.workflowRunBackendId !== "") + writer.tag(1, runtime_1.WireType.LengthDelimited).string(message.workflowRunBackendId); + /* string workflow_job_run_backend_id = 2; */ + if (message.workflowJobRunBackendId !== "") + writer.tag(2, runtime_1.WireType.LengthDelimited).string(message.workflowJobRunBackendId); + /* string name = 3; */ + if (message.name !== "") + writer.tag(3, runtime_1.WireType.LengthDelimited).string(message.name); + let u = options.writeUnknownFields; + if (u !== false) + (u == true ? runtime_2.UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); + return writer; + } +} +/** + * @generated MessageType for protobuf message github.actions.results.api.v1.GetSignedArtifactURLRequest + */ +exports.GetSignedArtifactURLRequest = new GetSignedArtifactURLRequest$Type(); +// @generated message type with reflection information, may provide speed optimized methods +class GetSignedArtifactURLResponse$Type extends runtime_5.MessageType { + constructor() { + super("github.actions.results.api.v1.GetSignedArtifactURLResponse", [ + { no: 1, name: "signed_url", kind: "scalar", T: 9 /*ScalarType.STRING*/ } + ]); + } + create(value) { + const message = { signedUrl: "" }; + globalThis.Object.defineProperty(message, runtime_4.MESSAGE_TYPE, { enumerable: false, value: this }); + if (value !== undefined) + (0, runtime_3.reflectionMergePartial)(this, message, value); + return message; + } + internalBinaryRead(reader, length, options, target) { + let message = target !== null && target !== void 0 ? target : this.create(), end = reader.pos + length; + while (reader.pos < end) { + let [fieldNo, wireType] = reader.tag(); + switch (fieldNo) { + case /* string signed_url */ 1: + message.signedUrl = reader.string(); + break; + default: + let u = options.readUnknownField; + if (u === "throw") + throw new globalThis.Error(`Unknown field ${fieldNo} (wire type ${wireType}) for ${this.typeName}`); + let d = reader.skip(wireType); + if (u !== false) + (u === true ? runtime_2.UnknownFieldHandler.onRead : u)(this.typeName, message, fieldNo, wireType, d); + } + } + return message; + } + internalBinaryWrite(message, writer, options) { + /* string signed_url = 1; */ + if (message.signedUrl !== "") + writer.tag(1, runtime_1.WireType.LengthDelimited).string(message.signedUrl); + let u = options.writeUnknownFields; + if (u !== false) + (u == true ? runtime_2.UnknownFieldHandler.onWrite : u)(this.typeName, message, writer); + return writer; + } +} +/** + * @generated MessageType for protobuf message github.actions.results.api.v1.GetSignedArtifactURLResponse + */ +exports.GetSignedArtifactURLResponse = new GetSignedArtifactURLResponse$Type(); /** * @generated ServiceType for protobuf service github.actions.results.api.v1.ArtifactService */ exports.ArtifactService = new runtime_rpc_1.ServiceType("github.actions.results.api.v1.ArtifactService", [ { name: "CreateArtifact", options: {}, I: exports.CreateArtifactRequest, O: exports.CreateArtifactResponse }, - { name: "FinalizeArtifact", options: {}, I: exports.FinalizeArtifactRequest, O: exports.FinalizeArtifactResponse } + { name: "FinalizeArtifact", options: {}, I: exports.FinalizeArtifactRequest, O: exports.FinalizeArtifactResponse }, + { name: "ListArtifacts", options: {}, I: exports.ListArtifactsRequest, O: exports.ListArtifactsResponse }, + { name: "GetSignedArtifactURL", options: {}, I: exports.GetSignedArtifactURLRequest, O: exports.GetSignedArtifactURLResponse } ]); //# sourceMappingURL=artifact.js.map @@ -6951,23 +7252,45 @@ class ArtifactServiceClientJSON { this.rpc = rpc; this.CreateArtifact.bind(this); this.FinalizeArtifact.bind(this); + this.ListArtifacts.bind(this); + this.GetSignedArtifactURL.bind(this); } CreateArtifact(request) { const data = artifact_1.CreateArtifactRequest.toJson(request, { useProtoFieldName: true, - emitDefaultValues: false + emitDefaultValues: false, }); - const promise = this.rpc.request('github.actions.results.api.v1.ArtifactService', 'CreateArtifact', 'application/json', data); - return promise.then(data => artifact_1.CreateArtifactResponse.fromJson(data, { ignoreUnknownFields: true })); + const promise = this.rpc.request("github.actions.results.api.v1.ArtifactService", "CreateArtifact", "application/json", data); + return promise.then((data) => artifact_1.CreateArtifactResponse.fromJson(data, { + ignoreUnknownFields: true, + })); } FinalizeArtifact(request) { const data = artifact_1.FinalizeArtifactRequest.toJson(request, { useProtoFieldName: true, - emitDefaultValues: false + emitDefaultValues: false, }); - const promise = this.rpc.request('github.actions.results.api.v1.ArtifactService', 'FinalizeArtifact', 'application/json', data); - return promise.then(data => artifact_1.FinalizeArtifactResponse.fromJson(data, { - ignoreUnknownFields: true + const promise = this.rpc.request("github.actions.results.api.v1.ArtifactService", "FinalizeArtifact", "application/json", data); + return promise.then((data) => artifact_1.FinalizeArtifactResponse.fromJson(data, { + ignoreUnknownFields: true, + })); + } + ListArtifacts(request) { + const data = artifact_1.ListArtifactsRequest.toJson(request, { + useProtoFieldName: true, + emitDefaultValues: false, + }); + const promise = this.rpc.request("github.actions.results.api.v1.ArtifactService", "ListArtifacts", "application/json", data); + return promise.then((data) => artifact_1.ListArtifactsResponse.fromJson(data, { ignoreUnknownFields: true })); + } + GetSignedArtifactURL(request) { + const data = artifact_1.GetSignedArtifactURLRequest.toJson(request, { + useProtoFieldName: true, + emitDefaultValues: false, + }); + const promise = this.rpc.request("github.actions.results.api.v1.ArtifactService", "GetSignedArtifactURL", "application/json", data); + return promise.then((data) => artifact_1.GetSignedArtifactURLResponse.fromJson(data, { + ignoreUnknownFields: true, })); } } @@ -6977,16 +7300,28 @@ class ArtifactServiceClientProtobuf { this.rpc = rpc; this.CreateArtifact.bind(this); this.FinalizeArtifact.bind(this); + this.ListArtifacts.bind(this); + this.GetSignedArtifactURL.bind(this); } CreateArtifact(request) { const data = artifact_1.CreateArtifactRequest.toBinary(request); - const promise = this.rpc.request('github.actions.results.api.v1.ArtifactService', 'CreateArtifact', 'application/protobuf', data); - return promise.then(data => artifact_1.CreateArtifactResponse.fromBinary(data)); + const promise = this.rpc.request("github.actions.results.api.v1.ArtifactService", "CreateArtifact", "application/protobuf", data); + return promise.then((data) => artifact_1.CreateArtifactResponse.fromBinary(data)); } FinalizeArtifact(request) { const data = artifact_1.FinalizeArtifactRequest.toBinary(request); - const promise = this.rpc.request('github.actions.results.api.v1.ArtifactService', 'FinalizeArtifact', 'application/protobuf', data); - return promise.then(data => artifact_1.FinalizeArtifactResponse.fromBinary(data)); + const promise = this.rpc.request("github.actions.results.api.v1.ArtifactService", "FinalizeArtifact", "application/protobuf", data); + return promise.then((data) => artifact_1.FinalizeArtifactResponse.fromBinary(data)); + } + ListArtifacts(request) { + const data = artifact_1.ListArtifactsRequest.toBinary(request); + const promise = this.rpc.request("github.actions.results.api.v1.ArtifactService", "ListArtifacts", "application/protobuf", data); + return promise.then((data) => artifact_1.ListArtifactsResponse.fromBinary(data)); + } + GetSignedArtifactURL(request) { + const data = artifact_1.GetSignedArtifactURLRequest.toBinary(request); + const promise = this.rpc.request("github.actions.results.api.v1.ArtifactService", "GetSignedArtifactURL", "application/protobuf", data); + return promise.then((data) => artifact_1.GetSignedArtifactURLResponse.fromBinary(data)); } } exports.ArtifactServiceClientProtobuf = ArtifactServiceClientProtobuf; @@ -6994,35 +7329,51 @@ var ArtifactServiceMethod; (function (ArtifactServiceMethod) { ArtifactServiceMethod["CreateArtifact"] = "CreateArtifact"; ArtifactServiceMethod["FinalizeArtifact"] = "FinalizeArtifact"; + ArtifactServiceMethod["ListArtifacts"] = "ListArtifacts"; + ArtifactServiceMethod["GetSignedArtifactURL"] = "GetSignedArtifactURL"; })(ArtifactServiceMethod || (exports.ArtifactServiceMethod = ArtifactServiceMethod = {})); exports.ArtifactServiceMethodList = [ ArtifactServiceMethod.CreateArtifact, - ArtifactServiceMethod.FinalizeArtifact + ArtifactServiceMethod.FinalizeArtifact, + ArtifactServiceMethod.ListArtifacts, + ArtifactServiceMethod.GetSignedArtifactURL, ]; function createArtifactServiceServer(service) { return new twirp_ts_1.TwirpServer({ service, - packageName: 'github.actions.results.api.v1', - serviceName: 'ArtifactService', + packageName: "github.actions.results.api.v1", + serviceName: "ArtifactService", methodList: exports.ArtifactServiceMethodList, - matchRoute: matchArtifactServiceRoute + matchRoute: matchArtifactServiceRoute, }); } exports.createArtifactServiceServer = createArtifactServiceServer; function matchArtifactServiceRoute(method, events) { switch (method) { - case 'CreateArtifact': + case "CreateArtifact": return (ctx, service, data, interceptors) => __awaiter(this, void 0, void 0, function* () { - ctx = Object.assign(Object.assign({}, ctx), { methodName: 'CreateArtifact' }); + ctx = Object.assign(Object.assign({}, ctx), { methodName: "CreateArtifact" }); yield events.onMatch(ctx); return handleArtifactServiceCreateArtifactRequest(ctx, service, data, interceptors); }); - case 'FinalizeArtifact': + case "FinalizeArtifact": return (ctx, service, data, interceptors) => __awaiter(this, void 0, void 0, function* () { - ctx = Object.assign(Object.assign({}, ctx), { methodName: 'FinalizeArtifact' }); + ctx = Object.assign(Object.assign({}, ctx), { methodName: "FinalizeArtifact" }); yield events.onMatch(ctx); return handleArtifactServiceFinalizeArtifactRequest(ctx, service, data, interceptors); }); + case "ListArtifacts": + return (ctx, service, data, interceptors) => __awaiter(this, void 0, void 0, function* () { + ctx = Object.assign(Object.assign({}, ctx), { methodName: "ListArtifacts" }); + yield events.onMatch(ctx); + return handleArtifactServiceListArtifactsRequest(ctx, service, data, interceptors); + }); + case "GetSignedArtifactURL": + return (ctx, service, data, interceptors) => __awaiter(this, void 0, void 0, function* () { + ctx = Object.assign(Object.assign({}, ctx), { methodName: "GetSignedArtifactURL" }); + yield events.onMatch(ctx); + return handleArtifactServiceGetSignedArtifactURLRequest(ctx, service, data, interceptors); + }); default: events.onNotFound(); const msg = `no handler found`; @@ -7036,7 +7387,7 @@ function handleArtifactServiceCreateArtifactRequest(ctx, service, data, intercep case twirp_ts_1.TwirpContentType.Protobuf: return handleArtifactServiceCreateArtifactProtobuf(ctx, service, data, interceptors); default: - const msg = 'unexpected Content-Type'; + const msg = "unexpected Content-Type"; throw new twirp_ts_1.TwirpError(twirp_ts_1.TwirpErrorCode.BadRoute, msg); } } @@ -7047,7 +7398,29 @@ function handleArtifactServiceFinalizeArtifactRequest(ctx, service, data, interc case twirp_ts_1.TwirpContentType.Protobuf: return handleArtifactServiceFinalizeArtifactProtobuf(ctx, service, data, interceptors); default: - const msg = 'unexpected Content-Type'; + const msg = "unexpected Content-Type"; + throw new twirp_ts_1.TwirpError(twirp_ts_1.TwirpErrorCode.BadRoute, msg); + } +} +function handleArtifactServiceListArtifactsRequest(ctx, service, data, interceptors) { + switch (ctx.contentType) { + case twirp_ts_1.TwirpContentType.JSON: + return handleArtifactServiceListArtifactsJSON(ctx, service, data, interceptors); + case twirp_ts_1.TwirpContentType.Protobuf: + return handleArtifactServiceListArtifactsProtobuf(ctx, service, data, interceptors); + default: + const msg = "unexpected Content-Type"; + throw new twirp_ts_1.TwirpError(twirp_ts_1.TwirpErrorCode.BadRoute, msg); + } +} +function handleArtifactServiceGetSignedArtifactURLRequest(ctx, service, data, interceptors) { + switch (ctx.contentType) { + case twirp_ts_1.TwirpContentType.JSON: + return handleArtifactServiceGetSignedArtifactURLJSON(ctx, service, data, interceptors); + case twirp_ts_1.TwirpContentType.Protobuf: + return handleArtifactServiceGetSignedArtifactURLProtobuf(ctx, service, data, interceptors); + default: + const msg = "unexpected Content-Type"; throw new twirp_ts_1.TwirpError(twirp_ts_1.TwirpErrorCode.BadRoute, msg); } } @@ -7056,12 +7429,14 @@ function handleArtifactServiceCreateArtifactJSON(ctx, service, data, interceptor let request; let response; try { - const body = JSON.parse(data.toString() || '{}'); - request = artifact_1.CreateArtifactRequest.fromJson(body, { ignoreUnknownFields: true }); + const body = JSON.parse(data.toString() || "{}"); + request = artifact_1.CreateArtifactRequest.fromJson(body, { + ignoreUnknownFields: true, + }); } catch (e) { if (e instanceof Error) { - const msg = 'the json request could not be decoded'; + const msg = "the json request could not be decoded"; throw new twirp_ts_1.TwirpError(twirp_ts_1.TwirpErrorCode.Malformed, msg).withCause(e, true); } } @@ -7076,7 +7451,7 @@ function handleArtifactServiceCreateArtifactJSON(ctx, service, data, interceptor } return JSON.stringify(artifact_1.CreateArtifactResponse.toJson(response, { useProtoFieldName: true, - emitDefaultValues: false + emitDefaultValues: false, })); }); } @@ -7085,14 +7460,14 @@ function handleArtifactServiceFinalizeArtifactJSON(ctx, service, data, intercept let request; let response; try { - const body = JSON.parse(data.toString() || '{}'); + const body = JSON.parse(data.toString() || "{}"); request = artifact_1.FinalizeArtifactRequest.fromJson(body, { - ignoreUnknownFields: true + ignoreUnknownFields: true, }); } catch (e) { if (e instanceof Error) { - const msg = 'the json request could not be decoded'; + const msg = "the json request could not be decoded"; throw new twirp_ts_1.TwirpError(twirp_ts_1.TwirpErrorCode.Malformed, msg).withCause(e, true); } } @@ -7107,7 +7482,69 @@ function handleArtifactServiceFinalizeArtifactJSON(ctx, service, data, intercept } return JSON.stringify(artifact_1.FinalizeArtifactResponse.toJson(response, { useProtoFieldName: true, - emitDefaultValues: false + emitDefaultValues: false, + })); + }); +} +function handleArtifactServiceListArtifactsJSON(ctx, service, data, interceptors) { + return __awaiter(this, void 0, void 0, function* () { + let request; + let response; + try { + const body = JSON.parse(data.toString() || "{}"); + request = artifact_1.ListArtifactsRequest.fromJson(body, { + ignoreUnknownFields: true, + }); + } + catch (e) { + if (e instanceof Error) { + const msg = "the json request could not be decoded"; + throw new twirp_ts_1.TwirpError(twirp_ts_1.TwirpErrorCode.Malformed, msg).withCause(e, true); + } + } + if (interceptors && interceptors.length > 0) { + const interceptor = (0, twirp_ts_1.chainInterceptors)(...interceptors); + response = yield interceptor(ctx, request, (ctx, inputReq) => { + return service.ListArtifacts(ctx, inputReq); + }); + } + else { + response = yield service.ListArtifacts(ctx, request); + } + return JSON.stringify(artifact_1.ListArtifactsResponse.toJson(response, { + useProtoFieldName: true, + emitDefaultValues: false, + })); + }); +} +function handleArtifactServiceGetSignedArtifactURLJSON(ctx, service, data, interceptors) { + return __awaiter(this, void 0, void 0, function* () { + let request; + let response; + try { + const body = JSON.parse(data.toString() || "{}"); + request = artifact_1.GetSignedArtifactURLRequest.fromJson(body, { + ignoreUnknownFields: true, + }); + } + catch (e) { + if (e instanceof Error) { + const msg = "the json request could not be decoded"; + throw new twirp_ts_1.TwirpError(twirp_ts_1.TwirpErrorCode.Malformed, msg).withCause(e, true); + } + } + if (interceptors && interceptors.length > 0) { + const interceptor = (0, twirp_ts_1.chainInterceptors)(...interceptors); + response = yield interceptor(ctx, request, (ctx, inputReq) => { + return service.GetSignedArtifactURL(ctx, inputReq); + }); + } + else { + response = yield service.GetSignedArtifactURL(ctx, request); + } + return JSON.stringify(artifact_1.GetSignedArtifactURLResponse.toJson(response, { + useProtoFieldName: true, + emitDefaultValues: false, })); }); } @@ -7120,7 +7557,7 @@ function handleArtifactServiceCreateArtifactProtobuf(ctx, service, data, interce } catch (e) { if (e instanceof Error) { - const msg = 'the protobuf request could not be decoded'; + const msg = "the protobuf request could not be decoded"; throw new twirp_ts_1.TwirpError(twirp_ts_1.TwirpErrorCode.Malformed, msg).withCause(e, true); } } @@ -7145,7 +7582,7 @@ function handleArtifactServiceFinalizeArtifactProtobuf(ctx, service, data, inter } catch (e) { if (e instanceof Error) { - const msg = 'the protobuf request could not be decoded'; + const msg = "the protobuf request could not be decoded"; throw new twirp_ts_1.TwirpError(twirp_ts_1.TwirpErrorCode.Malformed, msg).withCause(e, true); } } @@ -7161,6 +7598,56 @@ function handleArtifactServiceFinalizeArtifactProtobuf(ctx, service, data, inter return Buffer.from(artifact_1.FinalizeArtifactResponse.toBinary(response)); }); } +function handleArtifactServiceListArtifactsProtobuf(ctx, service, data, interceptors) { + return __awaiter(this, void 0, void 0, function* () { + let request; + let response; + try { + request = artifact_1.ListArtifactsRequest.fromBinary(data); + } + catch (e) { + if (e instanceof Error) { + const msg = "the protobuf request could not be decoded"; + throw new twirp_ts_1.TwirpError(twirp_ts_1.TwirpErrorCode.Malformed, msg).withCause(e, true); + } + } + if (interceptors && interceptors.length > 0) { + const interceptor = (0, twirp_ts_1.chainInterceptors)(...interceptors); + response = yield interceptor(ctx, request, (ctx, inputReq) => { + return service.ListArtifacts(ctx, inputReq); + }); + } + else { + response = yield service.ListArtifacts(ctx, request); + } + return Buffer.from(artifact_1.ListArtifactsResponse.toBinary(response)); + }); +} +function handleArtifactServiceGetSignedArtifactURLProtobuf(ctx, service, data, interceptors) { + return __awaiter(this, void 0, void 0, function* () { + let request; + let response; + try { + request = artifact_1.GetSignedArtifactURLRequest.fromBinary(data); + } + catch (e) { + if (e instanceof Error) { + const msg = "the protobuf request could not be decoded"; + throw new twirp_ts_1.TwirpError(twirp_ts_1.TwirpErrorCode.Malformed, msg).withCause(e, true); + } + } + if (interceptors && interceptors.length > 0) { + const interceptor = (0, twirp_ts_1.chainInterceptors)(...interceptors); + response = yield interceptor(ctx, request, (ctx, inputReq) => { + return service.GetSignedArtifactURL(ctx, inputReq); + }); + } + else { + response = yield service.GetSignedArtifactURL(ctx, request); + } + return Buffer.from(artifact_1.GetSignedArtifactURLResponse.toBinary(response)); + }); +} //# sourceMappingURL=artifact.twirp.js.map /***/ }), @@ -7179,6 +7666,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.Client = void 0; const core_1 = __nccwpck_require__(66526); @@ -7223,7 +7721,7 @@ If the error persists, please check whether Actions is operating normally at [ht /** * Download Artifact */ - downloadArtifact(artifactId, repositoryOwner, repositoryName, token, options) { + 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.`); @@ -7232,7 +7730,11 @@ If the error persists, please check whether Actions is operating normally at [ht }; } try { - return (0, download_artifact_1.downloadArtifact)(artifactId, repositoryOwner, repositoryName, token, options); + 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); + } + return (0, download_artifact_1.downloadArtifactInternal)(artifactId, options); } catch (error) { (0, core_1.warning)(`Artifact download failed with error: ${error}. @@ -7249,7 +7751,7 @@ If the error persists, please check whether Actions and API requests are operati /** * List Artifacts */ - listArtifacts(workflowRunId, repositoryOwner, repositoryName, token) { + 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.`); @@ -7258,7 +7760,11 @@ If the error persists, please check whether Actions and API requests are operati }; } try { - return (0, list_artifacts_1.listArtifacts)(workflowRunId, repositoryOwner, repositoryName, token); + 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.listArtifactsInternal)(); } catch (error) { (0, core_1.warning)(`Listing Artifacts failed with error: ${error}. @@ -7275,7 +7781,7 @@ If the error persists, please check whether Actions and API requests are operati /** * Get Artifact */ - getArtifact(artifactName, workflowRunId, repositoryOwner, repositoryName, token) { + 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.`); @@ -7284,7 +7790,11 @@ If the error persists, please check whether Actions and API requests are operati }; } try { - return (0, get_artifact_1.getArtifact)(artifactName, workflowRunId, repositoryOwner, repositoryName, token); + 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); + } + return (0, get_artifact_1.getArtifactInternal)(artifactName); } catch (error) { (0, core_1.warning)(`Fetching Artifact failed with error: ${error}. @@ -7345,7 +7855,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.downloadArtifact = void 0; +exports.downloadArtifactInternal = exports.downloadArtifactPublic = void 0; const promises_1 = __importDefault(__nccwpck_require__(73292)); const github = __importStar(__nccwpck_require__(51132)); const core = __importStar(__nccwpck_require__(66526)); @@ -7353,6 +7863,9 @@ const httpClient = __importStar(__nccwpck_require__(52932)); 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); parsed.search = ''; @@ -7384,16 +7897,9 @@ function streamExtract(url, directory) { return response.message.pipe(unzipper_1.default.Extract({ path: directory })).promise(); }); } -function downloadArtifact(artifactId, repositoryOwner, repositoryName, token, options) { +function downloadArtifactPublic(artifactId, repositoryOwner, repositoryName, token, options) { return __awaiter(this, void 0, void 0, function* () { - const downloadPath = (options === null || options === void 0 ? void 0 : options.path) || (0, config_1.getGitHubWorkspaceDir)(); - if (!(yield exists(downloadPath))) { - core.debug(`Artifact destination folder does not exist, creating: ${downloadPath}`); - yield promises_1.default.mkdir(downloadPath, { recursive: true }); - } - else { - core.debug(`Artifact destination folder already exists: ${downloadPath}`); - } + const downloadPath = yield resolveOrCreateDirectory(options === null || options === void 0 ? void 0 : options.path); const api = github.getOctokit(token); core.info(`Downloading artifact '${artifactId}' from '${repositoryOwner}/${repositoryName}'`); const { headers, status } = yield api.rest.actions.downloadArtifact({ @@ -7424,7 +7930,56 @@ function downloadArtifact(artifactId, repositoryOwner, repositoryName, token, op return { success: true, downloadPath }; }); } -exports.downloadArtifact = downloadArtifact; +exports.downloadArtifactPublic = downloadArtifactPublic; +function downloadArtifactInternal(artifactId, options) { + return __awaiter(this, void 0, void 0, function* () { + const downloadPath = yield resolveOrCreateDirectory(options === null || options === void 0 ? void 0 : options.path); + const artifactClient = (0, artifact_twirp_client_1.internalArtifactTwirpClient)(); + const { workflowRunBackendId, workflowJobRunBackendId } = (0, util_1.getBackendIdsFromToken)(); + const listReq = { + workflowRunBackendId, + workflowJobRunBackendId, + idFilter: generated_1.Int64Value.create({ value: artifactId.toString() }) + }; + 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 }; + } + if (artifacts.length > 1) { + core.warning('Multiple artifacts found, defaulting to first.'); + } + const signedReq = { + workflowRunBackendId: artifacts[0].workflowRunBackendId, + workflowJobRunBackendId: artifacts[0].workflowJobRunBackendId, + name: artifacts[0].name + }; + const { signedUrl } = yield artifactClient.GetSignedArtifactURL(signedReq); + core.info(`Redirecting to blob download url: ${scrubQueryParameters(signedUrl)}`); + try { + core.info(`Starting download of artifact to: ${downloadPath}`); + yield streamExtract(signedUrl, downloadPath); + core.info(`Artifact download completed successfully.`); + } + catch (error) { + throw new Error(`Unable to download and extract artifact: ${error.message}`); + } + return { success: true, downloadPath }; + }); +} +exports.downloadArtifactInternal = downloadArtifactInternal; +function resolveOrCreateDirectory(downloadPath = (0, config_1.getGitHubWorkspaceDir)()) { + return __awaiter(this, void 0, void 0, function* () { + if (!(yield exists(downloadPath))) { + core.debug(`Artifact destination folder does not exist, creating: ${downloadPath}`); + yield promises_1.default.mkdir(downloadPath, { recursive: true }); + } + else { + core.debug(`Artifact destination folder already exists: ${downloadPath}`); + } + return downloadPath; + }); +} //# sourceMappingURL=download-artifact.js.map /***/ }), @@ -7467,15 +8022,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.getArtifact = void 0; +exports.getArtifactInternal = exports.getArtifactPublic = void 0; const github_1 = __nccwpck_require__(51132); -const user_agent_1 = __nccwpck_require__(79681); +const plugin_retry_1 = __nccwpck_require__(69980); +const core = __importStar(__nccwpck_require__(66526)); const utils_1 = __nccwpck_require__(43129); const retry_options_1 = __nccwpck_require__(80722); const plugin_request_log_1 = __nccwpck_require__(73665); -const plugin_retry_1 = __nccwpck_require__(69980); -const core = __importStar(__nccwpck_require__(66526)); -function getArtifact(artifactName, workflowRunId, repositoryOwner, repositoryName, token) { +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); +function getArtifactPublic(artifactName, workflowRunId, repositoryOwner, repositoryName, token) { return __awaiter(this, void 0, void 0, function* () { const [retryOpts, requestOpts] = (0, retry_options_1.getRetryOptions)(utils_1.defaults); const opts = { @@ -7512,13 +8070,46 @@ function getArtifact(artifactName, workflowRunId, repositoryOwner, repositoryNam artifact: { name: getArtifactResp.data.artifacts[0].name, id: getArtifactResp.data.artifacts[0].id, - url: getArtifactResp.data.artifacts[0].url, size: getArtifactResp.data.artifacts[0].size_in_bytes } }; }); } -exports.getArtifact = getArtifact; +exports.getArtifactPublic = getArtifactPublic; +function getArtifactInternal(artifactName) { + return __awaiter(this, void 0, void 0, function* () { + const artifactClient = (0, artifact_twirp_client_1.internalArtifactTwirpClient)(); + const { workflowRunBackendId, workflowJobRunBackendId } = (0, util_1.getBackendIdsFromToken)(); + const req = { + workflowRunBackendId, + workflowJobRunBackendId, + nameFilter: generated_1.StringValue.create({ value: artifactName }) + }; + const res = yield artifactClient.ListArtifacts(req); + if (res.artifacts.length === 0) { + core.warning('no artifacts found'); + return { + success: false + }; + } + if (res.artifacts.length > 1) { + 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) + } + }; + }); +} +exports.getArtifactInternal = getArtifactInternal; //# sourceMappingURL=get-artifact.js.map /***/ }), @@ -7538,7 +8129,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.listArtifacts = void 0; +exports.listArtifactsInternal = exports.listArtifactsPublic = void 0; const core_1 = __nccwpck_require__(66526); const github_1 = __nccwpck_require__(51132); const user_agent_1 = __nccwpck_require__(79681); @@ -7546,11 +8137,13 @@ const retry_options_1 = __nccwpck_require__(80722); const utils_1 = __nccwpck_require__(43129); 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); // Limiting to 1000 for perf reasons const maximumArtifactCount = 1000; const paginationCount = 100; const maxNumberOfPages = maximumArtifactCount / paginationCount; -function listArtifacts(workflowRunId, repositoryOwner, repositoryName, token) { +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}`); const artifacts = []; @@ -7582,7 +8175,6 @@ function listArtifacts(workflowRunId, repositoryOwner, repositoryName, token) { artifacts.push({ name: artifact.name, id: artifact.id, - url: artifact.url, size: artifact.size_in_bytes }); } @@ -7601,18 +8193,38 @@ function listArtifacts(workflowRunId, repositoryOwner, repositoryName, token) { artifacts.push({ name: artifact.name, id: artifact.id, - url: artifact.url, size: artifact.size_in_bytes }); } } - (0, core_1.info)(`Finished fetching artifact list`); + (0, core_1.info)(`Found ${artifacts.length} artifact(s)`); return { artifacts }; }); } -exports.listArtifacts = listArtifacts; +exports.listArtifactsPublic = listArtifactsPublic; +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)(); + const req = { + workflowRunBackendId, + workflowJobRunBackendId + }; + const res = yield artifactClient.ListArtifacts(req); + const artifacts = res.artifacts.map(artifact => ({ + name: artifact.name, + id: Number(artifact.databaseId), + size: Number(artifact.size) + })); + (0, core_1.info)(`Found ${artifacts.length} artifact(s)`); + return { + artifacts + }; + }); +} +exports.listArtifactsInternal = listArtifactsInternal; //# sourceMappingURL=list-artifacts.js.map /***/ }), @@ -7689,12 +8301,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.createArtifactTwirpClient = void 0; +exports.internalArtifactTwirpClient = void 0; const http_client_1 = __nccwpck_require__(52932); const auth_1 = __nccwpck_require__(40903); const core_1 = __nccwpck_require__(66526); const generated_1 = __nccwpck_require__(90265); const config_1 = __nccwpck_require__(95042); +const user_agent_1 = __nccwpck_require__(79681); class ArtifactHttpClient { constructor(userAgent, maxAttempts, baseRetryIntervalMilliseconds, retryMultiplier) { this.maxAttempts = 5; @@ -7720,7 +8333,7 @@ class ArtifactHttpClient { request(service, method, contentType, data) { return __awaiter(this, void 0, void 0, function* () { const url = new URL(`/twirp/${service}/${method}`, this.baseUrl).href; - (0, core_1.debug)(`Requesting: ${url}`); + (0, core_1.debug)(`[Request] ${method} ${url}`); const headers = { 'Content-Type': contentType }; @@ -7743,6 +8356,8 @@ 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)); if (this.isSuccessStatusCode(statusCode)) { return response; } @@ -7803,11 +8418,11 @@ class ArtifactHttpClient { return Math.trunc(Math.random() * (maxTime - minTime) + minTime); } } -function createArtifactTwirpClient(type, maxAttempts, baseRetryIntervalMilliseconds, retryMultiplier) { - const client = new ArtifactHttpClient(`@actions/artifact-${type}`, maxAttempts, baseRetryIntervalMilliseconds, retryMultiplier); +function internalArtifactTwirpClient(options) { + const client = new ArtifactHttpClient((0, user_agent_1.getUserAgentString)(), options === null || options === void 0 ? void 0 : options.maxAttempts, options === null || options === void 0 ? void 0 : options.retryIntervalMs, options === null || options === void 0 ? void 0 : options.retryMultiplier); return new generated_1.ArtifactServiceClientJSON(client); } -exports.createArtifactTwirpClient = createArtifactTwirpClient; +exports.internalArtifactTwirpClient = internalArtifactTwirpClient; //# sourceMappingURL=artifact-twirp-client.js.map /***/ }), @@ -7909,14 +8524,38 @@ exports.getUserAgentString = getUserAgentString; "use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", ({ value: true })); exports.getBackendIdsFromToken = void 0; +const core = __importStar(__nccwpck_require__(66526)); const config_1 = __nccwpck_require__(95042); const jwt_decode_1 = __importDefault(__nccwpck_require__(25582)); -const InvalidJwtError = new Error('Failed to get backend IDs: The provided JWT token is invalid'); +const InvalidJwtError = new Error('Failed to get backend IDs: The provided JWT token is invalid and/or missing claims'); // uses the JWT token claims to get the // workflow run and workflow job run backend ids function getBackendIdsFromToken() { @@ -7941,22 +8580,25 @@ function getBackendIdsFromToken() { */ for (const scopes of scpParts) { const scopeParts = scopes.split(':'); + if ((scopeParts === null || scopeParts === void 0 ? void 0 : scopeParts[0]) !== 'Actions.Results') { + // not the Actions.Results scope + continue; + } /* * example scopeParts: * ["Actions.Results", "ce7f54c7-61c7-4aae-887f-30da475f5f1a", "ca395085-040a-526b-2ce8-bdc85f692774"] */ if (scopeParts.length !== 3) { - // not the Actions.Results scope - continue; + // missing expected number of claims + throw InvalidJwtError; } - if (scopeParts[0] !== 'Actions.Results') { - // not the Actions.Results scope - continue; - } - return { + const ids = { workflowRunBackendId: scopeParts[1], workflowJobRunBackendId: scopeParts[2] }; + core.debug(`Workflow Run Backend ID: ${ids.workflowRunBackendId}`); + core.debug(`Workflow Job Run Backend ID: ${ids.workflowJobRunBackendId}`); + return ids; } throw InvalidJwtError; } @@ -8259,16 +8901,8 @@ function uploadArtifact(name, files, rootDirectory, options) { 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)(); - if (!backendIds.workflowRunBackendId || !backendIds.workflowJobRunBackendId) { - core.warning(`Failed to get the necessary backend ids which are required to create the artifact`); - return { - success: false - }; - } - core.debug(`Workflow Run Backend ID: ${backendIds.workflowRunBackendId}`); - core.debug(`Workflow Job Run Backend ID: ${backendIds.workflowJobRunBackendId}`); // create the artifact client - const artifactClient = (0, artifact_twirp_client_1.createArtifactTwirpClient)('upload'); + const artifactClient = (0, artifact_twirp_client_1.internalArtifactTwirpClient)(); // create the artifact const createArtifactReq = { workflowRunBackendId: backendIds.workflowRunBackendId, @@ -118711,9 +119345,9 @@ function run() { const inputs = { name: core.getInput(constants_1.Inputs.Name, { required: false }), path: core.getInput(constants_1.Inputs.Path, { required: false }), - token: core.getInput(constants_1.Inputs.GitHubToken, { required: true }), - repository: core.getInput(constants_1.Inputs.Repository, { required: true }), - runID: parseInt(core.getInput(constants_1.Inputs.RunID, { required: true })) + token: core.getInput(constants_1.Inputs.GitHubToken, { required: false }), + repository: core.getInput(constants_1.Inputs.Repository, { required: false }), + runID: parseInt(core.getInput(constants_1.Inputs.RunID, { required: false })) }; if (!inputs.path) { inputs.path = process.env['GITHUB_WORKSPACE'] || process.cwd(); @@ -118724,15 +119358,24 @@ function run() { const isSingleArtifactDownload = !!inputs.name; const resolvedPath = path.resolve(inputs.path); core.debug(`Resolved path is ${resolvedPath}`); - const [owner, repo] = inputs.repository.split('/'); - if (!owner || !repo) { - throw new Error(`Invalid repository: '${inputs.repository}'. Must be in format owner/repo`); + const options = {}; + if (inputs.token) { + const [repositoryOwner, repositoryName] = inputs.repository.split('/'); + if (!repositoryOwner || !repositoryName) { + throw new Error(`Invalid repository: '${inputs.repository}'. Must be in format owner/repo`); + } + options.findBy = { + token: inputs.token, + workflowRunId: inputs.runID, + repositoryName, + repositoryOwner + }; } const artifactClient = artifact.create(); let artifacts = []; if (isSingleArtifactDownload) { core.info(`Downloading single artifact`); - const { artifact: targetArtifact } = yield artifactClient.getArtifact(inputs.name, inputs.runID, owner, repo, inputs.token); + const { artifact: targetArtifact } = yield artifactClient.getArtifact(inputs.name, options); if (!targetArtifact) { throw new Error(`Artifact '${inputs.name}' not found`); } @@ -118741,16 +119384,16 @@ 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(inputs.runID, owner, repo, inputs.token); + 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`); artifacts = listArtifactResponse.artifacts; } - const downloadPromises = artifacts.map(artifact => artifactClient.downloadArtifact(artifact.id, owner, repo, inputs.token, { - path: isSingleArtifactDownload ? resolvedPath : path.join(resolvedPath, artifact.name) - })); + const downloadPromises = artifacts.map(artifact => artifactClient.downloadArtifact(artifact.id, Object.assign(Object.assign({}, options), { path: isSingleArtifactDownload + ? resolvedPath + : path.join(resolvedPath, artifact.name) }))); const chunkedPromises = exports.chunk(downloadPromises, PARALLEL_DOWNLOADS); for (const chunk of chunkedPromises) { yield Promise.all(chunk); @@ -119017,7 +119660,7 @@ module.exports = JSON.parse('[[[0,44],"disallowed_STD3_valid"],[[45,46],"valid"] /***/ ((module) => { "use strict"; -module.exports = JSON.parse('{"name":"@actions/artifact","version":"2.0.0","preview":true,"description":"Actions artifact lib","keywords":["github","actions","artifact"],"homepage":"https://github.com/actions/toolkit/tree/main/packages/artifact","license":"MIT","main":"lib/artifact.js","types":"lib/artifact.d.ts","directories":{"lib":"lib","test":"__tests__"},"files":["lib","!.DS_Store"],"publishConfig":{"access":"public"},"repository":{"type":"git","url":"git+https://github.com/actions/toolkit.git","directory":"packages/artifact"},"scripts":{"audit-moderate":"npm install && npm audit --json --audit-level=moderate > audit.json","test":"echo \\"Error: run tests from root\\" && exit 1","bootstrap":"cd ../../ && npm run bootstrap","tsc-run":"tsc","tsc":"npm run bootstrap && npm run tsc-run"},"bugs":{"url":"https://github.com/actions/toolkit/issues"},"dependencies":{"@actions/core":"^1.10.0","@actions/github":"^5.1.1","@actions/http-client":"^2.1.0","@azure/storage-blob":"^12.15.0","@octokit/core":"^3.5.1","@octokit/plugin-request-log":"^1.0.4","@octokit/plugin-retry":"^3.0.9","@octokit/request-error":"^5.0.0","@protobuf-ts/plugin":"^2.2.3-alpha.1","@types/unzipper":"^0.10.6","archiver":"^5.3.1","crypto":"^1.0.1","jwt-decode":"^3.1.2","twirp-ts":"^2.5.0","unzipper":"^0.10.14"},"devDependencies":{"@types/archiver":"^5.3.2","typescript":"^5.2.2"}}'); +module.exports = JSON.parse('{"name":"@actions/artifact","version":"2.0.0","preview":true,"description":"Actions artifact lib","keywords":["github","actions","artifact"],"homepage":"https://github.com/actions/toolkit/tree/main/packages/artifact","license":"MIT","main":"lib/artifact.js","types":"lib/artifact.d.ts","directories":{"lib":"lib","test":"__tests__"},"files":["lib","!.DS_Store"],"publishConfig":{"access":"public"},"repository":{"type":"git","url":"git+https://github.com/actions/toolkit.git","directory":"packages/artifact"},"scripts":{"audit-moderate":"npm install && npm audit --json --audit-level=moderate > audit.json","test":"cd ../../ && npm run test ./packages/artifact","bootstrap":"cd ../../ && npm run bootstrap","tsc-run":"tsc","tsc":"npm run bootstrap && npm run tsc-run"},"bugs":{"url":"https://github.com/actions/toolkit/issues"},"dependencies":{"@actions/core":"^1.10.0","@actions/github":"^5.1.1","@actions/http-client":"^2.1.0","@azure/storage-blob":"^12.15.0","@octokit/core":"^3.5.1","@octokit/plugin-request-log":"^1.0.4","@octokit/plugin-retry":"^3.0.9","@octokit/request-error":"^5.0.0","@protobuf-ts/plugin":"^2.2.3-alpha.1","@types/unzipper":"^0.10.6","archiver":"^5.3.1","crypto":"^1.0.1","jwt-decode":"^3.1.2","twirp-ts":"^2.5.0","unzipper":"^0.10.14"},"devDependencies":{"@types/archiver":"^5.3.2","typescript":"^5.2.2"}}'); /***/ }) diff --git a/src/download-artifact.ts b/src/download-artifact.ts index 778f899..c8fff56 100644 --- a/src/download-artifact.ts +++ b/src/download-artifact.ts @@ -17,9 +17,9 @@ async function run(): Promise { const inputs = { name: core.getInput(Inputs.Name, {required: false}), path: core.getInput(Inputs.Path, {required: false}), - token: core.getInput(Inputs.GitHubToken, {required: true}), - repository: core.getInput(Inputs.Repository, {required: true}), - runID: parseInt(core.getInput(Inputs.RunID, {required: true})) + token: core.getInput(Inputs.GitHubToken, {required: false}), + repository: core.getInput(Inputs.Repository, {required: false}), + runID: parseInt(core.getInput(Inputs.RunID, {required: false})) } if (!inputs.path) { @@ -30,15 +30,25 @@ async function run(): Promise { inputs.path = inputs.path.replace('~', os.homedir()) } - const isSingleArtifactDownload: boolean = !!inputs.name + const isSingleArtifactDownload = !!inputs.name const resolvedPath = path.resolve(inputs.path) core.debug(`Resolved path is ${resolvedPath}`) - const [owner, repo] = inputs.repository.split('/') - if (!owner || !repo) { - throw new Error( - `Invalid repository: '${inputs.repository}'. Must be in format owner/repo` - ) + const options: artifact.FindOptions = {} + if (inputs.token) { + const [repositoryOwner, repositoryName] = inputs.repository.split('/') + if (!repositoryOwner || !repositoryName) { + throw new Error( + `Invalid repository: '${inputs.repository}'. Must be in format owner/repo` + ) + } + + options.findBy = { + token: inputs.token, + workflowRunId: inputs.runID, + repositoryName, + repositoryOwner + } } const artifactClient = artifact.create() @@ -49,10 +59,7 @@ async function run(): Promise { const {artifact: targetArtifact} = await artifactClient.getArtifact( inputs.name, - inputs.runID, - owner, - repo, - inputs.token + options ) if (!targetArtifact) { @@ -65,15 +72,12 @@ async function run(): Promise { 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( - inputs.runID, - owner, - repo, - inputs.token + 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(options) + if (listArtifactResponse.artifacts.length === 0) { throw new Error( `No artifacts found for run '${inputs.runID}' in '${inputs.repository}'` @@ -85,8 +89,11 @@ async function run(): Promise { } const downloadPromises = artifacts.map(artifact => - artifactClient.downloadArtifact(artifact.id, owner, repo, inputs.token, { - path: isSingleArtifactDownload ? resolvedPath : path.join(resolvedPath, artifact.name) + artifactClient.downloadArtifact(artifact.id, { + ...options, + path: isSingleArtifactDownload + ? resolvedPath + : path.join(resolvedPath, artifact.name) }) ) From 0742efc19be9b56956fabc269755e8d64585ff1a Mon Sep 17 00:00:00 2001 From: Rob Herley Date: Mon, 4 Dec 2023 13:08:24 -0500 Subject: [PATCH 2/2] set new 'latest' attribute for list operations --- dist/index.js | 84 ++++++++++++++++++++++++++++++---------- src/download-artifact.ts | 5 ++- 2 files changed, 67 insertions(+), 22 deletions(-) diff --git a/dist/index.js b/dist/index.js index 18f2555..d69cf65 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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}'`); } diff --git a/src/download-artifact.ts b/src/download-artifact.ts index c8fff56..23c7132 100644 --- a/src/download-artifact.ts +++ b/src/download-artifact.ts @@ -76,7 +76,10 @@ async function run(): Promise { `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(