Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/check-dist.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# `dist/index.js` is a special file in Actions.
# When you reference an action with `uses:` in a workflow,
# `index.js` is the code that will run.
# For our project, we generate this file through a build process
# from other source files.
# We need to make sure the checked-in `index.js` actually matches what we expect it to be.
name: Check dist

on:
# push:
# branches:
# - master
# paths-ignore:
# - '**.md'
pull_request:
paths-ignore:
- '**.md'
workflow_dispatch:

jobs:
check-dist:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set Node.js 20.x
uses: actions/setup-node@v1
with:
node-version: 20.x

- name: Install dependencies
run: npm ci

- name: Rebuild the index.js file
run: npm run build

- name: Compare the expected and actual dist/ directories
run: |
if [ "$(git diff --ignore-space-at-eol dist/ | wc -l)" -gt "0" ]; then
echo "Detected uncommitted changes after build. See status below:"
git diff
exit 1
fi
2 changes: 1 addition & 1 deletion .github/workflows/ci-unit-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- uses: actions/setup-node@v3
with:
# This should match the using value in `actions.yaml`
node-version: 16
node-version: 20
- run: npm ci
- run: npm run lint
# - run: npm run test
23 changes: 23 additions & 0 deletions .github/workflows/create-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Create release

on:
push:
branches:
- master
workflow_dispatch:

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
check-dist:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Create Release
run: |
gh repo set-default brave-intl/general-docker-build-pipeline-action
tag=$(gh release view --json tagName --jq .tagName)
gh release create $(echo "$tag" | awk -F. '{$NF++; print $1"."$2"."$NF}') --generate-notes
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ outputs:
aws-build-id:
description: 'The AWS CodeBuild Build ID for this build.'
runs:
using: 'node16'
using: 'node20'
main: 'dist/index.js'
59 changes: 38 additions & 21 deletions code-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,17 @@

const core = require("@actions/core");
const github = require("@actions/github");
const aws = require("aws-sdk");

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");

module.exports = {
Expand Down Expand Up @@ -38,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).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}`);

Expand Down Expand Up @@ -81,17 +94,21 @@ async function waitForBuildEndTime(
let errObject = false;
// Check the state
const [batch, cloudWatch = {}] = await Promise.all([
codeBuild.batchGetBuilds({ ids: [id] }).promise(),
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,
})
.promise(),
),
]).catch((err) => {
errObject = err;
/* Returning [] here so that the assignment above
Expand Down Expand Up @@ -252,15 +269,15 @@ function inputs2Parameters(inputs) {
}

function buildSdk() {
const codeBuild = new aws.CodeBuild({
const codeBuild = new CodeBuildClient({
customUserAgent: "brave-intl/aws-codebuild-run-build",
});

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

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

Expand Down
Loading