Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
0e5c748
ci: Add Buildkite testing action to CI.
varungandhi-src Aug 7, 2022
b57f475
ci: Add Buildkite hooks like Sorbet.
varungandhi-src Aug 8, 2022
9bed1ef
ci: Remove os filter for agent queue.
varungandhi-src Aug 8, 2022
0f29cd6
ci: Temporarily make hooks unused.
varungandhi-src Aug 8, 2022
6929dbb
ci: Fix test target for Buildkite.
varungandhi-src Aug 8, 2022
6dee8f6
cleanup: Format Bazel files.
varungandhi-src Aug 8, 2022
4cf02f7
cleanup: Auto-format C++ code.
varungandhi-src Aug 8, 2022
bbf7b14
ci: Specify Ruby version using ASDF.
varungandhi-src Aug 8, 2022
076d0b1
ci: Break up steps in test-indexer.sh
varungandhi-src Aug 8, 2022
876d1e9
ci: Disable compdb generation linter.
varungandhi-src Aug 8, 2022
969b5be
ci: Fix --test_env flag passed to bazel.
varungandhi-src Aug 8, 2022
04e5985
ci: Remove lint check for VS Code extension.
varungandhi-src Aug 8, 2022
be31afe
ci: Update test-indexer script timing, installing Ruby.
varungandhi-src Aug 8, 2022
6df6301
ci: Work around asdf-ruby bug.
varungandhi-src Aug 8, 2022
7d56b6a
ci: Add Buildkite caching.
varungandhi-src Aug 8, 2022
7790eb2
ci: Hide Ruby installation in Buildkite.
varungandhi-src Aug 8, 2022
017e45a
test: Make git clone of repo quiet.
varungandhi-src Aug 8, 2022
b12aa1d
ci: Reshim Ruby without explicit version.
varungandhi-src Aug 8, 2022
f4ec4ef
ci: Fix incorrect usage of cache keys.
varungandhi-src Aug 8, 2022
642bedc
ci: Add pre-command hook to install aws CLI.
varungandhi-src Aug 8, 2022
104b9c6
ci: Try passing AWS env vars + fix agent config.
varungandhi-src Aug 8, 2022
e34e415
ci: Create AWS config files before trying to use them.
varungandhi-src Aug 8, 2022
3c64ab8
ci: Turn off prettier check as it is failing inexplicably.
varungandhi-src Aug 8, 2022
816d606
ci: Minor cleanups for repo test script.
varungandhi-src Aug 8, 2022
e724b99
ci: Set global ruby version with asdf.
varungandhi-src Aug 8, 2022
7371717
ci: Unpack AWS CLI in temporary directory.
varungandhi-src Aug 8, 2022
ac66f85
ci: Work around buggy argument parsing in mktemp
varungandhi-src Aug 8, 2022
6d92441
ci: Create template with Xs for Linux mktemp.
varungandhi-src Aug 8, 2022
d357a7f
ci: I apologize for writing Bash, I apologize for writing Bash, I apo…
varungandhi-src Aug 8, 2022
bb5ed5e
ci: Remove lint step from buildkite.
varungandhi-src Aug 8, 2022
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
1 change: 1 addition & 0 deletions .buildkite/all-succeeded.sh
32 changes: 32 additions & 0 deletions .buildkite/hooks/pre-command
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash

set -e

if echo "$BUILDKITE_PLUGINS" | grep "cache-buildkite-plugin"; then
if ! which aws; then
echo "pwd: $PWD"
ls

AWS_TEMPDIR="$(mktemp -d -t "awscli-XXXXXXXX")"
pushd "$AWS_TEMPDIR"
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
ls
popd
rm -rf "$AWS_TEMPDIR"

echo "pwd: $PWD"
ls

# From https://sourcegraph.sourcegraph.com/github.com/sourcegraph/sourcegraph/-/blob/enterprise/cmd/server/pre-build.sh?L40-47
AWS_CONFIG_DIR_PATH="/buildkite/.aws"
mkdir -p "$AWS_CONFIG_DIR_PATH"
AWS_CONFIG_FILE="$AWS_CONFIG_DIR_PATH/config"
export AWS_CONFIG_FILE
AWS_SHARED_CREDENTIALS_FILE="/buildkite/.aws/credentials"
export AWS_SHARED_CREDENTIALS_FILE
aws configure set aws_access_key_id "$BUILDKITE_HMAC_KEY" --profile buildkite
aws configure set aws_secret_access_key "$BUILDKITE_HMAC_SECRET" --profile buildkite
fi
fi
65 changes: 65 additions & 0 deletions .buildkite/linters.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/bin/bash

set -euo pipefail
export JOB_NAME=linters

# shellcheck source=SCRIPTDIR/tools/setup-bazel.sh
source .buildkite/tools/setup-bazel.sh

set -x
globalErr=0

echo "~~~ Checking build files"
if ! ./tools/scripts/format_build_files.sh -t &> buildifier; then
globalErr=1
echo "^^^ +++"
buildkite-agent annotate --context tools/scripts/format_build_files.sh --style error --append < buildifier
fi

echo "~~~ Checking c++ formatting"
if ! ./tools/scripts/format_cxx.sh -t &> format_cxx; then
globalErr=1
echo "^^^ +++"
buildkite-agent annotate --context tools/scripts/format_cxx.sh --style error --append < format_cxx
fi

echo "~~~ Checking that the compilation db builds"
if ! ./tools/scripts/build_compilation_db.sh &> compdb; then
globalErr=1
echo "^^^ +++"
buildkite-agent annotate --context tools/scripts/build_compilation_db.sh --style error --append < compdb
fi

# Skip this because bazel query is failing due to third-party stuff
# echo "~~~ Checking compilation db targets"
# if ! ./tools/scripts/generate_compdb_targets.sh -t &> compdb-targets; then
# globalErr=1
# echo "^^^ +++"
# buildkite-agent annotate --context tools/scripts/generate_compdb_targets.sh --style error --append < compdb-targets
# fi

echo "~~~ Linting uses of \`using namespace std\`"
if ! ./tools/scripts/check_using_namespace_std.sh &> std_check; then
globalErr=1
echo "^^^ +++"
buildkite-agent annotate --context tools/scripts/check_using_namespace_std.sh --style error --append < std_check
fi

echo "~~~ Checking ErrorClass error code numbers"
if ! ./tools/scripts/check_error_classes.sh &> error_class_check; then
globalErr=1
echo "^^^ +++"
buildkite-agent annotate --context tools/scripts/check_error_classes.sh --style error --append < error_class_check
fi

echo "~~~ Running shellcheck"
if ! ./tools/scripts/lint_sh.sh -t &> lint_sh; then
globalErr=1
echo "^^^ +++"
buildkite-agent annotate --context tools/scripts/lint_sh.sh --style error --append < lint_sh
fi

echo "~~~"
if [ "$globalErr" -ne 0 ]; then
exit $globalErr
fi
30 changes: 30 additions & 0 deletions .buildkite/pipeline.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash

# Largely based off .sorbet-buildkite/pipeline.sh

set -euo pipefail

whitelisted=0

echo "BUILDKITE_PULL_REQUEST=$BUILDKITE_PULL_REQUEST"
echo "BUILDKITE_PULL_REQUEST_REPO=$BUILDKITE_PULL_REQUEST_REPO"

if [[ "$BUILDKITE_PULL_REQUEST" == "false" ]]; then
# whitelist commits that are triggered in branch builds of github.com/sourcegraph/scip-ruby
echo "Automatically running build for non-PR commit pushed to sourcegraph/scip-ruby"
whitelisted=1
fi

if [[ "$BUILDKITE_PULL_REQUEST_REPO" == "git://github.com/sourcegraph/scip-ruby.git" ]] ||
[[ "$BUILDKITE_PULL_REQUEST_REPO" == "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/sourcegraph/scip-ruby.git" ]]; then
# whitelist folks with write access to github.com/sorbet/sorbet
echo "Automatically running build for non-fork PR created against sourcegraph/scip-ruby"
whitelisted=1
fi

if [[ "${whitelisted}" -ne 1 ]] ; then
(echo -e "steps:\\n - block: \":key: Needs contributor approval!\"\\n - wait: ~\\n";
grep -v "steps:" .buildkite/pipeline.yaml ) | buildkite-agent pipeline upload
else
buildkite-agent pipeline upload
fi
52 changes: 52 additions & 0 deletions .buildkite/pipeline.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Loosely based off .sorbet-buildkite/pipeline.yaml

s3-settings: &s3-settings
backend: s3
s3:
bucket: sourcegraph_buildkite_cache
endpoint: https://storage.googleapis.com
profile: buildkite
region: us-central1
tarball: {}

bazel-repo-cache: &bazel-repo-cache
id: bazel-repos
key: "bazel-repos-{{ checksum WORKSPACE }}"
restore-keys:
- "bazel-repos-{{ checksum WORKSPACE }}"
- "bazel-repos-"
paths:
- /usr/local/var/bazelcache/repos
<<: *s3-settings

bazel-build-cache: &bazel-build-cache
id: bazel-build
key: "bazel-build-{{ env.BUILDKITE_COMMIT }}"
restore-keys:
- "bazel-build-{{ env.BUILDKITE_COMMIT }}"
- "bazel-build-"
paths:
- /usr/local/var/bazelcache/build
<<: *s3-settings

steps:
- label: ":linux: test-indexer.sh"
command: .buildkite/test-indexer.sh
artifact_paths:
- "_out_/profile*.json"
agents:
queue: stateless
env:
AWS_CONFIG_FILE: /buildkite/.aws/config
AWS_SHARED_CREDENTIALS_FILE: /buildkite/.aws/credentials
plugins:
- https://github.com/sourcegraph/cache-buildkite-plugin.git#master: *bazel-repo-cache
- https://github.com/sourcegraph/cache-buildkite-plugin.git#master: *bazel-build-cache

- wait: ~

# Success Phase - Allow the PR to be merged
- label: "All tests and builds succeeded"
command: .buildkite/all-succeeded.sh

- wait: ~
128 changes: 128 additions & 0 deletions .buildkite/test-indexer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#!/usr/bin/env bash

# Largely based off test-compiler.sh from the Sorbet buildkite config.

get_date() {
date '+%s'
}
PREV_TIME="$(get_date)"
PREV_CMD=""
print_time_elapsed() {
CUR_TIME="$(get_date)"
local DELTA=$(( CUR_TIME - PREV_TIME ))
if [ "$DELTA" -ne 0 ]; then
echo "Ran in ${DELTA}s: $PREV_CMD\n"
fi
PREV_CMD="$BASH_COMMAND"
PREV_TIME="$CUR_TIME"
}
trap print_time_elapsed DEBUG

set -euo pipefail

unameOut="$(uname -s)"
case "${unameOut}" in
Linux*) platform="linux";;
Darwin*) platform="mac";;
*) exit 1
esac

if [[ "linux" == "$platform" ]]; then
apt-get update
apt-get install -yy libncurses5-dev libncursesw5-dev xxd
elif [[ "mac" == "$platform" ]]; then
if ! [ -x "$(command -v wget)" ]; then
brew install wget
fi
fi

export JOB_NAME=test
source .buildkite/tools/setup-bazel.sh

err=0

echo "--- Building"

mkdir -p _out_

# `-c opt` is required, otherwise the tests are too slow
# forcedebug is really the ~only thing in `--config=dbg` we care about.
# must come after `-c opt` because `-c opt` will define NDEBUG on its own
build_args=(
"//main:scip-ruby"
"//test:scip_test_runner"
"-c" "opt"
"--config=forcedebug"
"--spawn_strategy=local"
)

./bazel build \
--experimental_generate_json_trace_profile \
--profile=_out_/profile_build.json \
"${build_args[@]}" || err=$?

echo "+++ Running snapshot tests"

test_args=(
"//test/scip"
"-c" "opt"
"--config=forcedebug"
"--spawn_strategy=local"
)

./bazel test \
--experimental_generate_json_trace_profile \
--profile=_out_/profile_snapshot_tests.json \
--test_summary=terse \
--test_output=errors \
"${test_args[@]}" || err=$?

echo "--- Installing Ruby"

# From https://github.com/asdf-vm/asdf-ruby/issues/125#issuecomment-958941354
rm -rf .asdf/shims
OPENSSL_CFLAGS=-Wno-error=implicit-function-declaration asdf install ruby
asdf global ruby 2.7.0

echo "+++ Running repo tests"

test_args=(
"//test/scip/repos"
"-c" "opt"
"--test_env" "PATH=${PATH}"
"--test_env" "HOME=${HOME}"
"--config=forcedebug"
"--spawn_strategy=local"
)

./bazel test \
--experimental_generate_json_trace_profile \
--profile=_out_/profile_repo_tests.json \
--test_summary=terse \
--test_output=errors \
"${test_args[@]}" || err=$?

if [ "$err" -ne 0 ]; then
echo "--- annotating build result"
failing_tests="$(mktemp)"

echo 'Run this command to run failing tests locally:' >> "$failing_tests"
echo >> "$failing_tests"
echo '```bash' >> "$failing_tests"
echo "./bazel test \\" >> "$failing_tests"

# Take the lines that start with target labels.
# Lines look like "//foo FAILED in 10s"
{ ./bazel test --test_summary=terse "${test_args[@]}" || true ; } | \
grep '^//' | \
sed -e 's/ .*/ \\/' | \
sed -e 's/^/ /' >> "$failing_tests"

# Put this last as an easy way to not have a `\` on the last line.
echo ' -c opt --config=forcedebug' >> "$failing_tests"
echo '```' >> "$failing_tests"

buildkite-agent annotate --context "test-indexer.sh" --style error --append < "$failing_tests"

exit "$err"
fi
1 change: 1 addition & 0 deletions .buildkite/tools
64 changes: 64 additions & 0 deletions .buildkite/unused-hooks/gh-status
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env bash

set -e
[ -z "$DEBUG" ] || set -x;

usage() {
echo "$0 <repo> <commit> <state> <target_url> <context>" >&2;
}

if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
usage
cat >&2 <<EOS
NOTE:
valid states are "error", "failure", "pending" and "success"

This uses your \`.netrc\` file to authenticate with GitHub. In order to run the
script, make sure you have \`api.github.com\` in
this file. For example:
machine api.github.com
login foca
password <an access token>
Generate this access token at https://github.com/settings/tokens and make sure
it has access to the \`"repo"\` scope.
EOS
exit 1;
fi

[ -n "$5" ] || (usage; exit 1);

REPO="$1"
shift

COMMIT="$1"
shift

STATE="$1"
shift

TARGET_URL="$1"
shift

CONTEXT="$1"
shift

BODY=""
[ -t 0 ] || BODY=$(cat);

payload=$(
jq --null-input \
--arg state "$STATE" \
--arg target_url "$TARGET_URL" \
--arg description "$DESCRIPTION" \
--arg context "$CONTEXT" \
'{ state: $state, target_url: $target_url, description: $description, context: $context}'
)

response=$(
curl --fail \
--netrc \
--silent \
--location \
--data "$payload" \
"https://api.github.com/repos/${REPO}/statuses/${COMMIT}"
)
12 changes: 12 additions & 0 deletions .buildkite/unused-hooks/post-command
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

set -euo pipefail
if [ "HEAD" == "${BUILDKITE_COMMIT}" ]; then
echo "not using commit marks as this is HEAD build"
else
if [ "$BUILDKITE_COMMAND_EXIT_STATUS" -ne 0 ]; then
.buildkite/hooks/gh-status sourcegraph/scip-ruby "${BUILDKITE_COMMIT}" failure "${BUILDKITE_BUILD_URL}#${BUILDKITE_JOB_ID}" "${BUILDKITE_LABEL}"
else
.buildkite/hooks/gh-status sourcegraph/scip-ruby "${BUILDKITE_COMMIT}" success "${BUILDKITE_BUILD_URL}#${BUILDKITE_JOB_ID}" "${BUILDKITE_LABEL}"
fi
fi
Loading