Skip to content

Commit 00750bf

Browse files
authored
Merge pull request #34 from brave-intl/aws-sdk-v3
Migrate AWS SDK to V3
2 parents 8477565 + c347707 commit 00750bf

File tree

8 files changed

+67325
-87557
lines changed

8 files changed

+67325
-87557
lines changed

.github/workflows/check-dist.yaml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# `dist/index.js` is a special file in Actions.
2+
# When you reference an action with `uses:` in a workflow,
3+
# `index.js` is the code that will run.
4+
# For our project, we generate this file through a build process
5+
# from other source files.
6+
# We need to make sure the checked-in `index.js` actually matches what we expect it to be.
7+
name: Check dist
8+
9+
on:
10+
# push:
11+
# branches:
12+
# - master
13+
# paths-ignore:
14+
# - '**.md'
15+
pull_request:
16+
paths-ignore:
17+
- '**.md'
18+
workflow_dispatch:
19+
20+
jobs:
21+
check-dist:
22+
runs-on: ubuntu-latest
23+
24+
steps:
25+
- uses: actions/checkout@v3
26+
27+
- name: Set Node.js 20.x
28+
uses: actions/setup-node@v1
29+
with:
30+
node-version: 20.x
31+
32+
- name: Install dependencies
33+
run: npm ci
34+
35+
- name: Rebuild the index.js file
36+
run: npm run build
37+
38+
- name: Compare the expected and actual dist/ directories
39+
run: |
40+
if [ "$(git diff --ignore-space-at-eol dist/ | wc -l)" -gt "0" ]; then
41+
echo "Detected uncommitted changes after build. See status below:"
42+
git diff
43+
exit 1
44+
fi

.github/workflows/ci-unit-tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
- uses: actions/setup-node@v3
1313
with:
1414
# This should match the using value in `actions.yaml`
15-
node-version: 16
15+
node-version: 20
1616
- run: npm ci
1717
- run: npm run lint
1818
# - run: npm run test
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Create release
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
workflow_dispatch:
8+
9+
env:
10+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
11+
12+
jobs:
13+
check-dist:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v3
18+
19+
- name: Create Release
20+
run: |
21+
gh repo set-default brave-intl/general-docker-build-pipeline-action
22+
tag=$(gh release view --json tagName --jq .tagName)
23+
gh release create $(echo "$tag" | awk -F. '{$NF++; print $1"."$2"."$NF}') --generate-notes

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ outputs:
2323
aws-build-id:
2424
description: 'The AWS CodeBuild Build ID for this build.'
2525
runs:
26-
using: 'node16'
26+
using: 'node20'
2727
main: 'dist/index.js'

code-build.js

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,17 @@
33

44
const core = require("@actions/core");
55
const github = require("@actions/github");
6-
const aws = require("aws-sdk");
6+
7+
const {
8+
CloudWatchLogsClient,
9+
GetLogEventsCommand,
10+
} = require("@aws-sdk/client-cloudwatch-logs");
11+
const {
12+
CodeBuildClient,
13+
BatchGetBuildsCommand,
14+
} = require("@aws-sdk/client-codebuild");
15+
const { LambdaClient, InvokeCommand } = require("@aws-sdk/client-lambda");
16+
717
const assert = require("assert");
818

919
module.exports = {
@@ -38,19 +48,22 @@ async function build(sdk, params, config) {
3848
// Invoke the lambda to start the build
3949
const buildTime = (Date.now() / 1000).toString();
4050
const imageTag = `${params.sourceVersion}-${Math.floor(buildTime)}`;
41-
const lambdaParams = {
42-
FunctionName: "GeneralDockerBuildPipelineLambdaFunction",
43-
Payload: JSON.stringify({
44-
owner: params.owner,
45-
repo: params.repo,
46-
branch: params.branch,
47-
sourceVersion: params.sourceVersion,
48-
reproducible: params.reproducible,
49-
imageTag,
50-
}),
51-
};
52-
const response = await sdk.lambda.invoke(lambdaParams).promise();
53-
const start = JSON.parse(JSON.parse(response.Payload));
51+
const response = await sdk.lambda.send(
52+
new InvokeCommand({
53+
FunctionName: "GeneralDockerBuildPipelineLambdaFunction",
54+
Payload: JSON.stringify({
55+
owner: params.owner,
56+
repo: params.repo,
57+
branch: params.branch,
58+
sourceVersion: params.sourceVersion,
59+
reproducible: params.reproducible,
60+
imageTag,
61+
}),
62+
})
63+
);
64+
const start = JSON.parse(
65+
JSON.parse(Buffer.from(response.Payload).toString())
66+
);
5467

5568
await core.notice(`Built image tag: ${imageTag}`);
5669

@@ -81,17 +94,21 @@ async function waitForBuildEndTime(
8194
let errObject = false;
8295
// Check the state
8396
const [batch, cloudWatch = {}] = await Promise.all([
84-
codeBuild.batchGetBuilds({ ids: [id] }).promise(),
97+
codeBuild.send(
98+
new BatchGetBuildsCommand({
99+
ids: [id],
100+
})
101+
),
85102
!hideCloudWatchLogs &&
86103
logGroupName &&
87-
cloudWatchLogs // only make the call if hideCloudWatchLogs is not enabled and a logGroupName exists
88-
.getLogEvents({
104+
cloudWatchLogs.send(
105+
new GetLogEventsCommand({
89106
logGroupName,
90107
logStreamName,
91108
startFromHead,
92109
nextToken,
93110
})
94-
.promise(),
111+
),
95112
]).catch((err) => {
96113
errObject = err;
97114
/* Returning [] here so that the assignment above
@@ -252,15 +269,15 @@ function inputs2Parameters(inputs) {
252269
}
253270

254271
function buildSdk() {
255-
const codeBuild = new aws.CodeBuild({
272+
const codeBuild = new CodeBuildClient({
256273
customUserAgent: "brave-intl/aws-codebuild-run-build",
257274
});
258275

259-
const cloudWatchLogs = new aws.CloudWatchLogs({
276+
const cloudWatchLogs = new CloudWatchLogsClient({
260277
customUserAgent: "brave-intl/aws-codebuild-run-build",
261278
});
262279

263-
const lambda = new aws.Lambda({
280+
const lambda = new LambdaClient({
264281
customUserAgent: "brave-intl/aws-codebuild-run-build",
265282
});
266283

0 commit comments

Comments
 (0)