From 83b889d09d0249b550dc07bfd524318084bfdd6b Mon Sep 17 00:00:00 2001 From: Rob Herley Date: Mon, 4 Dec 2023 15:40:37 -0500 Subject: [PATCH] consume latest @actions/artifact --- dist/index.js | 868 ++++++++++++++++++++++++++++++++++++----- src/upload-artifact.ts | 4 +- 2 files changed, 774 insertions(+), 98 deletions(-) diff --git a/dist/index.js b/dist/index.js index 0906d58..c190e52 100644 --- a/dist/index.js +++ b/dist/index.js @@ -3960,7 +3960,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 @@ -3971,6 +3971,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 { @@ -4109,7 +4110,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) { @@ -4137,7 +4138,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; @@ -4165,7 +4166,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); @@ -4230,12 +4231,319 @@ 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*/ }, + { no: 6, name: "created_at", kind: "message", T: () => timestamp_1.Timestamp } + ]); + } + 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; + 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") + 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); + /* 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); + 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 @@ -4264,23 +4572,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, })); } } @@ -4290,16 +4620,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; @@ -4307,35 +4649,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`; @@ -4349,7 +4707,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); } } @@ -4360,7 +4718,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); } } @@ -4369,12 +4749,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); } } @@ -4389,7 +4771,7 @@ function handleArtifactServiceCreateArtifactJSON(ctx, service, data, interceptor } return JSON.stringify(artifact_1.CreateArtifactResponse.toJson(response, { useProtoFieldName: true, - emitDefaultValues: false + emitDefaultValues: false, })); }); } @@ -4398,14 +4780,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); } } @@ -4420,7 +4802,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, })); }); } @@ -4433,7 +4877,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); } } @@ -4458,7 +4902,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); } } @@ -4474,6 +4918,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 /***/ }), @@ -4492,6 +4986,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); @@ -4536,7 +5041,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.`); @@ -4545,7 +5050,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}. @@ -4562,7 +5071,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.`); @@ -4571,7 +5080,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, options === null || options === void 0 ? void 0 : options.latest); + } + 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}. @@ -4588,7 +5101,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.`); @@ -4597,7 +5110,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}. @@ -4658,7 +5175,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)); @@ -4666,6 +5183,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 = ''; @@ -4697,16 +5217,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({ @@ -4737,7 +5250,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 /***/ }), @@ -4780,15 +5342,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 = { @@ -4817,21 +5382,58 @@ function getArtifact(artifactName, workflowRunId, repositoryOwner, repositoryNam 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, - url: getArtifactResp.data.artifacts[0].url, - 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 } }; }); } -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 + }; + } + 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})`); + } + 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 + } + }; + }); +} +exports.getArtifactInternal = getArtifactInternal; //# sourceMappingURL=get-artifact.js.map /***/ }), @@ -4851,7 +5453,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); @@ -4859,14 +5461,17 @@ 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); +const generated_1 = __nccwpck_require__(90265); // 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, 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, @@ -4895,8 +5500,8 @@ function listArtifacts(workflowRunId, repositoryOwner, repositoryName, token) { artifacts.push({ name: artifact.name, id: artifact.id, - url: artifact.url, - 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 @@ -4914,18 +5519,67 @@ function listArtifacts(workflowRunId, repositoryOwner, repositoryName, token) { artifacts.push({ name: artifact.name, id: artifact.id, - url: artifact.url, - size: artifact.size_in_bytes + size: artifact.size_in_bytes, + createdAt: artifact.created_at + ? new Date(artifact.created_at) + : undefined }); } } - (0, core_1.info)(`Finished fetching artifact list`); + if (latest) { + artifacts = filterLatest(artifacts); + } + (0, core_1.info)(`Found ${artifacts.length} artifact(s)`); return { artifacts }; }); } -exports.listArtifacts = listArtifacts; +exports.listArtifactsPublic = listArtifactsPublic; +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)(); + const req = { + workflowRunBackendId, + workflowJobRunBackendId + }; + const res = yield artifactClient.ListArtifacts(req); + let 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 + })); + if (latest) { + artifacts = filterLatest(artifacts); + } + (0, core_1.info)(`Found ${artifacts.length} artifact(s)`); + return { + artifacts + }; + }); +} +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 /***/ }), @@ -5002,12 +5656,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; @@ -5033,7 +5688,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 }; @@ -5056,6 +5711,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; } @@ -5116,11 +5773,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 /***/ }), @@ -5222,14 +5879,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() { @@ -5254,22 +5935,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; } @@ -5572,16 +6256,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, @@ -121712,7 +122388,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/upload-artifact.ts b/src/upload-artifact.ts index 896929d..e635d27 100644 --- a/src/upload-artifact.ts +++ b/src/upload-artifact.ts @@ -1,6 +1,6 @@ import * as core from '../node_modules/@actions/core/' import { - UploadOptions, + UploadArtifactOptions, create } from '../node_modules/@actions/artifact/lib/artifact' import {findFilesToUpload} from './search' @@ -41,7 +41,7 @@ async function run(): Promise { core.debug(`Root artifact directory is ${searchResult.rootDirectory}`) const artifactClient = create() - const options: UploadOptions = {} + const options: UploadArtifactOptions = {} if (inputs.retentionDays) { options.retentionDays = inputs.retentionDays }