Skip to content

Commit 9ec1a08

Browse files
committed
Merge remote-tracking branch 'upstream/master'
# Conflicts: # action.yml # code-build.js # dist/index.js
2 parents 0487e20 + f188bf3 commit 9ec1a08

File tree

9 files changed

+6958
-529
lines changed

9 files changed

+6958
-529
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ jobs:
88
contents: read
99
runs-on: ubuntu-latest
1010
steps:
11-
- uses: actions/checkout@v2
12-
- uses: actions/setup-node@v1
11+
- uses: actions/checkout@v3
12+
- uses: actions/setup-node@v3
1313
with:
1414
# This should match the using value in `actions.yaml`
15-
node-version: 12
15+
node-version: 16
1616
- run: npm ci
1717
- run: npm run lint
1818
- run: npm run test

README.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ The only required input is `project-name`.
3232
The name of an image for this build that overrides the one specified
3333
in the build project.
3434
1. **disable-source-override** (optional) :
35-
Set to `true` if you want to disable providing `sourceTypeOverride` and `sourceLocationOverride` to CodeBuild.
35+
Set to `true` if you want to disable providing `sourceVersion`,
36+
`sourceTypeOverride` and `sourceLocationOverride` to CodeBuild.
3637
1. **env-vars-for-codebuild** (optional) :
3738
A comma-separated list of the names of environment variables
3839
that the action passes from GitHub Actions to CodeBuild.
@@ -48,6 +49,31 @@ The only required input is `project-name`.
4849
the one defined here replaces the one in the CodeBuild project.
4950
For a list of CodeBuild environment variables, see
5051

52+
1. **update-interval** (optional) :
53+
Update interval as seconds for how often the API is called to check on the status.
54+
55+
A higher value mitigates the chance of hitting API rate-limiting especially when
56+
running many instances of this action in parallel, but also introduces a larger
57+
potential time overhead (ranging from 0 to update interval) for the action to
58+
fetch the build result and finish.
59+
60+
Lower value limits the potential time overhead worst case but it may hit the API
61+
rate-limit more often, depending on the use-case.
62+
63+
The default value is 30.
64+
65+
1. **update-back-off** (optional) :
66+
Base back-off time in seconds for the update interval.
67+
68+
When API rate-limiting is hit the back-off time, augmented with jitter, will be
69+
added to the next update interval.
70+
E.g. with update interval of 30 and back-off time of 15, upon hitting the rate-limit
71+
the next interval for the update call will be 30 + random_between(0, 15 _ 2 \*\* 0))
72+
seconds and if the rate-limit is hit again the next interval will be
73+
30 + random_between(0, 15 _ 2 \*\* 1) and so on.
74+
75+
The default value is 15.
76+
5177
### Outputs
5278

5379
1. **aws-build-id** : The CodeBuild build ID of the build that the action ran.

action.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,18 @@ inputs:
2222
env-vars-for-codebuild:
2323
description: 'Comma separated list of environment variables to send to CodeBuild'
2424
required: false
25+
update-interval:
26+
description: 'How often the action calls the API for updates'
27+
required: false
28+
update-back-off:
29+
description: 'Base back-off time for the update calls for API if rate-limiting is encountered'
30+
required: false
2531
disable-source-override:
2632
description: 'Set to `true` if you want do disable source repo override'
2733
required: false
2834
outputs:
2935
aws-build-id:
3036
description: 'The AWS CodeBuild Build ID for this build.'
3137
runs:
32-
using: 'node12'
38+
using: 'node16'
3339
main: 'dist/index.js'

code-build.js

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,37 @@ function runBuild() {
2020
// get a codeBuild instance from the SDK
2121
const sdk = buildSdk();
2222

23+
const inputs = githubInputs();
24+
25+
const config = (({ updateInterval, updateBackOff }) => ({
26+
updateInterval,
27+
updateBackOff,
28+
}))(inputs);
29+
2330
// Get input options for startBuild
24-
const params = inputs2Parameters(githubInputs());
31+
const params = inputs2Parameters(inputs);
2532

26-
return build(sdk, params);
33+
return build(sdk, params, config);
2734
}
2835

29-
async function build(sdk, params) {
36+
async function build(sdk, params, config) {
3037
// Start the build
3138
const start = await sdk.codeBuild.startBuild(params).promise();
3239

3340
// Wait for the build to "complete"
34-
return waitForBuildEndTime(sdk, start.build);
41+
return waitForBuildEndTime(sdk, start.build, config);
3542
}
3643

3744
async function waitForBuildEndTime(
3845
sdk,
3946
{ id, logs },
47+
{ updateInterval, updateBackOff },
4048
seqEmptyLogs,
4149
totalEvents,
4250
throttleCount,
4351
nextToken
4452
) {
45-
const {
46-
codeBuild,
47-
cloudWatchLogs,
48-
wait = 1000 * 30,
49-
backOff = 1000 * 15,
50-
} = sdk;
53+
const { codeBuild, cloudWatchLogs } = sdk;
5154

5255
totalEvents = totalEvents || 0;
5356
seqEmptyLogs = seqEmptyLogs || 0;
@@ -86,17 +89,21 @@ async function waitForBuildEndTime(
8689
if (errObject) {
8790
//We caught an error in trying to make the AWS api call, and are now checking to see if it was just a rate limiting error
8891
if (errObject.message && errObject.message.search("Rate exceeded") !== -1) {
89-
//We were rate-limited, so add `backOff` seconds to the wait time
90-
let newWait = wait + backOff;
92+
// We were rate-limited, so add backoff with Full Jitter, ref: https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/
93+
let jitteredBackOff = Math.floor(
94+
Math.random() * (updateBackOff * 2 ** throttleCount)
95+
);
96+
let newWait = updateInterval + jitteredBackOff;
9197
throttleCount++;
9298

9399
//Sleep before trying again
94100
await new Promise((resolve) => setTimeout(resolve, newWait));
95101

96102
// Try again from the same token position
97103
return waitForBuildEndTime(
98-
{ ...sdk, wait: newWait },
104+
{ ...sdk },
99105
{ id, logs },
106+
{ updateInterval: newWait, updateBackOff },
100107
seqEmptyLogs,
101108
totalEvents,
102109
throttleCount,
@@ -136,13 +143,19 @@ async function waitForBuildEndTime(
136143
// More to do: Sleep for a few seconds to avoid rate limiting
137144
// If never throttled and build is complete, halve CWL polling delay to minimize latency
138145
await new Promise((resolve) =>
139-
setTimeout(resolve, current.endTime && throttleCount == 0 ? wait / 2 : wait)
146+
setTimeout(
147+
resolve,
148+
current.endTime && throttleCount == 0
149+
? updateInterval / 2
150+
: updateInterval
151+
)
140152
);
141153

142154
// Try again
143155
return waitForBuildEndTime(
144156
sdk,
145157
current,
158+
{ updateInterval, updateBackOff },
146159
seqEmptyLogs,
147160
totalEvents,
148161
throttleCount,
@@ -175,8 +188,9 @@ function githubInputs() {
175188
core.getInput("compute-type-override", { required: false }) || undefined;
176189

177190
const environmentTypeOverride =
178-
core.getInput("environment-type-override", { required: false }) || undefined;
179-
const imageOverride =
191+
core.getInput("environment-type-override", { required: false }) ||
192+
undefined;
193+
const imageOverride =
180194
core.getInput("image-override", { required: false }) || undefined;
181195

182196
const envPassthrough = core
@@ -185,6 +199,17 @@ function githubInputs() {
185199
.map((i) => i.trim())
186200
.filter((i) => i !== "");
187201

202+
const updateInterval =
203+
parseInt(
204+
core.getInput("update-interval", { required: false }) || "30",
205+
10
206+
) * 1000;
207+
const updateBackOff =
208+
parseInt(
209+
core.getInput("update-back-off", { required: false }) || "15",
210+
10
211+
) * 1000;
212+
188213
return {
189214
projectName,
190215
owner,
@@ -195,6 +220,8 @@ function githubInputs() {
195220
environmentTypeOverride,
196221
imageOverride,
197222
envPassthrough,
223+
updateInterval,
224+
updateBackOff,
198225
disableSourceOverride,
199226
};
200227
}
@@ -237,6 +264,7 @@ function inputs2Parameters(inputs) {
237264
environmentTypeOverride,
238265
imageOverride,
239266
environmentVariablesOverride,
267+
disableSourceOverride,
240268
};
241269
}
242270

0 commit comments

Comments
 (0)