Files
DataStack/.gitea/workflows/datastack-ci.yml
T

426 lines
24 KiB
YAML

name: DataStack CI Verification
on:
push:
branches: [main]
paths:
- '.gitea/workflows/datastack-ci.yml'
# Base-owned PR workflow; never run fork-controlled code on self-hosted runners.
pull_request_target:
branches: [main]
types: [opened, reopened, synchronize]
paths-ignore:
- 'notes/**'
- '**/*.md'
workflow_dispatch:
inputs:
p01_only:
description: Run P01 tests, typecheck, build and Windows clean-install only
required: false
type: boolean
default: false
quality_only:
description: Run only TypeScript and ESLint after a focused P01 test type fix
required: false
type: boolean
default: false
python_only:
description: Narrow CI-06 Python job rerun after a proven runner setup failure
required: false
type: boolean
default: false
# CI needs repository read only; it never publishes artifacts or edits remotes.
permissions:
contents: read
jobs:
node-regression:
if: ${{ (github.event_name != 'pull_request_target' || (github.event.pull_request.head.repo.full_name == github.repository && github.event.pull_request.base.ref == 'main')) && (github.event_name != 'workflow_dispatch' || github.event.inputs.quality_only != 'true' && (github.event_name != 'workflow_dispatch' || github.event.inputs.python_only != 'true')) }}
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
with:
github-server-url: https://dev.ivib.cc
persist-credentials: false
ref: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}
- name: Install dependencies
run: npm ci --no-audit --no-fund
- name: Build Node SDK
run: |
npm --prefix sdk/node/datastack install --no-audit --no-fund
npm --prefix sdk/node/datastack run build
- name: Run all TypeScript regression suites with bounded isolation
run: |
set +e
failed=0
total=0
for file in tests/*.test.ts; do
total=$((total + 1))
echo "CI_SUITE_BEGIN $file"
timeout --signal=TERM --kill-after=5s 70s npx --yes tsx@4.20.6 --test "$file"
code=$?
echo "CI_SUITE_EXIT $file $code"
if [ "$code" -ne 0 ]; then failed=$((failed + 1)); fi
done
echo "CI_SUITE_SUMMARY total=$total failed=$failed"
test "$total" -eq 24 || exit 1
test "$failed" -eq 0
python-regression:
if: ${{ (github.event_name != 'pull_request_target' || (github.event.pull_request.head.repo.full_name == github.repository && github.event.pull_request.base.ref == 'main')) && (github.event_name != 'workflow_dispatch' || github.event.inputs.p01_only != 'true') }}
runs-on: ubuntu-latest
container: node:22-bookworm-slim
timeout-minutes: 20
steps:
- name: Install Bookworm Python and checkout prerequisites
run: |
set -eu
apt-get update -qq
apt-get install -y --no-install-recommends git ca-certificates python3 python3-venv python3-pip
- uses: actions/checkout@v4
with:
github-server-url: https://dev.ivib.cc
persist-credentials: false
ref: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}
- name: CI-06 Python 3.11 isolated virtual environment
run: |
set -eu
python3 --version
python3 -m venv /tmp/datastack-ci-venv
/tmp/datastack-ci-venv/bin/python -m pip install --disable-pip-version-check -e ./sdk/python/datastack -e ./sdk-python
- name: CI-06 compile and assert 14 Python SDK regressions
run: |
set -eu
py=/tmp/datastack-ci-venv/bin/python
"$py" -m compileall -q ./sdk/python/datastack ./sdk-python
"$py" -m unittest discover -s tests -p '*_test.py' -v > /tmp/datastack-python-tests.log 2>&1 || { cat /tmp/datastack-python-tests.log; exit 1; }
cat /tmp/datastack-python-tests.log
grep -Eq '^Ran 14 tests in ' /tmp/datastack-python-tests.log
grep -Eq '^OK$' /tmp/datastack-python-tests.log
echo DATASTACK_PYTHON_14_OF_14_PASS
quality:
if: ${{ (github.event_name != 'pull_request_target' || (github.event.pull_request.head.repo.full_name == github.repository && github.event.pull_request.base.ref == 'main')) && (github.event_name != 'workflow_dispatch' || github.event.inputs.python_only != 'true') }}
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v4
with:
github-server-url: https://dev.ivib.cc
persist-credentials: false
ref: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}
- name: Install dependencies
run: npm ci --no-audit --no-fund
- name: TypeScript type check
run: npx tsc --noEmit
- name: ESLint
run: npm run lint
production-build:
if: ${{ (github.event_name != 'pull_request_target' || (github.event.pull_request.head.repo.full_name == github.repository && github.event.pull_request.base.ref == 'main')) && (github.event_name != 'workflow_dispatch' || github.event.inputs.quality_only != 'true' && (github.event_name != 'workflow_dispatch' || github.event.inputs.python_only != 'true')) }}
runs-on: ubuntu-latest
timeout-minutes: 25
steps:
- uses: actions/checkout@v4
with:
github-server-url: https://dev.ivib.cc
persist-credentials: false
ref: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}
- name: Install dependencies
run: npm ci --no-audit --no-fund
- name: Next.js production build
run: |
set -eu
npm run build
test -f .next/standalone/server.js
docker-image-build:
if: ${{ (github.event_name != 'pull_request_target' || (github.event.pull_request.head.repo.full_name == github.repository && github.event.pull_request.base.ref == 'main')) && (github.event_name != 'workflow_dispatch' || github.event.inputs.p01_only != 'true' && (github.event_name != 'workflow_dispatch' || github.event.inputs.python_only != 'true')) }}
runs-on: ubuntu-latest
container: node:22-alpine
timeout-minutes: 100
steps:
- name: CI-07 provision Docker Buildx CLI
run: |
set -eu
apk add --no-cache git docker-cli docker-cli-buildx docker-cli-compose
docker --version
docker buildx version
docker compose version
- uses: actions/checkout@v4
with:
github-server-url: https://dev.ivib.cc
persist-credentials: false
ref: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}
- name: CI-07 inspect daemon and validate Compose without starting services
run: |
set -eu
docker info --format 'Driver={{.Driver}} Root={{.DockerRootDir}}'
df -h .
docker compose -f docker/docker-compose.yml config --no-interpolate --quiet
echo DATASTACK_COMPOSE_CONFIG_PASS
- name: CI-07 isolated BuildKit all three images (no deployment)
run: |
set -eu
builder="datastack-p03-${GITHUB_RUN_ID:-0}-${GITHUB_RUN_ATTEMPT:-1}"
tag="datastack-p03-${GITHUB_SHA:-local}"
cleanup() { docker buildx rm --force "$builder" >/dev/null 2>&1 || true; }
trap cleanup EXIT
docker buildx create --name "$builder" --driver docker-container --use
docker buildx inspect "$builder" --bootstrap
docker buildx build --builder "$builder" --progress=plain --no-cache --load -f docker/Dockerfile.server -t "$tag-ingestion" .
docker buildx build --builder "$builder" --progress=plain --no-cache --load -f docker/Dockerfile.web -t "$tag-web" .
docker buildx build --builder "$builder" --progress=plain --no-cache --load -f docker/Dockerfile.proxy -t "$tag-proxy" .
docker image inspect "$tag-ingestion" "$tag-web" "$tag-proxy" >/dev/null
echo DATASTACK_THREE_IMAGES_BUILD_PASS
- name: FA02 checkout frozen previous tested source for disposable rollback
uses: actions/checkout@v4
with:
github-server-url: https://dev.ivib.cc
persist-credentials: false
ref: ea3b3038fbd8851613a80098e540346d47c62079
path: fa02-baseline
- name: FA02 isolated five-service startup, fixture restore and previous-image rollback
run: |
set -eu
project="dsfa02${GITHUB_RUN_ID:-0}${GITHUB_RUN_ATTEMPT:-1}"
candidate="datastack-p03-${GITHUB_SHA:-local}"
previous="datastack-fa02-baseline-${GITHUB_RUN_ID:-0}"
compose() { docker compose -f docker/docker-compose.yml -p "$project" "$@"; }
if docker ps -aq --filter "label=com.docker.compose.project=$project" | grep -q .; then
echo "FAIL_CLOSED: pre-existing Compose project $project"; exit 1
fi
for vol in "${project}_datastack-data" "${project}_pgdata" "${project}_redisdata"; do
if docker volume inspect "$vol" >/dev/null 2>&1; then echo "FAIL_CLOSED: existing volume $vol"; exit 1; fi
done
# The daemon must not host known production services; no production containers or volumes are touched.
if docker ps --format '{{.Names}}' | grep -Ev '^(GITEA-ACTIONS-TASK-|buildx_buildkit_)' | grep -Eiq 'coolify|traefik|production|readbox|zitplane'; then
echo "FAIL_CLOSED: production-like containers found on Actions Docker host"; exit 1
fi
testdir="$(mktemp -d /tmp/datastack-fa02-XXXXXX)"
created=0
cleanup() {
if [ "$created" -eq 1 ]; then
compose down --volumes --remove-orphans >/dev/null 2>&1 || echo "RUN_OWNED_COMPOSE_CLEANUP_FAILED"
fi
rm -rf "$testdir"
}
trap cleanup EXIT
for svc in ingestion web proxy; do
docker image inspect "$candidate-$svc" >/dev/null
done
# Use cached old accepted images when available; otherwise build the frozen prior source
# inside a run-owned BuildKit builder without modifying its files or any live service.
need_previous=0
for svc in ingestion web proxy; do
if ! docker image inspect "$previous-$svc" >/dev/null 2>&1; then need_previous=1; fi
done
if [ "$need_previous" -eq 1 ]; then
baseline_builder="dsfa02rollback${GITHUB_RUN_ID:-0}"
baseline_cleanup() { docker buildx rm --force "$baseline_builder" >/dev/null 2>&1 || true; }
trap 'baseline_cleanup; cleanup' EXIT
docker buildx create --name "$baseline_builder" --driver docker-container --use
docker buildx inspect "$baseline_builder" --bootstrap
for svc in ingestion web proxy; do
dockerfile="server"
if [ "$svc" = web ]; then dockerfile="web"; fi
if [ "$svc" = proxy ]; then dockerfile="proxy"; fi
docker buildx build --builder "$baseline_builder" --progress=plain --no-cache --load \
-f "fa02-baseline/docker/Dockerfile.$dockerfile" -t "$previous-$svc" fa02-baseline
done
baseline_cleanup
trap cleanup EXIT
fi
for svc in ingestion web proxy; do
docker image tag "$candidate-$svc" "$project-$svc"
done
# Only disposable, generated secrets; never print secret values or use real production data.
export SERVICE_REALBASE64_64_JWT="$(node -e "console.log(require('node:crypto').randomBytes(48).toString('base64'))")"
export SERVICE_REALBASE64_64_ADMINSESSION="$(node -e "console.log(require('node:crypto').randomBytes(48).toString('base64'))")"
export SERVICE_REALBASE64_64_ADMININSTALL="$(node -e "console.log(require('node:crypto').randomBytes(48).toString('base64'))")"
export SERVICE_REALBASE64_64_INTERNAL="$(node -e "console.log(require('node:crypto').randomBytes(48).toString('base64'))")"
export SERVICE_PASSWORD_64_POSTGRES="$(node -e "console.log(require('node:crypto').randomBytes(32).toString('hex'))")"
export SERVICE_HEX_32_DATABASENAME="$(node -e "console.log(require('node:crypto').randomBytes(16).toString('hex'))")"
export DATASTACK_ADMIN_EMAIL=fa02-ci@example.invalid
export DATASTACK_CORS_ORIGINS=http://localhost.invalid
docker compose -f docker/docker-compose.yml -p "$project" config --quiet
created=1
compose up -d --no-build --wait --wait-timeout 240
compose ps
for svc in postgres redis web ingestion proxy; do
test "$(compose ps --status running -q "$svc" | wc -l)" -eq 1
done
echo DATASTACK_DISPOSABLE_FIVE_SERVICE_HEALTH_PASS
# Disposable PostgreSQL backup and restore into a second, isolated database.
compose exec -T postgres sh -c 'psql -q -U datastack "$POSTGRES_DB" -v ON_ERROR_STOP=1 -c "CREATE TABLE fa02_disposable_fixture (id integer PRIMARY KEY); INSERT INTO fa02_disposable_fixture VALUES (4242);"'
compose exec -T postgres sh -c 'pg_dump -U datastack "$POSTGRES_DB"' > "$testdir/pg.sql"
test -s "$testdir/pg.sql"
compose exec -T postgres createdb -U datastack fa02_disposable_restore
compose exec -T postgres psql -q -v ON_ERROR_STOP=1 -U datastack -d fa02_disposable_restore < "$testdir/pg.sql"
restored="$(compose exec -T postgres psql -At -U datastack -d fa02_disposable_restore -c 'SELECT id FROM fa02_disposable_fixture WHERE id = 4242')"
test "$restored" = 4242
echo DATASTACK_DISPOSABLE_POSTGRES_BACKUP_RESTORE_PASS
# Redis AOF and CSV storage fixtures: no user/production records.
compose exec -T redis redis-cli SET fa02:disposable:probe stable-fixture >/dev/null
compose exec -T redis redis-cli SAVE >/dev/null
compose exec -T ingestion sh -c 'mkdir -p /app/storage/data/fa02-disposable && printf "clientId,eventId,timestamp,payload\nfa02,1,now,test-only\n" > /app/storage/data/fa02-disposable/probe.csv'
compose exec -T ingestion cat /app/storage/data/fa02-disposable/probe.csv > "$testdir/csv.bak"
compose exec -T web cmp /app/storage/data/fa02-disposable/probe.csv /app/storage/data/fa02-disposable/probe.csv
compose exec -T ingestion rm /app/storage/data/fa02-disposable/probe.csv
compose exec -T ingestion sh -c 'cat > /app/storage/data/fa02-disposable/probe.csv' < "$testdir/csv.bak"
test "$(compose exec -T web sha256sum /app/storage/data/fa02-disposable/probe.csv | cut -d ' ' -f1)" = "$(sha256sum "$testdir/csv.bak" | cut -d ' ' -f1)"
compose restart redis
compose up -d --no-build --wait --wait-timeout 240
test "$(compose exec -T redis redis-cli GET fa02:disposable:probe | tr -d '\r')" = stable-fixture
echo DATASTACK_DISPOSABLE_REDIS_CSV_RECOVERY_PASS
# Roll back only the disposable Compose project's application-image tags to the
# accepted frozen baseline; fixtures and Docker host production resources untouched.
for svc in ingestion web proxy; do
docker image tag "$previous-$svc" "$project-$svc"
done
compose up -d --no-build --force-recreate --wait --wait-timeout 240
test "$(compose exec -T redis redis-cli GET fa02:disposable:probe | tr -d '\r')" = stable-fixture
test "$(compose exec -T ingestion sha256sum /app/storage/data/fa02-disposable/probe.csv | cut -d ' ' -f1)" = "$(sha256sum "$testdir/csv.bak" | cut -d ' ' -f1)"
for svc in postgres redis web ingestion proxy; do
test "$(compose ps --status running -q "$svc" | wc -l)" -eq 1
done
echo DATASTACK_DISPOSABLE_PREVIOUS_IMAGE_ROLLBACK_PASS
windows-compatibility:
if: ${{ (github.event_name != 'pull_request_target' || (github.event.pull_request.head.repo.full_name == github.repository && github.event.pull_request.base.ref == 'main')) && (github.event_name != 'workflow_dispatch' || github.event.inputs.quality_only != 'true' && (github.event_name != 'workflow_dispatch' || github.event.inputs.python_only != 'true')) }}
runs-on: windows-latest
timeout-minutes: 45
steps:
- uses: actions/checkout@v4
with:
github-server-url: https://dev.ivib.cc
persist-credentials: false
ref: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}
- name: Verify native Windows toolchain
shell: powershell
run: |
$ErrorActionPreference = 'Stop'
node --version
npm --version
python --version
git rev-parse HEAD
- name: Install dependencies and compile Node SDK
shell: powershell
run: |
$ErrorActionPreference = 'Stop'
# Verify the committed cross-platform lock without disposable regeneration.
npm ci --no-audit --no-fund
if ($LASTEXITCODE -ne 0) { throw 'Committed-lock npm ci failed' }
npm --prefix sdk/node/datastack install --no-audit --no-fund
if ($LASTEXITCODE -ne 0) { throw 'SDK install failed' }
npm --prefix sdk/node/datastack run build
if ($LASTEXITCODE -ne 0) { throw 'SDK compilation failed' }
- name: FF01 native Windows File Manager CRUD and ZIP acceptance
shell: powershell
run: |
$ErrorActionPreference = 'Stop'
npx.cmd --yes tsx@4.20.6 --test tests/files-manager.test.ts
if ($LASTEXITCODE -ne 0) { throw 'FF01 Windows Files Manager regression failed' }
- name: FA02 Windows Python SDK full acceptance
shell: powershell
run: |
$ErrorActionPreference = 'Stop'
$venv = Join-Path $env:RUNNER_TEMP 'datastack-fa02-python'
python -m venv $venv
if ($LASTEXITCODE -ne 0) { throw 'Windows Python venv creation failed' }
$py = Join-Path $venv 'Scripts\python.exe'
& $py -m pip install -e ./sdk/python/datastack -e ./sdk-python
if ($LASTEXITCODE -ne 0) { throw 'Windows SDK install failed' }
& $py -m compileall -q ./sdk/python/datastack ./sdk-python
if ($LASTEXITCODE -ne 0) { throw 'Windows SDK compile failed' }
& $py -m unittest discover -s tests -p '*_test.py' -v
if ($LASTEXITCODE -ne 0) { throw 'Windows SDK regression failed' }
Write-Output 'DATASTACK_FA02_WINDOWS_PYTHON_PASS'
- name: FA02 Windows ESLint acceptance
shell: powershell
run: |
$ErrorActionPreference = 'Stop'
npm run lint
if ($LASTEXITCODE -ne 0) { throw 'Windows ESLint failed' }
Write-Output 'DATASTACK_FA02_WINDOWS_ESLINT_PASS'
security-audit:
if: ${{ (github.event_name != 'pull_request_target' || (github.event.pull_request.head.repo.full_name == github.repository && github.event.pull_request.base.ref == 'main')) && (github.event_name != 'workflow_dispatch' || github.event.inputs.p01_only != 'true' && (github.event_name != 'workflow_dispatch' || github.event.inputs.python_only != 'true')) }}
runs-on: ubuntu-latest
container: node:22-alpine
timeout-minutes: 15
steps:
- name: Install checkout prerequisite
run: apk add --no-cache git
- uses: actions/checkout@v4
with:
github-server-url: https://dev.ivib.cc
persist-credentials: false
ref: ${{ github.event_name == 'pull_request_target' && github.event.pull_request.head.sha || github.sha }}
- name: CI-08 read-only full and runtime npm advisory inventory
run: |
set -eu
if npm audit --json > /tmp/datastack-audit-full.json; then :; else test "$?" -eq 1; fi
if npm audit --omit=dev --json > /tmp/datastack-audit-runtime.json; then :; else test "$?" -eq 1; fi
node <<'NODE'
const fs = require("node:fs");
for (const scope of ["full", "runtime"]) {
const audit = JSON.parse(fs.readFileSync("/tmp/datastack-audit-" + scope + ".json", "utf8"));
if (!audit.metadata || !audit.metadata.vulnerabilities || !audit.vulnerabilities) {
throw Error("Incomplete npm audit response for " + scope);
}
console.log("AUDIT_COUNTS " + scope + " " + JSON.stringify(audit.metadata.vulnerabilities));
for (const [name, item] of Object.entries(audit.vulnerabilities)) {
const advisories = (item.via || []).filter(v => typeof v === "object").map(v => ({
id: v.source, url: v.url, range: v.range, severity: v.severity
}));
console.log("AUDIT_PACKAGE " + scope + " " + JSON.stringify({
package: name, severity: item.severity, direct: item.isDirect,
range: item.range, via: advisories,
viaPackages: (item.via || []).filter(v => typeof v === "string"),
fixAvailable: item.fixAvailable
}));
}
if (scope === "runtime") {
const counts = audit.metadata.vulnerabilities;
if (!Number.isInteger(counts.high) || !Number.isInteger(counts.critical)) {
throw Error("Incomplete runtime npm advisory severity counts");
}
if (counts.high > 0 || counts.critical > 0) {
throw Error("DATASTACK_RUNTIME_SECURITY_GATE_FAILED high=" + counts.high + " critical=" + counts.critical);
}
console.log("DATASTACK_RUNTIME_SECURITY_HIGH_CRITICAL_ZERO");
}
}
NODE
git diff --exit-code -- package.json package-lock.json
echo DATASTACK_SECURITY_TRIAGE_INVENTORY_PASS
- name: FA02 verify installed older-major security backports and exact lock
run: |
set -eu
npm ci --no-audit --no-fund
for patch in patches/cloudcmd-got-security.patch patches/cloudcmd-glob-security.patch patches/cloudcmd-minimatch-security.patch patches/cloudcmd-file-type-security.patch; do
git apply --reverse --check "$patch"
echo DATASTACK_SECURITY_VERIFIED_BACKPORT "$patch"
done
node <<'NODE'
const fs = require('node:fs');
const assert = require('node:assert/strict');
const pkgs = [
['got@10.7.0', 'node_modules/got/dist/source/request-as-event-emitter.js', 'Cannot redirect to UNIX socket'],
['glob@10.5.0', 'node_modules/glob/dist/commonjs/walker.js', 'return cb()'],
['minimatch@9.0.9', 'node_modules/glob/node_modules/minimatch/dist/commonjs/index.js', 'braceExpandMax'],
['minimatch@10.2.6', 'node_modules/onezip/node_modules/glob/node_modules/minimatch/dist/commonjs/index.js', 'braceExpandMax'],
['file-type@16.5.4 join-io', 'node_modules/join-io/node_modules/ponse/node_modules/file-type/core.js', 'previousPosition'],
['file-type@16.5.4 restbox', 'node_modules/restbox/node_modules/ponse/node_modules/file-type/core.js', 'previousPosition'],
];
for (const [pkg, path, needle] of pkgs) {
assert.ok(fs.readFileSync(path, 'utf8').includes(needle), 'missing patched marker: ' + pkg);
console.log('FA02_PATCHED_EXECUTABLE_SOURCE_VERIFIED', pkg);
}
console.log('FA02_NPM_ADVISORY_METADATA_MAY_STILL_FLAG_OLDER_VERSIONS');
NODE
git diff --exit-code -- package.json package-lock.json
echo DATASTACK_FA02_SECURITY_SOURCE_AND_LOCK_GATE_PASS