diff --git a/action.yml b/action.yml index 898a840..7b37ab7 100644 --- a/action.yml +++ b/action.yml @@ -9,21 +9,23 @@ 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: download-path: description: 'Path of artifact download' runs: - using: 'node16' + using: 'node20' main: 'dist/index.js' diff --git a/dist/index.js b/dist/index.js index 76b0501..6ad7d95 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); } 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,8 @@ 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 util_1 = __nccwpck_require__(80565); const scrubQueryParameters = (url) => { const parsed = new URL(url); parsed.search = ''; @@ -7384,16 +7896,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 +7929,55 @@ 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 + }; + 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 +8020,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 +8068,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 +8127,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 +8135,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 +8173,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 +8191,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 +8299,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; @@ -7719,8 +8330,8 @@ class ArtifactHttpClient { // JSON generated client. request(service, method, contentType, data) { return __awaiter(this, void 0, void 0, function* () { - const url = `${this.baseUrl}/twirp/${service}/${method}`; - (0, core_1.debug)(`Requesting ${url}`); + const url = new URL(`/twirp/${service}/${method}`, this.baseUrl).href; + (0, core_1.debug)(`[Request] ${method} ${url}`); const headers = { 'Content-Type': contentType }; @@ -7743,6 +8354,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,22 +8416,26 @@ 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 /***/ }), /***/ 95042: -/***/ ((__unused_webpack_module, exports) => { +/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { "use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.getGitHubWorkspaceDir = exports.isGhes = exports.getResultsServiceUrl = exports.getRuntimeToken = exports.getUploadChunkSize = void 0; +exports.getConcurrency = exports.getGitHubWorkspaceDir = exports.isGhes = exports.getResultsServiceUrl = exports.getRuntimeToken = exports.getUploadChunkSize = void 0; +const os_1 = __importDefault(__nccwpck_require__(22037)); // Used for controlling the highWaterMark value of the zip that is being streamed // The same value is used as the chunk size that is use during upload to blob storage function getUploadChunkSize() { @@ -7838,7 +8455,7 @@ function getResultsServiceUrl() { if (!resultsUrl) { throw new Error('Unable to get the ACTIONS_RESULTS_URL env variable'); } - return resultsUrl; + return new URL(resultsUrl).origin; } exports.getResultsServiceUrl = getResultsServiceUrl; function isGhes() { @@ -7854,6 +8471,18 @@ function getGitHubWorkspaceDir() { return ghWorkspaceDir; } exports.getGitHubWorkspaceDir = getGitHubWorkspaceDir; +// Mimics behavior of azcopy: https://learn.microsoft.com/en-us/azure/storage/common/storage-use-azcopy-optimize +// If your machine has fewer than 5 CPUs, then the value of this variable is set to 32. +// Otherwise, the default value is equal to 16 multiplied by the number of CPUs. The maximum value of this variable is 300. +function getConcurrency() { + const numCPUs = os_1.default.cpus().length; + if (numCPUs <= 4) { + return 32; + } + const concurrency = 16 * numCPUs; + return concurrency > 300 ? 300 : concurrency; +} +exports.getConcurrency = getConcurrency; //# sourceMappingURL=config.js.map /***/ }), @@ -7893,14 +8522,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() { @@ -7925,22 +8578,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; } @@ -7996,11 +8652,11 @@ const stream = __importStar(__nccwpck_require__(12781)); function uploadZipToBlobStorage(authenticatedUploadURL, zipUploadStream) { return __awaiter(this, void 0, void 0, function* () { let uploadByteCount = 0; - const maxBuffers = 5; + const maxConcurrency = (0, config_1.getConcurrency)(); const bufferSize = (0, config_1.getUploadChunkSize)(); const blobClient = new storage_blob_1.BlobClient(authenticatedUploadURL); const blockBlobClient = blobClient.getBlockBlobClient(); - core.debug(`Uploading artifact zip to blob storage with maxBuffers: ${maxBuffers}, bufferSize: ${bufferSize}`); + core.debug(`Uploading artifact zip to blob storage with maxConcurrency: ${maxConcurrency}, bufferSize: ${bufferSize}`); const uploadCallback = (progress) => { core.info(`Uploaded bytes ${progress.loadedBytes}`); uploadByteCount = progress.loadedBytes; @@ -8016,7 +8672,7 @@ function uploadZipToBlobStorage(authenticatedUploadURL, zipUploadStream) { zipUploadStream.pipe(hashStream).setEncoding('hex'); // This stream is used to compute a hash of the zip content that gets used. Integrity check try { core.info('Beginning upload of artifact content to blob storage'); - yield blockBlobClient.uploadStream(uploadStream, bufferSize, maxBuffers, options); + yield blockBlobClient.uploadStream(uploadStream, bufferSize, maxConcurrency, options); core.info('Finished uploading artifact content to blob storage!'); hashStream.end(); sha256Hash = hashStream.read(); @@ -8240,19 +8896,11 @@ function uploadArtifact(name, files, rootDirectory, options) { success: false }; } - const zipUploadStream = yield (0, zip_1.createZipUploadStream)(zipSpecification); + 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, @@ -8471,12 +9119,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.createZipUploadStream = exports.ZipUploadStream = void 0; +exports.createZipUploadStream = exports.ZipUploadStream = exports.DEFAULT_COMPRESSION_LEVEL = void 0; const stream = __importStar(__nccwpck_require__(12781)); const archiver = __importStar(__nccwpck_require__(71160)); const core = __importStar(__nccwpck_require__(66526)); const fs_1 = __nccwpck_require__(57147); const config_1 = __nccwpck_require__(95042); +exports.DEFAULT_COMPRESSION_LEVEL = 6; // Custom stream transformer so we can set the highWaterMark property // See https://github.com/nodejs/node/issues/8855 class ZipUploadStream extends stream.Transform { @@ -8491,14 +9140,12 @@ class ZipUploadStream extends stream.Transform { } } exports.ZipUploadStream = ZipUploadStream; -function createZipUploadStream(uploadSpecification) { +function createZipUploadStream(uploadSpecification, compressionLevel = exports.DEFAULT_COMPRESSION_LEVEL) { return __awaiter(this, void 0, void 0, function* () { + core.debug(`Creating Artifact archive with compressionLevel: ${compressionLevel}`); const zip = archiver.create('zip', { - zlib: { level: 9 } // Sets the compression level. - // Available options are 0-9 - // 0 => no compression - // 1 => fastest with low compression - // 9 => highest compression ratio but the slowest + highWaterMark: (0, config_1.getUploadChunkSize)(), + zlib: { level: compressionLevel } }); // register callbacks for various events during the zip lifecycle zip.on('error', zipErrorCallback); @@ -118696,9 +119343,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(); @@ -118708,31 +119355,40 @@ function run() { } 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 (inputs.name) { - 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`); } - core.debug(`Found named artifact '${inputs.name}' (ID: ${targetArtifact.id}, Size: ${targetArtifact.size})`); + core.debug('Found named artifact:'); + core.debug(JSON.stringify(targetArtifact, null, 2)); artifacts = [targetArtifact]; } else { - 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`); + core.debug(`Found ${listArtifactResponse.artifacts.length} artifacts:`); + core.debug(JSON.stringify(listArtifactResponse, null, 2)); artifacts = listArtifactResponse.artifacts; } - const downloadPromises = artifacts.map(artifact => artifactClient.downloadArtifact(artifact.id, owner, repo, inputs.token, { - path: path.join(resolvedPath, artifact.name) - })); + const downloadPromises = artifacts.map(artifact => artifactClient.downloadArtifact(artifact.id, Object.assign(Object.assign({}, options), { path: path.join(resolvedPath, artifact.name) }))); const chunkedPromises = exports.chunk(downloadPromises, PARALLEL_DOWNLOADS); for (const chunk of chunkedPromises) { yield Promise.all(chunk); @@ -118999,7 +119655,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 2cdb916..67edb72 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) { @@ -33,11 +33,21 @@ async function run(): Promise { 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() @@ -46,28 +56,19 @@ async function run(): Promise { if (inputs.name) { const {artifact: targetArtifact} = await artifactClient.getArtifact( inputs.name, - inputs.runID, - owner, - repo, - inputs.token + options ) if (!targetArtifact) { throw new Error(`Artifact '${inputs.name}' not found`) } - core.debug( - `Found named artifact '${inputs.name}' (ID: ${targetArtifact.id}, Size: ${targetArtifact.size})` - ) + core.debug('Found named artifact:') + core.debug(JSON.stringify(targetArtifact, null, 2)) artifacts = [targetArtifact] } else { - const listArtifactResponse = await artifactClient.listArtifacts( - inputs.runID, - owner, - repo, - inputs.token - ) + const listArtifactResponse = await artifactClient.listArtifacts(options) if (listArtifactResponse.artifacts.length === 0) { throw new Error( @@ -75,12 +76,14 @@ async function run(): Promise { ) } - core.debug(`Found ${listArtifactResponse.artifacts.length} artifacts`) + core.debug(`Found ${listArtifactResponse.artifacts.length} artifacts:`) + core.debug(JSON.stringify(listArtifactResponse, null, 2)) artifacts = listArtifactResponse.artifacts } const downloadPromises = artifacts.map(artifact => - artifactClient.downloadArtifact(artifact.id, owner, repo, inputs.token, { + artifactClient.downloadArtifact(artifact.id, { + ...options, path: path.join(resolvedPath, artifact.name) }) )