Files

277 lines
13 KiB
YAML

name: CI
on:
# Every branch push runs CI, not just the release branches. A feature branch
# that never gets a run is a branch whose breakage is invisible until someone
# opens a PR and waits; catching it at push time is the whole point of having
# the workflow. Tags are excluded because they are not branch state.
push:
branches:
- "**"
tags-ignore:
- "**"
pull_request:
workflow_dispatch:
workflow_call:
permissions:
contents: read
concurrency:
group: ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
go-test:
name: Go tests
runs-on: ubuntu-24.04
timeout-minutes: 45
services:
inventory-postgres:
image: postgres:17-alpine
env:
POSTGRES_USER: inventory
POSTGRES_PASSWORD: inventory-test
POSTGRES_DB: gift_inventory_test
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U inventory -d gift_inventory_test"
--health-interval 5s --health-timeout 5s --health-retries 12
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Set up Go
uses: actions/setup-go@v7
with:
go-version-file: go.mod
cache-dependency-path: go.sum
- name: Download Go modules
run: go mod download
- name: Check reachable Go vulnerabilities
run: go run golang.org/x/vuln/cmd/govulncheck@v1.9.0 ./...
- name: Test
run: go test ./... -count=1
- name: Verify legacy Compose credentials and volume upgrade
env:
TELESRV_RUN_COMPOSE_INTEGRATION: '1'
run: go test ./deploy -run '^TestLegacyComposeCredentialsIntegration$' -count=1 -timeout=5m
- name: Verify gift inventory and Stars ledger against PostgreSQL
env:
TELESRV_TEST_POSTGRES_DSN: postgres://inventory:inventory-test@127.0.0.1:5432/gift_inventory_test?sslmode=disable
run: go test ./internal/store/postgres -run '^(TestStarGiftAuctionEarlyBidsPostgres|TestStarGiftFreeUpgradePostgres|TestStarGiftAuctionDurationSurvivesCatalogReloadPostgres|TestOfficialStarGiftInventoryPostgres|TestOfficialStarGiftBundleIsAtomicPostgres|TestStarGiftStorePostgres|TestStarsLedgerPostgres|TestBotGiftPurchaseIsNotConvertibleToStarsPostgres|TestStarGiftDeleteRemovesGiftFromProfilePostgres|TestStarGiftDeleteRefusesUpgradedGiftPostgres|TestStarGiftDeleteRefreshesCollectionHashPostgres|TestStarGiftDeleteRefusesIrreversibleGiftsPostgres|TestStarGiftDeleteBlocksLaterUpgradePostgres)$' -count=1 -timeout=3m
- name: Verify admin operator and audit command flow against PostgreSQL
env:
TELESRV_TEST_POSTGRES_DSN: postgres://inventory:inventory-test@127.0.0.1:5432/gift_inventory_test?sslmode=disable
run: go test ./cmd/telesrv-admin -run '^(TestOperatorCommand|TestOperatorCreateRoute|TestOperatorUniqueness|TestNamedOperator|TestDemotion|TestAuditTrail)' -count=1 -timeout=5m
- name: Imported gift auction PostgreSQL regression
env:
TELESRV_TEST_POSTGRES_DSN: postgres://inventory:inventory-test@127.0.0.1:5432/gift_inventory_test?sslmode=disable
run: go test ./internal/admin -run '^TestImportedGiftAuctionBundlePostgres$' -count=1 -timeout=3m
- name: Verify fact-check persistence and visibility against PostgreSQL
env:
TELESRV_TEST_POSTGRES_DSN: postgres://inventory:inventory-test@127.0.0.1:5432/gift_inventory_test?sslmode=disable
run: go test ./internal/store/postgres -run '^TestChannelFactCheck' -count=1 -timeout=3m
admin-web:
name: Admin web build
runs-on: ubuntu-24.04
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Set up Node
uses: actions/setup-node@v6
with:
node-version: '22'
cache: npm
cache-dependency-path: cmd/telesrv-admin/web/package-lock.json
- name: Install dependencies
working-directory: cmd/telesrv-admin/web
run: npm ci
- name: Build
working-directory: cmd/telesrv-admin/web
run: npm run build
- name: Check the generated API-doc tables
# docs/admin-panel-api.{en,ru}.md carry route and permission tables
# generated from nav.ts / permissions.tsx / security.go. They drifted
# badly once because nothing compared them to the source, so the check
# is the whole point: it fails when a page or a right is added and the
# docs are not regenerated with
# python3 scripts/gen_admin_panel_doc_tables.py --write
run: python3 scripts/gen_admin_panel_doc_tables.py --check
grammystore:
name: Grammy store bot
runs-on: ubuntu-24.04
timeout-minutes: 15
services:
postgres:
image: postgres:16-alpine
env:
POSTGRES_DB: grammystore_test
POSTGRES_USER: test_user
POSTGRES_PASSWORD: test_password
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U test_user -d grammystore_test"
--health-interval 5s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Set up Node
uses: actions/setup-node@v6
with:
node-version: '22'
cache: npm
cache-dependency-path: cmd/bots/grammystore/package-lock.json
- name: Install dependencies
working-directory: cmd/bots/grammystore
run: npm ci
- name: Check syntax
working-directory: cmd/bots/grammystore
run: npm run check
- name: Test
working-directory: cmd/bots/grammystore
env:
DATABASE_URL: postgres://test_user:test_password@localhost:5432/grammystore_test
BOT_TOKEN: "999:TEST"
OWNER_IDS: "1"
GRAMSRV_TOKEN: "test-token"
CODE_WEBHOOK_SECRET: "abcdefghijklmnopqrstuvwxyz1234"
run: npm test
docker-smoke:
name: Docker main topology smoke
runs-on: ubuntu-24.04
timeout-minutes: 30
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Generate isolated environment
run: ./scripts/new-docker-env.sh --advertise-ip 127.0.0.1
- name: Validate deployment inputs
run: |
docker compose version
sh -n scripts/new-docker-env.sh
bash -n scripts/start-docker.sh
bash -n scripts/backup.sh
bash -n scripts/restore.sh
bash -n scripts/check-media.sh
sh -n deploy/docker/docker-entrypoint.sh
compose=(docker compose -p telesrv-main-ci --project-directory deploy/docker --env-file deploy/docker/.env -f deploy/docker/compose.yaml)
bridge=("${compose[@]}" -f deploy/docker/compose.bridge-network.yaml)
"${compose[@]}" config --quiet
# Every path telesrv writes to must live on the /var/lib/telesrv volume.
# The container rootfs is read_only, so a data path with a relative
# default that compose forgets to pin kills the server at startup --
# which is exactly how TELESRV_WALLET_STATE_DIR took the stack down once.
"${compose[@]}" config --format json | python3 -c 'import json,sys; s=json.load(sys.stdin)["services"]; assert s["server"].get("network_mode") == "host"; assert s["admin"].get("network_mode") == "host"; assert len(s["server"].get("ports", [])) == 0; assert len(s["admin"].get("ports", [])) == 0; assert str(s["server"]["environment"]["TELESRV_TURN_RELAY_MAX_PORT"]) == "12999"; _e = s["server"]["environment"]; assert not _e["TELESRV_WALLET_STATE_DIR"] or _e["TELESRV_WALLET_STATE_DIR"].startswith("/var/lib/telesrv/"); assert _e["TELESRV_WALLET_KEY_FILE"].startswith("/var/lib/telesrv")'
"${bridge[@]}" config --quiet
"${bridge[@]}" config --format json | python3 -c 'import json,sys; c=json.load(sys.stdin); s=c["services"]; assert s["server"].get("network_mode") != "host"; assert s["admin"].get("network_mode") != "host"; assert len(s["server"].get("ports", [])) == 69; assert len(s["admin"].get("ports", [])) == 1; assert "admin_host_access" in s["admin"]["networks"]; assert not c["networks"]["admin_host_access"].get("internal", False); assert str(s["server"]["environment"]["TELESRV_TURN_RELAY_MAX_PORT"]) == "12563"'
- name: Validate PowerShell launchers
shell: pwsh
run: |
$tokens = $null
$errors = $null
[void][System.Management.Automation.Language.Parser]::ParseFile("scripts/new-docker-env.ps1", [ref]$tokens, [ref]$errors)
if ($errors.Count -gt 0) { $errors | ForEach-Object { Write-Error $_ }; exit 1 }
$tokens = $null
$errors = $null
[void][System.Management.Automation.Language.Parser]::ParseFile("scripts/start-docker.ps1", [ref]$tokens, [ref]$errors)
if ($errors.Count -gt 0) { $errors | ForEach-Object { Write-Error $_ }; exit 1 }
foreach ($launcher in @("scripts/backup.ps1", "scripts/restore.ps1", "scripts/check-media.ps1")) {
$tokens = $null
$errors = $null
[void][System.Management.Automation.Language.Parser]::ParseFile($launcher, [ref]$tokens, [ref]$errors)
if ($errors.Count -gt 0) { $errors | ForEach-Object { Write-Error $_ }; exit 1 }
}
- name: Build application images
run: |
compose=(docker compose -p telesrv-main-ci --project-directory deploy/docker --env-file deploy/docker/.env -f deploy/docker/compose.yaml)
"${compose[@]}" build --pull server admin
- name: Start and wait for readiness
run: docker compose -p telesrv-main-ci --project-directory deploy/docker --env-file deploy/docker/.env -f deploy/docker/compose.yaml up -d --no-build --wait --wait-timeout 600
- name: Verify runtime and media listeners
run: |
compose=(docker compose -p telesrv-main-ci --project-directory deploy/docker --env-file deploy/docker/.env -f deploy/docker/compose.yaml)
for service in server admin; do
container_id="$("${compose[@]}" ps --quiet "$service")"
test -n "$container_id"
test "$(docker inspect --format '{{.Config.User}}' "$container_id")" = "10001:10001"
test "$(docker inspect --format '{{.HostConfig.ReadonlyRootfs}}' "$container_id")" = "true"
test "$(docker inspect --format '{{json .HostConfig.CapDrop}}' "$container_id")" = '["ALL"]'
test "$(docker inspect --format '{{.HostConfig.PidsLimit}}' "$container_id")" = "1024"
test "$(docker inspect --format '{{json .HostConfig.SecurityOpt}}' "$container_id")" = '["no-new-privileges:true"]'
test "$(docker inspect --format '{{.HostConfig.NetworkMode}}' "$container_id")" = "host"
done
# The wallet state directory holds per-account key material and
# NewFileStore refuses anything group- or world-accessible. Assert the
# mode on the mounted volume rather than trusting the image build: a
# permissive mode here is what stopped the server from booting.
server_container="$("${compose[@]}" ps --quiet server)"
test "$(docker exec "$server_container" stat -c %a /var/lib/telesrv/wallet)" = "700"
curl --fail --silent --show-error http://127.0.0.1:2401/healthz | grep -qx ok
curl --fail --silent --show-error http://127.0.0.1:2600/ >/dev/null
timeout 5 bash -c 'exec 3<>/dev/tcp/127.0.0.1/2400'
python3 - <<'PY'
import os
import socket
import struct
transaction_id = os.urandom(12)
request = struct.pack("!HHI12s", 0x0001, 0, 0x2112A442, transaction_id)
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as client:
client.settimeout(5)
client.sendto(request, ("127.0.0.1", 12400))
response, _ = client.recvfrom(2048)
message_type, _, cookie = struct.unpack("!HHI", response[:8])
assert message_type == 0x0101, hex(message_type)
assert cookie == 0x2112A442, hex(cookie)
assert response[8:20] == transaction_id
PY
server_logs="$("${compose[@]}" logs --no-color server)"
case "$server_logs" in *"sfu listening"*) ;; *) echo "Embedded SFU did not become ready" >&2; exit 1 ;; esac
case "$server_logs" in *"turn listening"*) ;; *) echo "Embedded TURN did not become ready" >&2; exit 1 ;; esac
case "$server_logs" in *"live stream rtmp ingest listening"*) ;; *) echo "RTMP listener did not become ready" >&2; exit 1 ;; esac
- name: Show logs on failure
if: failure()
run: docker compose -p telesrv-main-ci --project-directory deploy/docker --env-file deploy/docker/.env -f deploy/docker/compose.yaml logs --no-color --tail 200
- name: Remove isolated stack
if: always()
run: docker compose -p telesrv-main-ci --project-directory deploy/docker --env-file deploy/docker/.env -f deploy/docker/compose.yaml down --volumes --remove-orphans