diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml deleted file mode 100644 index 943068e18..000000000 --- a/.github/workflows/go.yml +++ /dev/null @@ -1,44 +0,0 @@ -name: Go - -on: - push: - branches: - - main - - v[0-9]* - pull_request: - branches: - - main - - v[0-9]* - -jobs: - test: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 - with: - go-version-file: "src/go.mod" - - run: go run github.com/onsi/ginkgo/v2/ginkgo -r --randomize-all --randomize-suites --fail-on-pending --keep-going --race --trace - working-directory: src - - vet: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 - with: - go-version-file: "src/go.mod" - - run: go vet $(go list ./... | grep -v internal/promql$) - working-directory: src - - lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-go@v5 - with: - go-version-file: "src/go.mod" - - uses: golangci/golangci-lint-action@v4.0.0 - with: - args: --config .golangci.yml - working-directory: src diff --git a/.github/workflows/scripts.yml b/.github/workflows/scripts.yml new file mode 100644 index 000000000..c96560119 --- /dev/null +++ b/.github/workflows/scripts.yml @@ -0,0 +1,30 @@ +name: scripts + +on: + push: + branches: + - main + - v[0-9]* + pull_request: + branches: + - main + - v[0-9]* + +jobs: + unit-test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: "src/go.mod" + - run: ./scripts/subtests/unit-test + + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: "src/go.mod" + - run: ./scripts/subtests/lint diff --git a/scripts/deploy-bosh-lite b/scripts/deploy-bosh-lite deleted file mode 100755 index cb9bbe848..000000000 --- a/scripts/deploy-bosh-lite +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -bosh -e lite -d log-cache deploy manifests/log-cache.yml \ - --vars-store deployment-vars.yml \ - --vars-file /tmp/loggregator-vars.yml \ - --var system_domain=bosh-lite.com \ - --var datadog_api_key="$DATADOG_API_KEY" \ - --no-redact diff --git a/scripts/operations/cf-auth-proxy.yml b/scripts/operations/cf-auth-proxy.yml deleted file mode 100644 index 4e5a049cf..000000000 --- a/scripts/operations/cf-auth-proxy.yml +++ /dev/null @@ -1,48 +0,0 @@ -- type: replace - path: /instance_groups/name=log-cache/jobs/- - value: - name: route_registrar - release: routing - properties: - route_registrar: - routes: - - name: log-cache-reverse-proxy - port: 8083 #TODO: pull from a bosh link - registration_interval: 20s - uris: - - log-cache.((system_domain)) - - "*.log-cache.((system_domain))" - -- type: replace - path: /instance_groups/name=log-cache/jobs/- - value: - name: log-cache-cf-auth-proxy - release: log-cache - properties: - proxy_port: 8083 - cc: - capi_internal_addr: "https://cloud-controller-ng.service.cf.internal:9023" - ca_cert: "((log_cache_tls_cc_auth_proxy.ca))" - common_name: cloud-controller-ng.service.cf.internal - cert: "((log_cache_tls_cc_auth_proxy.certificate))" - key: "((log_cache_tls_cc_auth_proxy.private_key))" - uaa: - client_id: doppler - client_secret: "((uaa_clients_doppler_secret))" - internal_addr: https://uaa.service.cf.internal:8443 - ca_cert: "((uaa_ca.certificate))" - -- type: replace - path: /instance_groups/name=log-cache/jobs/name=log-cache-gateway/properties?/gateway_addr? - value: localhost:8081 - -- type: replace - path: /variables/- - value: - name: log_cache_tls_cc_auth_proxy - type: certificate - options: - ca: service_cf_internal_ca - common_name: log-cache - extended_key_usage: - - client_auth diff --git a/scripts/subtests/lint b/scripts/subtests/lint new file mode 100755 index 000000000..bb8f5c95b --- /dev/null +++ b/scripts/subtests/lint @@ -0,0 +1,18 @@ +#!/bin/bash + +set -eux +set -o pipefail + +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" + +set +e +golangci_lint_executable=$(which golangci-lint) +set -e +if [ -z "${golangci_lint_executable}" ] || [ ! -x "${golangci_lint_executable}" ]; then + go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest +fi + +pushd "${SCRIPT_DIR}/../../src" > /dev/null + golangci-lint run ./... +popd > /dev/null + diff --git a/scripts/subtests/unit-test b/scripts/subtests/unit-test new file mode 100755 index 000000000..1d50d7eea --- /dev/null +++ b/scripts/subtests/unit-test @@ -0,0 +1,11 @@ +#!/bin/bash + +set -eux +set -o pipefail + +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" + +pushd "${SCRIPT_DIR}/../../src" > /dev/null + go run github.com/onsi/ginkgo/v2/ginkgo -r -p --randomize-all --randomize-suites --fail-on-pending --keep-going --race --trace +popd > /dev/null + diff --git a/scripts/test b/scripts/test index 9264fdc2b..382cecd0a 100755 --- a/scripts/test +++ b/scripts/test @@ -1,253 +1,10 @@ #!/bin/bash -trap "echo Exited!; exit 1;" SIGINT SIGTERM +set -eux +set -o pipefail -PROJECT_DIR="$(cd "$(dirname "$0")/.."; pwd)" +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" -function print_usage { - echo "usage: test [subcommand] [go test args]" - echo - echo -e "\033[1mSubcommands:\033[0m" - echo " all Run all the tests, excluding linters (default)" - echo " cleaners Run tools that clean the code base" - echo " unit Run the unit tests" - echo " linters Run common linters against the project" - echo " ops_files Run tests for operation files" - echo " install_tools Install all necessary binaries for these scripts" -} +"${SCRIPT_DIR}/subtests/lint" +"${SCRIPT_DIR}/subtests/unit-test" -function print_checkpoint { - echo - bold_blue "================================== $@" -} - -function green { - echo -e "\e[32m$1\e[0m" -} - -function red { - echo -e "\e[31m$1\e[0m" -} - -function bold_blue { - echo -e "\e[1;34m$1\e[0m" -} - -function check_output { - eval "$@" - local status=$? - exit_on_failure $status -} - -function exit_on_failure { - if [[ $1 -ne 0 ]]; then - red "SUITE FAILURE" - exit $1 - fi -} - -function run_cleaners { - print_checkpoint "Running Cleaners" - - go get github.com/kisielk/gotool - - if ! which goimports > /dev/null 2>&1; then - echo installing goimports - go get golang.org/x/tools/cmd/goimports - fi - if ! which misspell > /dev/null 2>&1; then - echo installing misspell - go get github.com/client9/misspell/cmd/misspell - fi - if ! which unconvert > /dev/null 2>&1; then - echo installing unconvert - go get github.com/mdempsky/unconvert - fi - - local log_cache_pkg="code.cloudfoundry.org/log-cache" - local log_cache_dir="$(dirname $(dirname $0))/src/$log_cache_pkg" - echo running goimports - goimports -w "$log_cache_dir" - echo running gofmt - gofmt -s -w "$log_cache_dir" - echo running misspell - misspell -w "$log_cache_dir" - echo running unconvert - unconvert -v -apply "$log_cache_pkg/..." - echo running go vet - go vet "$log_cache_pkg/..." - return 0 -} - -function run_unit { - pushd $PROJECT_DIR/src > /dev/null - TEST_OPTIONS="-ginkgo.randomizeAllSpecs -ginkgo.slowSpecThreshold 20" - - # The race detector dramatically increases the runtime of certain tests - # As a result, we first run the tests with race detection - # enabled, but only consider actual data races as failures. We then run the test suite - # without race detection and assert on test correctness. - print_checkpoint "Checking for Data Races" - race_log=$(mktemp log_cache_race_log.XXXXXXXX --tmpdir) - - go test -mod=vendor -race ./... \ - ${TEST_OPTIONS} \ - $@ 2>&1 > ${race_log} || true - if egrep 'DATA RACE|race detected' ${race_log}; then - cat ${race_log} - rm ${race_log} - return 1 - fi - rm ${race_log} - echo "No races found" - - print_checkpoint "Running Unit Tests" - go test ./... \ - ${TEST_OPTIONS} \ - $@ - exit_code=$? - popd > /dev/null - return $exit_code -} - -function run_all { - check_output run_cleaners - check_output run_unit $@ -} - -function parse_argc { - command=run_all - if [[ $# -eq 0 ]]; then - return - fi - - arg=$1 - case "$arg" in - -h|-help|--help|help) - print_usage - exit 0 - ;; - all|unit|cleaners|linters|install_tools|ops_files) - command=run_$arg - ;; - *) - echo "Invalid command: $arg\n" - print_usage - exit 1 - ;; - esac -} - -function run_install_tools { - print_checkpoint "Installing Tools" - - # testing - go get github.com/onsi/ginkgo/ginkgo - - # cleaners - go get golang.org/x/tools/cmd/goimports - go get github.com/client9/misspell/cmd/misspell - go get github.com/mdempsky/unconvert - - # linters - go get github.com/tsenart/deadcode - go get github.com/golang/lint/golint - go get github.com/opennota/check/cmd/aligncheck - go get github.com/opennota/check/cmd/structcheck - go get github.com/opennota/check/cmd/varcheck - go get github.com/kisielk/errcheck - go get github.com/gordonklaus/ineffassign - go get mvdan.cc/interfacer - go get honnef.co/go/tools/cmd/megacheck -} - -function run_linters { - print_checkpoint "Running Linters" - - local log_cache_pkg - if [ "$1" = "" ]; then - log_cache_pkg="code.cloudfoundry.org/log-cache" - else - log_cache_pkg="$1" - fi - local log_cache_dir="$(dirname $(dirname $0))/src/$log_cache_pkg" - - echo running go vet - go vet "$log_cache_pkg/..." - echo running deadcode - deadcode $dir - echo running golint - golint "$log_cache_pkg/..." - echo running aligncheck - aligncheck "$log_cache_pkg/..." - echo running structcheck - structcheck "$log_cache_pkg/..." - echo running varcheck - varcheck "$log_cache_pkg/..." - echo running errcheck - errcheck -ignore '[cC]lose' "$log_cache_pkg/..." - echo running ineffassign - ineffassign "$log_cache_dir" - echo running interfacer - interfacer "$log_cache_pkg/..." - echo running megacheck - megacheck "$log_cache_pkg/..." - - return 0 -} - -function run_ops_files { - print_checkpoint "Running Operation File Tests" - - pushd $PROJECT_DIR > /dev/null - echo creating deploy-in-cf.yml ops file - tmp_dir=`mktemp -d` - - cat < $tmp_dir/consumes_cf.yml -- type: replace - path: /instance_groups/name=log-cache/jobs/name=log-cache/consumes/reverse_log_proxy/deployment? - value: cf -EOF - - bosh int manifests/log-cache.yml --ops-file=$tmp_dir/consumes_cf.yml > $tmp_dir/adjusted.yml - - ops_file_path=manifests/operations/deploy-in-cf.yml - instance_groups=`bosh int $tmp_dir/adjusted.yml --path /instance_groups | sed 's/^\-/ /' | sed 's/^/ /'` - variables=`bosh int $tmp_dir/adjusted.yml --path /variables | sed 's/^\-/ /' | sed 's/^/ /'` - - cat < manifests/operations/deploy-in-cf.yml -- type: replace - path: /releases/- - value: - name: log-cache - version: latest -- type: replace - path: /instance_groups/- - value: -$instance_groups -- type: replace - path: /variables/- - value: -$variables -EOF - popd > /dev/null - - return 0 -} - -function setup_env { - export PATH="$PROJECT_DIR/bin:$PATH" - export GORACE="halt_on_error=1" -} - -function main { - setup_env - parse_argc $1 - shift - "$command" $@ - result=$? - exit_on_failure $result - green "SWEET SUITE SUCCESS" -} - -main $@