recovered from aaronjaworski710
CI / offline-tests (push) Has been cancelled
CI / web-unit-tests (push) Has been cancelled
CI / package-console10 (push) Has been cancelled

This commit is contained in:
reform
2026-10-23 20:02:14 +03:00
commit 8044e88be4
409 changed files with 104886 additions and 0 deletions
+233
View File
@@ -0,0 +1,233 @@
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
concurrency:
group: ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
actions: read
jobs:
test:
name: offline-tests
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
enable-cache: true
- name: Set up Python
run: uv python install 3.13
- name: Sync dependencies
run: uv sync --extra dev
- name: Shell syntax (setup/doctor/hub)
run: |
bash -n scripts/setup_simple.sh
bash -n scripts/doctor_secrets.sh
bash -n scripts/build_web_console.sh
bash -n scripts/deploy_web_console10.sh
bash -n register.sh
bash -n providers/mimo/run-register.sh
bash -n providers/mimo/smoke.sh
bash -n providers/_template/run-register.sh
- name: Syntax check
run: |
# I4: required paths must exist (fail CI if deleted);
# optional paths may be staged features and are skipped when absent.
set -euo pipefail
required=(
register_cli.py
grok_register_ttk.py
cpa_export.py
account_backup.py
tab_pool.py
proxy_bridge.py
proxy_rotate.py
mail_pool_probe.py
node_score.py
cpa_xai/__init__.py
cpa_xai/accounts.py
cpa_xai/browser_confirm.py
cpa_xai/mint.py
cpa_xai/oauth_device.py
cpa_xai/probe.py
cpa_xai/protocol_mint.py
cpa_xai/proxyutil.py
cpa_xai/schema.py
cpa_xai/writer.py
register_core/__init__.py
register_core/__main__.py
register_core/cli.py
register_core/contracts.py
register_core/errors.py
register_core/pipeline.py
register_core/email/__init__.py
register_core/providers/__init__.py
register_core/providers/grok_adapter.py
register_core/providers/mimo_adapter.py
register_core/verify/__init__.py
register_core/sink/jsonl_sink.py
register_core/util/process.py
register_core/util/secrets.py
register_core/verify/mimo_tts.py
register_core/verify/grok_chat.py
apps/control_api/app.py
apps/control_api/mail_ops.py
apps/control_api/nodes_ops.py
apps/control_api/accounts_ops.py
apps/control_api/system_ops.py
apps/control_api/process_registry.py
providers/mimo/inject_cpa_openai.py
scripts/backfill_cpa_xai_from_accounts.py
scripts/backup_registered_accounts.py
scripts/export_cpa_xai_from_grok_auth.py
scripts/remint_expired_and_sync_authdir.py
scripts/quality_milestone_watch.py
scripts/quality_sample_accounts.py
scripts/probe_mail_pool.py
)
optional=(
# Keep empty or list experimental modules not yet always shipped.
)
missing=0
present=()
for f in "${required[@]}"; do
if [[ -f "$f" ]]; then
present+=("$f")
else
echo "ERROR: required file missing: $f" >&2
missing=1
fi
done
if [[ "$missing" -ne 0 ]]; then
exit 1
fi
for f in "${optional[@]:-}"; do
[[ -z "$f" ]] && continue
if [[ -f "$f" ]]; then
present+=("$f")
else
echo "skip optional missing: $f"
fi
done
uv run python -m py_compile "${present[@]}"
- name: Offline unit tests
env:
# Never run live mailbox / remote inject in CI
GROK_REGISTER_LIVE: ""
run: uv run python -m pytest -q
- name: Secret path guard
run: |
set -euo pipefail
if git ls-files | grep -E '(^|/)(config\.json|\.env|mail_credentials\.txt|accounts_cli\.txt)$|mail_assets/hotmail|cpa_auths/xai-|^backups/|^logs/'; then
echo "Refusing tracked secret/runtime paths" >&2
git ls-files | grep -E '(^|/)(config\.json|\.env|mail_credentials\.txt|accounts_cli\.txt)$|cpa_auths/xai-|^backups/|^logs/' >&2
exit 1
fi
echo "OK: no secret runtime paths tracked"
bash scripts/doctor_secrets.sh || test $? -eq 2
web-test:
name: web-unit-tests
runs-on: ubuntu-latest
timeout-minutes: 10
# No main-only guard: console10 前端测试在 push 和 PR 上都要跑
# (package-web 只在 main push 跑,PR 上前端曾经完全没有覆盖)。
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "22"
cache: npm
cache-dependency-path: apps/web/package-lock.json
- name: Install deps
working-directory: apps/web
run: npm ci
- name: Unit tests
working-directory: apps/web
run: npm test
package-web:
name: package-console10
runs-on: ubuntu-latest
timeout-minutes: 10
needs: [test]
# M1: only package on main (PR CI still runs tests; deploy uses main artifacts)
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
permissions:
contents: read
actions: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "22"
cache: npm
cache-dependency-path: apps/web/package-lock.json
- name: Web unit tests
working-directory: apps/web
run: |
npm ci
npm test
- name: Build console10
run: ./scripts/build_web_console.sh
- name: Pack tarball
run: |
set -euo pipefail
mkdir -p artifacts
tar -C apps/web/dist -czf artifacts/console10-webroot.tgz .
# also keep a flat dist tree for artifact browsing
cp -a apps/web/dist artifacts/console10-dist
python - <<'PY'
from pathlib import Path
p = Path("artifacts/console10-webroot.tgz")
print(f"artifact_bytes={p.stat().st_size}")
assert p.stat().st_size > 1000, "web tarball too small"
idx = Path("artifacts/console10-dist/index.html")
assert idx.is_file(), "missing index.html in dist"
print("index_head:")
print(idx.read_text(encoding="utf-8", errors="replace")[:400])
PY
- name: Upload console10 artifact
uses: actions/upload-artifact@v4
with:
name: console10-web
path: |
artifacts/console10-webroot.tgz
artifacts/console10-dist/**
if-no-files-found: error
retention-days: 14
+298
View File
@@ -0,0 +1,298 @@
name: Deploy console10
# Deploy static SPA only — does NOT stop batch/coinbot.
#
# Triggers:
# - workflow_dispatch (manual; dry_run / rebuild / artifact options)
# - workflow_run: after successful CI on main (auto deploy that run's artifact)
#
# Required secrets (repo and/or Environment `pxed`):
# PXED_SSH_PRIVATE_KEY — deploy key private PEM
# PXED_HOST — ssh target (prefer direct host, e.g. user@pxed1497962.bohrium.tech)
# PXED_KNOWN_HOSTS — known_hosts lines (REQUIRED for real deploy)
# Optional:
# PXED_SSH_PORT — default 22
# PXED_WEB — remote web root (default /data/grok-register/apps/web)
#
# Protection: job uses Environment `pxed`.
on:
workflow_dispatch:
inputs:
ref:
description: "Git ref to build when not using artifact. Empty = this workflow SHA."
required: false
default: ""
type: string
use_latest_artifact:
description: "Prefer console10-web artifact from a successful main CI run."
required: false
default: true
type: boolean
remote_web:
description: "Override remote web root under /data/grok-register (empty = secret/default)."
required: false
default: ""
type: string
dry_run:
description: "Build/download only; do not scp/ssh."
required: false
default: false
type: boolean
workflow_run:
workflows: ["CI"]
types: [completed]
branches: [main]
concurrency:
group: deploy-console10
cancel-in-progress: false
# I6: explicit least privilege (repo default may be read; workflow_run needs actions:read)
permissions:
contents: read
actions: read
jobs:
deploy:
name: deploy-to-pxed
runs-on: ubuntu-latest
timeout-minutes: 20
# C1: Environment gate
environment: pxed
permissions:
contents: read
actions: read
# Auto path: only on successful CI that was a push to main (not PR CI)
if: >
github.event_name == 'workflow_dispatch' ||
(github.event_name == 'workflow_run' &&
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.event == 'push')
steps:
- name: Resolve mode
id: mode
env:
EVENT_NAME: ${{ github.event_name }}
# workflow_run fields are empty on workflow_dispatch; inputs empty on workflow_run
WR_ID: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.id || '' }}
WR_SHA: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.head_sha || '' }}
WR_URL: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.html_url || '' }}
INPUT_REF: ${{ github.event_name == 'workflow_dispatch' && inputs.ref || '' }}
INPUT_USE_ARTIFACT: ${{ github.event_name == 'workflow_dispatch' && (inputs.use_latest_artifact && 'true' || 'false') || 'true' }}
INPUT_DRY_RUN: ${{ github.event_name == 'workflow_dispatch' && (inputs.dry_run && 'true' || 'false') || 'false' }}
INPUT_REMOTE_WEB: ${{ github.event_name == 'workflow_dispatch' && inputs.remote_web || '' }}
THIS_SHA: ${{ github.sha }}
run: |
set -euo pipefail
if [[ "$EVENT_NAME" == "workflow_run" ]]; then
echo "trigger=auto" >> "$GITHUB_OUTPUT"
echo "dry_run=false" >> "$GITHUB_OUTPUT"
echo "prefer_artifact=true" >> "$GITHUB_OUTPUT"
echo "ci_run_id=$WR_ID" >> "$GITHUB_OUTPUT"
echo "ref=$WR_SHA" >> "$GITHUB_OUTPUT"
echo "remote_web_input=" >> "$GITHUB_OUTPUT"
echo "Auto-deploy from CI run $WR_ID sha=$WR_SHA ($WR_URL)"
else
REF="$INPUT_REF"
if [[ -z "$REF" ]]; then
REF="$THIS_SHA"
fi
echo "trigger=manual" >> "$GITHUB_OUTPUT"
echo "dry_run=$INPUT_DRY_RUN" >> "$GITHUB_OUTPUT"
echo "prefer_artifact=$INPUT_USE_ARTIFACT" >> "$GITHUB_OUTPUT"
echo "ci_run_id=" >> "$GITHUB_OUTPUT"
echo "ref=$REF" >> "$GITHUB_OUTPUT"
echo "remote_web_input=$INPUT_REMOTE_WEB" >> "$GITHUB_OUTPUT"
echo "Manual deploy ref=$REF dry_run=$INPUT_DRY_RUN prefer_artifact=$INPUT_USE_ARTIFACT"
fi
- name: Checkout (always — need deploy script)
uses: actions/checkout@v4
with:
ref: ${{ steps.mode.outputs.ref }}
- name: Sanitize remote web root
id: web
env:
PXED_WEB_SECRET: ${{ secrets.PXED_WEB }}
REMOTE_WEB_INPUT: ${{ steps.mode.outputs.remote_web_input }}
run: |
set -euo pipefail
# C2: never interpolate untrusted path into remote shell.
if [[ -n "${REMOTE_WEB_INPUT}" ]]; then
CANDIDATE="$REMOTE_WEB_INPUT"
elif [[ -n "${PXED_WEB_SECRET:-}" ]]; then
CANDIDATE="$PXED_WEB_SECRET"
else
CANDIDATE="/data/grok-register/apps/web"
fi
while [[ "$CANDIDATE" == */ && "$CANDIDATE" != / ]]; do
CANDIDATE="${CANDIDATE%/}"
done
case "$CANDIDATE" in
/data/grok-register|/data/grok-register/*) ;;
*)
echo "remote_web must be under /data/grok-register, got: $CANDIDATE" >&2
exit 1
;;
esac
if [[ "$CANDIDATE" == *..* ]]; then
echo "remote_web must not contain .." >&2
exit 1
fi
if [[ ! "$CANDIDATE" =~ ^/data/grok-register(/[A-Za-z0-9._+-]+)*$ ]]; then
echo "remote_web has unsafe characters: $CANDIDATE" >&2
exit 1
fi
echo "remote_web=$CANDIDATE" >> "$GITHUB_OUTPUT"
echo "Using remote_web=$CANDIDATE"
# I1: only accept runs that actually published console10-web; else rebuild.
- name: Obtain console10 tarball
id: tarball
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PREFER_ARTIFACT: ${{ steps.mode.outputs.prefer_artifact }}
CI_RUN_ID: ${{ steps.mode.outputs.ci_run_id }}
REPO: ${{ github.repository }}
run: |
set -euo pipefail
mkdir -p /tmp/console10-ci
OUT=/tmp/console10-ci/console10-webroot.tgz
got=0
download_from_run() {
local run_id="$1"
local dir
dir="$(mktemp -d /tmp/console10_art.XXXXXX)"
if ! gh run download "$run_id" --repo "$REPO" --name console10-web --dir "$dir" 2>/tmp/console10_dl.err; then
echo "download failed for run $run_id: $(cat /tmp/console10_dl.err 2>/dev/null || true)"
rm -rf "$dir"
return 1
fi
local tgz
tgz=$(find "$dir" -name 'console10-webroot.tgz' | head -1)
if [[ -z "$tgz" || ! -s "$tgz" ]]; then
echo "run $run_id has console10-web name but missing tarball"
find "$dir" -maxdepth 4 -type f || true
rm -rf "$dir"
return 1
fi
cp -f "$tgz" "$OUT"
rm -rf "$dir"
echo "Using artifact from CI run $run_id"
return 0
}
if [[ "$PREFER_ARTIFACT" == "true" ]]; then
if [[ -n "${CI_RUN_ID}" ]]; then
# auto path: this exact successful CI run
if download_from_run "$CI_RUN_ID"; then
got=1
else
echo "CI run $CI_RUN_ID has no usable console10-web; will rebuild"
fi
else
# manual: scan recent successful CI runs for artifact name (I1)
mapfile -t RUN_IDS < <(gh run list \
--repo "$REPO" \
--branch main \
--workflow CI \
--json databaseId,conclusion,status \
--limit 30 \
--jq '.[] | select(.conclusion=="success" and .status=="completed") | .databaseId')
for run_id in "${RUN_IDS[@]:-}"; do
# confirm artifact exists before download
has=$(gh api "repos/$REPO/actions/runs/$run_id/artifacts" \
--jq '[.artifacts[] | select(.name=="console10-web" and .expired==false)] | length')
if [[ "${has:-0}" -gt 0 ]]; then
if download_from_run "$run_id"; then
got=1
break
fi
else
echo "skip CI run $run_id (no console10-web artifact)"
fi
done
fi
fi
if [[ "$got" -eq 1 ]]; then
ls -la "$OUT"
echo "source=artifact" >> "$GITHUB_OUTPUT"
echo "path=$OUT" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "Falling back to rebuild from ref ${{ steps.mode.outputs.ref }}"
echo "source=rebuild" >> "$GITHUB_OUTPUT"
echo "path=$OUT" >> "$GITHUB_OUTPUT"
- name: Setup Node (rebuild fallback)
if: ${{ steps.tarball.outputs.source == 'rebuild' }}
uses: actions/setup-node@v4
with:
node-version: "22"
cache: npm
cache-dependency-path: apps/web/package-lock.json
- name: Build + pack (rebuild fallback)
if: ${{ steps.tarball.outputs.source == 'rebuild' }}
run: |
set -euo pipefail
./scripts/build_web_console.sh
mkdir -p /tmp/console10-ci
tar -C apps/web/dist -czf /tmp/console10-ci/console10-webroot.tgz .
ls -la /tmp/console10-ci/console10-webroot.tgz
test -s /tmp/console10-ci/console10-webroot.tgz
- name: Require deploy secrets
if: ${{ steps.mode.outputs.dry_run != 'true' }}
env:
PXED_SSH_PRIVATE_KEY: ${{ secrets.PXED_SSH_PRIVATE_KEY }}
PXED_HOST: ${{ secrets.PXED_HOST }}
PXED_KNOWN_HOSTS: ${{ secrets.PXED_KNOWN_HOSTS }}
run: |
set -euo pipefail
missing=0
for name in PXED_SSH_PRIVATE_KEY PXED_HOST PXED_KNOWN_HOSTS; do
if [[ -z "${!name}" ]]; then
echo "Missing required secret: $name" >&2
missing=1
fi
done
if [[ "$missing" -ne 0 ]]; then
echo "Real deploy needs PXED_SSH_PRIVATE_KEY + PXED_HOST + PXED_KNOWN_HOSTS" >&2
echo "Tip: manual dry_run=true builds/downloads without secrets." >&2
exit 1
fi
# I3: single deploy script path
- name: Deploy via scripts/deploy_web_console10.sh
if: ${{ steps.mode.outputs.dry_run != 'true' }}
env:
PXED_SSH_PRIVATE_KEY: ${{ secrets.PXED_SSH_PRIVATE_KEY }}
PXED_HOST: ${{ secrets.PXED_HOST }}
PXED_SSH_PORT: ${{ secrets.PXED_SSH_PORT }}
PXED_KNOWN_HOSTS: ${{ secrets.PXED_KNOWN_HOSTS }}
PXED_WEB: ${{ steps.web.outputs.remote_web }}
CONSOLE10_TGZ: /tmp/console10-ci/console10-webroot.tgz
SKIP_BUILD: "1"
PRUNE_STALE_ASSETS: "1"
DRY_RUN: "0"
run: |
set -euo pipefail
chmod +x scripts/deploy_web_console10.sh
./scripts/deploy_web_console10.sh
- name: Dry-run summary
if: ${{ steps.mode.outputs.dry_run == 'true' }}
run: |
set -euo pipefail
ls -la /tmp/console10-ci/console10-webroot.tgz
echo "source=${{ steps.tarball.outputs.source }}"
echo "remote_web=${{ steps.web.outputs.remote_web }}"
echo "trigger=${{ steps.mode.outputs.trigger }}"
echo "dry_run=1 — skipped scp/ssh"