Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

[CE-919] Add AWS Codebuild support #220

Merged
merged 14 commits into from
Nov 6, 2019
16 changes: 16 additions & 0 deletions codecov
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,22 @@ then
env="$env,${!language}"
fi

elif [ "$CODEBUILD_BUILD_ARN" != "" ];
then
say "$e==>$x AWS Codebuild detected."
# https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right here, @hootener :)

service="codebuild"
commit="$CODEBUILD_RESOLVED_SOURCE_VERSION"
build="$CODEBUILD_BUILD_ID"
branch="$(echo $CODEBUILD_WEBHOOK_HEAD_REF | sed 's/^refs\/heads\///')"
if [ "${CODEBUILD_SOURCE_VERSION/pr}" = "$CODEBUILD_SOURCE_VERSION" ] ; then
pr="false"
else
pr="$(echo $CODEBUILD_SOURCE_VERSION | sed 's/^pr\///')"
fi
job="$CODEBUILD_BUILD_ID"
slug="$(echo $CODEBUILD_SOURCE_REPO_URL | sed 's/^.*github.com\///' | sed 's/\.git$//')"

elif [ "$DOCKER_REPO" != "" ];
then
say "$e==>$x Docker detected."
Expand Down
8 changes: 8 additions & 0 deletions env
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ then
add "BUILD_NUMBER"
add "ghprbPullId"
add "BUILD_URL"

if [ "$CODEBUILD_BUILD_ARN" != "" ];
then
add "CODEBUILD_WEBHOOK_HEAD_REF"
add "CODEBUILD_RESOLVED_SOURCE_VERSION"
add "CODEBUILD_SOURCE_VERSION"
add "CODEBUILD_BUILD_ID"
add "CODEBUILD_SOURCE_REPO_URL"

elif [ "$CI" = "true" ] && [ "$TRAVIS" = "true" ] && [ "$SHIPPABLE" != "true" ];
then
Expand Down
7 changes: 7 additions & 0 deletions tests/env
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,10 @@ export BITBUCKET_REPO_OWNER=""
export BITBUCKET_REPO_SLUG=""
export BITBUCKET_PR_ID=""
export GITHUB_ACTION=""
export CODEBUILD_BUILD_ARN=""
export CODEBUILD_WEBHOOK_HEAD_REF=""
export CODEBUILD_RESOLVED_SOURCE_VERSION=""
export CODEBUILD_SOURCE_VERSION=""
export CODEBUILD_BUILD_ID=""
export CODEBUILD_SOURCE_REPO_URL=""
export CODEBUILD_BUILD_ID=""
drazisil marked this conversation as resolved.
Show resolved Hide resolved
24 changes: 24 additions & 0 deletions tests/test
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,30 @@ function assertURL () {
assertTrue 'Expected output differs.' $?
}

# Test an AWS Codebuild upload not from a PR
function test_codebuild () {
reset
export CODEBUILD_BUILD_ARN="true"
export CODEBUILD_WEBHOOK_HEAD_REF="refs/heads/codebuild-master"
export CODEBUILD_RESOLVED_SOURCE_VERSION="$TEST_DATA_GIT_COMMIT"
export CODEBUILD_SOURCE_VERSION="pr/42"
export CODEBUILD_BUILD_ID="33116958"
export CODEBUILD_SOURCE_REPO_URL="https://github.com/codecov/codecov-bash.git"
assertURL "https://codecov.io/upload/v4?package=bash-$VERSION&token=&branch=codebuild-master&commit=$TEST_DATA_GIT_COMMIT&build=33116958&build_url=&name=&tag=&slug=codecov%2Fcodecov-bash&service=codebuild&flags=&pr=42&job=33116958"
}

# Test an AWS Codebuild upload from a PR
function test_codebuild_pr () {
reset
export CODEBUILD_BUILD_ARN="true"
export CODEBUILD_WEBHOOK_HEAD_REF="refs/heads/codebuild-master"
export CODEBUILD_RESOLVED_SOURCE_VERSION="$TEST_DATA_GIT_COMMIT"
export CODEBUILD_SOURCE_VERSION="$TEST_DATA_GIT_COMMIT"
export CODEBUILD_BUILD_ID="33116958"
export CODEBUILD_SOURCE_REPO_URL="https://github.com/codecov/codecov-bash.git"
assertURL "https://codecov.io/upload/v4?package=bash-$VERSION&token=&branch=codebuild-master&commit=$TEST_DATA_GIT_COMMIT&build=33116958&build_url=&name=&tag=&slug=codecov%2Fcodecov-bash&service=codebuild&flags=&pr=false&job=33116958"
}

function test_travis () {
reset
export CI="true"
Expand Down