diff --git a/code-build.js b/code-build.js index c178a2b..8887bef 100644 --- a/code-build.js +++ b/code-build.js @@ -4,9 +4,15 @@ const core = require("@actions/core"); const github = require("@actions/github"); -const { CloudWatchLogs } = require("@aws-sdk/client-cloudwatch-logs"); -const { CodeBuild } = require("@aws-sdk/client-codebuild"); -const { Lambda } = require("@aws-sdk/client-lambda"); +const { + CloudWatchLogsClient, + GetLogEventsCommand, +} = require("@aws-sdk/client-cloudwatch-logs"); +const { + CodeBuildClient, + BatchGetBuildsCommand, +} = require("@aws-sdk/client-codebuild"); +const { LambdaClient, InvokeCommand } = require("@aws-sdk/client-lambda"); const assert = require("assert"); @@ -42,19 +48,22 @@ async function build(sdk, params, config) { // Invoke the lambda to start the build const buildTime = (Date.now() / 1000).toString(); const imageTag = `${params.sourceVersion}-${Math.floor(buildTime)}`; - const lambdaParams = { - FunctionName: "GeneralDockerBuildPipelineLambdaFunction", - Payload: JSON.stringify({ - owner: params.owner, - repo: params.repo, - branch: params.branch, - sourceVersion: params.sourceVersion, - reproducible: params.reproducible, - imageTag, - }), - }; - const response = await sdk.lambda.invoke(lambdaParams); - const start = JSON.parse(JSON.parse(response.Payload)); + const response = await sdk.lambda.send( + new InvokeCommand({ + FunctionName: "GeneralDockerBuildPipelineLambdaFunction", + Payload: JSON.stringify({ + owner: params.owner, + repo: params.repo, + branch: params.branch, + sourceVersion: params.sourceVersion, + reproducible: params.reproducible, + imageTag, + }), + }) + ); + const start = JSON.parse( + JSON.parse(Buffer.from(response.Payload).toString()) + ); await core.notice(`Built image tag: ${imageTag}`); @@ -85,18 +94,21 @@ async function waitForBuildEndTime( let errObject = false; // Check the state const [batch, cloudWatch = {}] = await Promise.all([ - codeBuild.batchGetBuilds({ ids: [id] }), - // The promise() call was removed by aws-sdk-js-codemod v2-to-v3 transform using best guess. - // Please check that it is correct, and create an issue on GitHub to report this use case. + codeBuild.send( + new BatchGetBuildsCommand({ + ids: [id], + }) + ), !hideCloudWatchLogs && logGroupName && - cloudWatchLogs // only make the call if hideCloudWatchLogs is not enabled and a logGroupName exists - .getLogEvents({ + cloudWatchLogs.send( + new GetLogEventsCommand({ logGroupName, logStreamName, startFromHead, nextToken, - }), + }) + ), ]).catch((err) => { errObject = err; /* Returning [] here so that the assignment above @@ -257,21 +269,21 @@ function inputs2Parameters(inputs) { } function buildSdk() { - const codeBuild = new CodeBuild({ + const codeBuild = new CodeBuildClient({ // The transformation for customUserAgent is not implemented. // Refer to UPGRADING.md on aws-sdk-js-v3 for changes needed. // Please create/upvote feature request on aws-sdk-js-codemod for customUserAgent. customUserAgent: "brave-intl/aws-codebuild-run-build", }); - const cloudWatchLogs = new CloudWatchLogs({ + const cloudWatchLogs = new CloudWatchLogsClient({ // The transformation for customUserAgent is not implemented. // Refer to UPGRADING.md on aws-sdk-js-v3 for changes needed. // Please create/upvote feature request on aws-sdk-js-codemod for customUserAgent. customUserAgent: "brave-intl/aws-codebuild-run-build", }); - const lambda = new Lambda({ + const lambda = new LambdaClient({ // The transformation for customUserAgent is not implemented. // Refer to UPGRADING.md on aws-sdk-js-v3 for changes needed. // Please create/upvote feature request on aws-sdk-js-codemod for customUserAgent. diff --git a/dist/index.js b/dist/index.js index 4dcc40b..89e70c6 100644 --- a/dist/index.js +++ b/dist/index.js @@ -12,9 +12,13 @@ const core = __nccwpck_require__(2186); const github = __nccwpck_require__(5438); - const { CloudWatchLogs } = __nccwpck_require__(1573); - const { CodeBuild } = __nccwpck_require__(6872); - const { Lambda } = __nccwpck_require__(6584); + const { CloudWatchLogsClient, GetLogEventsCommand } = __nccwpck_require__( + 1573 + ); + const { CodeBuildClient, BatchGetBuildsCommand } = __nccwpck_require__( + 6872 + ); + const { LambdaClient, InvokeCommand } = __nccwpck_require__(6584); const assert = __nccwpck_require__(9491); @@ -54,19 +58,22 @@ // Invoke the lambda to start the build const buildTime = (Date.now() / 1000).toString(); const imageTag = `${params.sourceVersion}-${Math.floor(buildTime)}`; - const lambdaParams = { - FunctionName: "GeneralDockerBuildPipelineLambdaFunction", - Payload: JSON.stringify({ - owner: params.owner, - repo: params.repo, - branch: params.branch, - sourceVersion: params.sourceVersion, - reproducible: params.reproducible, - imageTag, - }), - }; - const response = await sdk.lambda.invoke(lambdaParams).promise(); - const start = JSON.parse(JSON.parse(response.Payload)); + const response = await sdk.lambda.send( + new InvokeCommand({ + FunctionName: "GeneralDockerBuildPipelineLambdaFunction", + Payload: JSON.stringify({ + owner: params.owner, + repo: params.repo, + branch: params.branch, + sourceVersion: params.sourceVersion, + reproducible: params.reproducible, + imageTag, + }), + }) + ); + const start = JSON.parse( + JSON.parse(Buffer.from(response.Payload).toString()) + ); await core.notice(`Built image tag: ${imageTag}`); @@ -97,18 +104,21 @@ let errObject = false; // Check the state const [batch, cloudWatch = {}] = await Promise.all([ - codeBuild.batchGetBuilds({ ids: [id] }), - // The promise() call was removed by aws-sdk-js-codemod v2-to-v3 transform using best guess. - // Please check that it is correct, and create an issue on GitHub to report this use case. + codeBuild.send( + new BatchGetBuildsCommand({ + ids: [id], + }) + ), !hideCloudWatchLogs && logGroupName && - cloudWatchLogs // only make the call if hideCloudWatchLogs is not enabled and a logGroupName exists - .getLogEvents({ + cloudWatchLogs.send( + new GetLogEventsCommand({ logGroupName, logStreamName, startFromHead, nextToken, - }), + }) + ), ]).catch((err) => { errObject = err; /* Returning [] here so that the assignment above @@ -273,21 +283,21 @@ } function buildSdk() { - const codeBuild = new CodeBuild({ + const codeBuild = new CodeBuildClient({ // The transformation for customUserAgent is not implemented. // Refer to UPGRADING.md on aws-sdk-js-v3 for changes needed. // Please create/upvote feature request on aws-sdk-js-codemod for customUserAgent. customUserAgent: "brave-intl/aws-codebuild-run-build", }); - const cloudWatchLogs = new CloudWatchLogs({ + const cloudWatchLogs = new CloudWatchLogsClient({ // The transformation for customUserAgent is not implemented. // Refer to UPGRADING.md on aws-sdk-js-v3 for changes needed. // Please create/upvote feature request on aws-sdk-js-codemod for customUserAgent. customUserAgent: "brave-intl/aws-codebuild-run-build", }); - const lambda = new Lambda({ + const lambda = new LambdaClient({ // The transformation for customUserAgent is not implemented. // Refer to UPGRADING.md on aws-sdk-js-v3 for changes needed. // Please create/upvote feature request on aws-sdk-js-codemod for customUserAgent.