Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use CodeArtifact for AWS CodeBuild CI jobs #1455

Merged
merged 8 commits into from
Jan 13, 2021
Merged
Show file tree
Hide file tree
Changes from 7 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
13 changes: 12 additions & 1 deletion buildspec/linuxIntegrationTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ phases:

pre_build:
commands:
# If present, log into CodeArtifact. Provides a nice safety net in case NPM is down.
# Should only affect tests run through IDEs team-hosted CodeBuild.
- |
if [ $TOOLKITS_CODEARTIFACT_DOMAIN ] && [ $TOOLKITS_CODEARTIFACT_REPO ] && [ $ACCOUNT_ID ]; then
aws codeartifact login --tool npm --domain "$TOOLKITS_CODEARTIFACT_DOMAIN" --domain-owner "$ACCOUNT_ID" --repository "$TOOLKITS_CODEARTIFACT_REPO" > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "Connected to CodeArtifact"
else
echo "CodeArtifact connection failed. Falling back to npm"
fi
fi
Copy link
Contributor

@justinmk3 justinmk3 Jan 13, 2021

Choose a reason for hiding this comment

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

Please run this block through https://www.shellcheck.net/ . It has several issues. E.g. missing quotes around env vars.

shellcheck's SC2181 is suggesting this change:

                  if aws codeartifact login --tool npm --domain "$TOOLKITS_CODEARTIFACT_DOMAIN" --domain-owner "$ACCOUNT_ID" --repository "$TOOLKITS_CODEARTIFACT_REPO" > /dev/null 2>&1 ; then
                    echo "Connected to CodeArtifact"
                  else
                    echo "CodeArtifact connection failed. Falling back to npm"
                  fi

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got a Powershell equivalent? 😛

Copy link
Contributor

Choose a reason for hiding this comment

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

:) Not sure, but powershell has many fewer gotchas.

# make sure that SAM is in the path, is not automatically done on CodeBuild
- USER_BASE_PATH=$(python -m site --user-base) && export PATH=$PATH:$USER_BASE_PATH/bin
# start Docker
Expand All @@ -36,7 +47,7 @@ phases:

build:
commands:
- npm install --unsafe-perm
- npm ci --unsafe-perm
- xvfb-run npm run integrationTest

reports:
Expand Down
13 changes: 12 additions & 1 deletion buildspec/linuxTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,18 @@ phases:

pre_build:
commands:
- npm install --unsafe-perm
# If present, log into CodeArtifact. Provides a nice safety net in case NPM is down.
# Should only affect tests run through IDEs team-hosted CodeBuild.
- |
if [ $TOOLKITS_CODEARTIFACT_DOMAIN ] && [ $TOOLKITS_CODEARTIFACT_REPO ] && [ $ACCOUNT_ID ]; then
aws codeartifact login --tool npm --domain "$TOOLKITS_CODEARTIFACT_DOMAIN" --domain-owner "$ACCOUNT_ID" --repository "$TOOLKITS_CODEARTIFACT_REPO" > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "Connected to CodeArtifact"
else
echo "CodeArtifact connection failed. Falling back to npm"
fi
fi
- npm ci --unsafe-perm

build:
commands:
Expand Down
13 changes: 12 additions & 1 deletion buildspec/packageTestVsix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,19 @@ phases:

pre_build:
commands:
# If present, log into CodeArtifact. Provides a nice safety net in case NPM is down.
# Should only affect tests run through IDEs team-hosted CodeBuild.
- |
if [ $TOOLKITS_CODEARTIFACT_DOMAIN ] && [ $TOOLKITS_CODEARTIFACT_REPO ] && [ $ACCOUNT_ID ]; then
aws codeartifact login --tool npm --domain "$TOOLKITS_CODEARTIFACT_DOMAIN" --domain-owner "$ACCOUNT_ID" --repository "$TOOLKITS_CODEARTIFACT_REPO" > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "Connected to CodeArtifact"
else
echo "CodeArtifact connection failed. Falling back to npm"
fi
fi
# --unsafe-perm is needed because we run as root
- npm install --unsafe-perm
- npm ci --unsafe-perm

build:
commands:
Expand Down
15 changes: 14 additions & 1 deletion buildspec/windowsTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,23 @@ phases:
if(-Not($Env:CODE_COV_TOKEN -eq $null)) {
choco install -y --no-progress codecov
}
- choco install vcredist140

pre_build:
commands:
- npm install
# If present, log into CodeArtifact. Provides a nice safety net in case NPM is down.
# Should only affect tests run through IDEs team-hosted CodeBuild.
# UNCOMMENT THE FOLLOWING WHEN VS CODE CAN BUILD IN WIN_SERVER_CORE_2019_BASE: https://github.com/microsoft/vscode/issues/77499
# - |
# if ($Env:TOOLKITS_CODEARTIFACT_DOMAIN -and $Env:TOOLKITS_CODEARTIFACT_REPO -and $Env:ACCOUNT_ID) {
# aws codeartifact login --tool npm --domain "$TOOLKITS_CODEARTIFACT_DOMAIN" --domain-owner "$ACCOUNT_ID" --repository "$TOOLKITS_CODEARTIFACT_REPO"
# if ($?) {
# echo "Connected to CodeArtifact"
# } else {
# echo "CodeArtifact connection failed. Falling back to npm"
# }
# }
- npm ci

build:
commands:
Expand Down