Files
threshold/.gitea/workflows/ci.yml
T

112 lines
4.6 KiB
YAML

name: ci
on:
push:
branches: [main]
tags-ignore: ["**"]
pull_request:
workflow_dispatch:
schedule:
- cron: "17 5 * * *" # nightly vuln rescan
# One job on purpose: the shared runner pool is small, so all modules are
# checked sequentially on a single runner instead of a 15-way matrix.
jobs:
check:
runs-on: ubuntu-latest
timeout-minutes: 90
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: .go-version
cache: false
- name: install scanners
run: |
go install golang.org/x/vuln/cmd/govulncheck@latest
go install github.com/google/osv-scanner/v2/cmd/osv-scanner@latest
- name: build, vet, govulncheck, tests per module
shell: bash
run: |
export PATH="$(go env GOPATH)/bin:$PATH"
modules=$(find . -name go.mod -printf '%h\n' | sort)
failed=()
for m in $modules; do
echo "::group::$m"
(
set -e
cd "$m"
go build ./...
# composites: pre-existing upstream test-file warnings
go vet -composites=false ./...
govulncheck ./...
case "$m" in ./api|./sdk) go test ./... ;; esac # root needs Postgres
) || failed+=("$m")
echo "::endgroup::"
done
if [ ${#failed[@]} -gt 0 ]; then
echo "FAILED modules: ${failed[*]}"; exit 1
fi
- name: osv-scanner
run: osv-scanner scan source -r .
# DB-backed Go tests need Postgres 16 with a pre-migrated template database.
# The image is built from testing/dbtest/docker (not HashiCorp's Docker Hub
# image) and published on 127.0.0.1:55432 because the tests hardcode loopback.
# Skipped on pull requests to spare the shared runner pool.
db-tests:
if: github.event_name != 'pull_request'
runs-on: ubuntu-latest
timeout-minutes: 120
env:
TEST_DB_PORT: "55432"
PG_CONTAINER: threshold-sql-tests-${{ github.run_id }}
steps:
- name: require docker
run: |
if ! docker info >/dev/null 2>&1; then
echo "::error::this runner has no usable docker; db-tests need it"; exit 1
fi
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: .go-version
cache: false
- name: start postgres (pre-migrated template)
shell: bash
run: |
set -euo pipefail
docker build -q -t threshold-test-pg:16 -f testing/dbtest/docker/Dockerfile.16-alpine testing/dbtest/docker
mkdir -p "$RUNNER_TEMP/benchmark_dumps"
docker run -d --name "$PG_CONTAINER" -p "$TEST_DB_PORT:5432" \
-e POSTGRES_PASSWORD=boundary -e POSTGRES_USER=boundary -e POSTGRES_DB=boundary \
-e PGDATA=/pgdata --mount type=tmpfs,destination=/pgdata \
-v "$PWD/internal/db/schema/migrations:/migrations" \
-v "$RUNNER_TEMP/benchmark_dumps:/benchmark_dumps" \
threshold-test-pg:16 -c config_file=/etc/postgresql/postgresql.conf
# init scripts run on a temporary server first; wait for the real one
for i in $(seq 1 120); do
if docker logs "$PG_CONTAINER" 2>&1 | grep -q "init process complete" \
&& docker exec "$PG_CONTAINER" pg_isready -U boundary -d boundary >/dev/null 2>&1; then
echo "postgres ready"; exit 0
fi
sleep 3
done
docker logs "$PG_CONTAINER" | tail -30; echo "::error::postgres did not become ready"; exit 1
- name: go test (root module, DB-backed)
shell: bash
run: |
# Excluded: tests that start their own dev-DB/Vault containers via
# dockertest and then dial the mapped host port, which is unreachable
# from inside this job's container (internal/cmd/commands/server also
# fails the same way on untouched upstream).
pkgs=$(go list ./... | grep -v -E '/testing/internal/e2e|/enos/|/internal/tests/(cli|api)|/internal/cmd/commands/server$|/internal/credential/vault$|/internal/daemon/controller$|/internal/daemon/controller/handlers/credentialstores$')
# *Estimated*Count / ListDeletedStoreIds depend on pg planner stats and
# also fail on untouched upstream Boundary (verified); skipped here.
go test $pkgs -count=1 -p 2 -timeout 90m \
-skip 'EstimatedCount|EstimatedCredentialCount|EstimatedLibraryCount|ListDeletedStoreIds'
- name: stop postgres
if: always()
run: docker rm -f -v "$PG_CONTAINER" || true