Files
Genarrative/.gitea/workflows/project-ci.yml
T
kdletters 94ee363d84
Project CI / Frontend tests (push) Successful in 2m49s
Project CI / Repository checks (push) Successful in 3m24s
Project CI / Backend tests (push) Successful in 8m21s
Project CI / Native shell tests (push) Failing after 10m21s
补齐原生CI的merged-usr预检
按运行时代码动态复现 merged-usr 符号链接
避免 bubblewrap canary 因动态加载器路径误报失败
2026-07-21 22:03:01 +08:00

458 lines
16 KiB
YAML

name: Project CI
on:
push:
branches:
- master
- codex/ai-game-creator-app
pull_request:
workflow_dispatch:
permissions:
contents: read
env:
CI: 'true'
CARGO_INCREMENTAL: '0'
CARGO_HTTP_MULTIPLEXING: 'false'
CARGO_NET_RETRY: '10'
CARGO_TERM_COLOR: always
RUSTUP_MAX_RETRIES: '10'
RUSTC_WRAPPER: ''
CARGO_BUILD_RUSTC_WRAPPER: ''
jobs:
repository-checks:
name: Repository checks
runs-on: ubuntu-latest
steps:
- name: Checkout full history
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
fetch-depth: 0
persist-credentials: false
- name: Install base tools
shell: bash
run: |
set -euo pipefail
command -v apt-get >/dev/null 2>&1 || {
echo 'ubuntu-latest runner must provide an Ubuntu or Debian environment.' >&2
exit 1
}
sudo_command=()
if [[ "$(id -u)" -ne 0 ]]; then
command -v sudo >/dev/null 2>&1 || {
echo 'non-root runner user requires sudo for system dependencies.' >&2
exit 1
}
sudo_command=(sudo -E)
fi
"${sudo_command[@]}" apt-get update
"${sudo_command[@]}" env DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
ca-certificates \
curl
- name: Set up Node.js 22
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: '22'
- name: Resolve comparison base
shell: bash
run: |
set -euo pipefail
base_ref="$(node -e '
const fs = require("node:fs");
const event = JSON.parse(fs.readFileSync(process.env.GITHUB_EVENT_PATH, "utf8"));
process.stdout.write(event.pull_request?.base?.sha ?? event.before ?? "");
')"
if [[ -n "${base_ref}" && ! "${base_ref}" =~ ^0+$ ]]; then
git cat-file -e "${base_ref}^{commit}" 2>/dev/null || {
echo "comparison base commit is unavailable: ${base_ref}" >&2
exit 1
}
else
base_ref="$(git merge-base HEAD origin/master 2>/dev/null || git rev-parse HEAD)"
fi
if [[ "${GITHUB_EVENT_NAME:-}" == 'pull_request' ]] \
&& ! git merge-base --is-ancestor "${base_ref}" HEAD; then
echo 'pull request head does not contain the latest base commit; update the branch and rerun CI.' >&2
exit 1
fi
echo "SPACETIME_SCHEMA_BASE_REF=${base_ref}" >> "${GITHUB_ENV}"
- name: Set up repository Rust toolchain
shell: bash
run: |
set -euo pipefail
if ! command -v rustup >/dev/null 2>&1; then
for attempt in $(seq 1 10); do
if curl --retry 3 --retry-all-errors --retry-delay 2 \
--proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \
| sh -s -- -y --profile minimal --default-toolchain none; then
break
fi
if [[ "${attempt}" -eq 10 ]]; then
echo 'rustup bootstrap failed after 10 attempts.' >&2
exit 1
fi
sleep $((attempt * 2))
done
fi
echo "${HOME}/.cargo/bin" >> "${GITHUB_PATH}"
export PATH="${HOME}/.cargo/bin:${PATH}"
toolchain="$(sed -n 's/^channel = "\([^"]*\)"/\1/p' rust-toolchain.toml)"
test -n "${toolchain}"
for attempt in $(seq 1 10); do
if rustup toolchain install "${toolchain}" --profile minimal --component rustfmt; then
break
fi
if [[ "${attempt}" -eq 10 ]]; then
echo 'Rust toolchain installation failed after 10 attempts.' >&2
exit 1
fi
sleep $((attempt * 2))
done
rustc --version
cargo --version
rustfmt --version
- name: Install npm dependencies
run: npm ci
- name: Run repository lint gates
run: npm run lint
- name: Build web applications
run: npm run build
- name: Validate content data
run: npm run check:content
- name: Check committed whitespace
shell: bash
run: |
set -euo pipefail
base_ref="${SPACETIME_SCHEMA_BASE_REF:-}"
test -n "${base_ref}"
git cat-file -e "${base_ref}^{commit}"
git diff --check "${base_ref}"...HEAD
frontend-tests:
name: Frontend tests
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
persist-credentials: false
- name: Set up Node.js 22
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: '22'
- name: Install npm dependencies
run: npm ci
- name: Install AI game creator dependencies
run: npm ci --prefix apps/ai-game-creator-shell
- name: Run frontend and script tests
run: npm run test
backend-tests:
name: Backend tests
runs-on: ubuntu-latest
steps:
- name: Checkout full history
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
fetch-depth: 0
persist-credentials: false
- name: Install backend build dependencies
shell: bash
run: |
set -euo pipefail
command -v apt-get >/dev/null 2>&1 || {
echo 'ubuntu-latest runner must provide an Ubuntu or Debian environment.' >&2
exit 1
}
sudo_command=()
if [[ "$(id -u)" -ne 0 ]]; then
command -v sudo >/dev/null 2>&1 || {
echo 'non-root runner user requires sudo for system dependencies.' >&2
exit 1
}
sudo_command=(sudo -E)
fi
"${sudo_command[@]}" apt-get update
"${sudo_command[@]}" env DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
build-essential \
ca-certificates \
clang \
cmake \
curl \
ffmpeg \
libclang-dev \
libcurl4-openssl-dev \
libssl-dev \
lld \
pkg-config
- name: Set up Node.js 22
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: '22'
- name: Resolve comparison base
shell: bash
run: |
set -euo pipefail
base_ref="$(node -e '
const fs = require("node:fs");
const event = JSON.parse(fs.readFileSync(process.env.GITHUB_EVENT_PATH, "utf8"));
process.stdout.write(event.pull_request?.base?.sha ?? event.before ?? "");
')"
if [[ -n "${base_ref}" && ! "${base_ref}" =~ ^0+$ ]]; then
git cat-file -e "${base_ref}^{commit}" 2>/dev/null || {
echo "comparison base commit is unavailable: ${base_ref}" >&2
exit 1
}
else
base_ref="$(git merge-base HEAD origin/master 2>/dev/null || git rev-parse HEAD)"
fi
if [[ "${GITHUB_EVENT_NAME:-}" == 'pull_request' ]] \
&& ! git merge-base --is-ancestor "${base_ref}" HEAD; then
echo 'pull request head does not contain the latest base commit; update the branch and rerun CI.' >&2
exit 1
fi
echo "SPACETIME_SCHEMA_BASE_REF=${base_ref}" >> "${GITHUB_ENV}"
- name: Set up repository Rust toolchain
shell: bash
run: |
set -euo pipefail
if ! command -v rustup >/dev/null 2>&1; then
for attempt in $(seq 1 10); do
if curl --retry 3 --retry-all-errors --retry-delay 2 \
--proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \
| sh -s -- -y --profile minimal --default-toolchain none; then
break
fi
if [[ "${attempt}" -eq 10 ]]; then
echo 'rustup bootstrap failed after 10 attempts.' >&2
exit 1
fi
sleep $((attempt * 2))
done
fi
echo "${HOME}/.cargo/bin" >> "${GITHUB_PATH}"
export PATH="${HOME}/.cargo/bin:${PATH}"
toolchain="$(sed -n 's/^channel = "\([^"]*\)"/\1/p' rust-toolchain.toml)"
test -n "${toolchain}"
for attempt in $(seq 1 10); do
if rustup toolchain install "${toolchain}" --profile minimal --component rustfmt; then
break
fi
if [[ "${attempt}" -eq 10 ]]; then
echo 'Rust toolchain installation failed after 10 attempts.' >&2
exit 1
fi
sleep $((attempt * 2))
done
rustc --version
cargo --version
rustfmt --version
- name: Install npm dependencies
run: npm ci
- name: Check server-rs boundaries
run: npm run check:server-rs-ddd
- name: Run server-rs workspace tests
run: cargo test --locked --workspace --no-fail-fast --manifest-path server-rs/Cargo.toml
- name: Check api-server targets
run: cargo check --locked -p api-server --all-targets --manifest-path server-rs/Cargo.toml
- name: Check SpacetimeDB module
run: cargo check --locked -p spacetime-module --manifest-path server-rs/Cargo.toml
native-shell-tests:
name: Native shell tests
runs-on: ubuntu-latest
steps:
- name: Checkout full history
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
with:
fetch-depth: 0
persist-credentials: false
- name: Install native shell build dependencies
shell: bash
run: |
set -euo pipefail
command -v apt-get >/dev/null 2>&1 || {
echo 'ubuntu-latest runner must provide an Ubuntu or Debian environment.' >&2
exit 1
}
sudo_command=()
if [[ "$(id -u)" -ne 0 ]]; then
command -v sudo >/dev/null 2>&1 || {
echo 'non-root runner user requires sudo for system dependencies.' >&2
exit 1
}
sudo_command=(sudo -E)
fi
"${sudo_command[@]}" apt-get update
"${sudo_command[@]}" env DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
build-essential \
bubblewrap \
ca-certificates \
clang \
cmake \
curl \
file \
libayatana-appindicator3-dev \
libssl-dev \
libwebkit2gtk-4.1-dev \
libxdo-dev \
librsvg2-dev \
lld \
patchelf \
pkg-config \
wget
bwrap_args=(
--die-with-parent
--unshare-all
--unshare-user
--disable-userns
--assert-userns-disabled
--cap-drop ALL
--clearenv
--ro-bind /usr /usr
)
for merged_path in /bin /sbin /lib /lib64; do
if [[ -L "${merged_path}" ]]; then
bwrap_args+=(--symlink "$(readlink "${merged_path}")" "${merged_path}")
fi
done
bwrap_args+=(
--proc /proc
--dev /dev
--tmpfs /tmp
--
/usr/bin/true
)
bwrap "${bwrap_args[@]}"
- name: Set up Node.js 22
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
with:
node-version: '22'
- name: Expose trusted Node.js command paths
shell: bash
run: |
set -euo pipefail
node_path="$(command -v node)"
npm_path="$(command -v npm)"
test -x "${node_path}"
test -x "${npm_path}"
node_root="$(cd "$(dirname "${node_path}")/.." && pwd -P)"
test -d "${node_root}/lib/node_modules/npm"
sudo_command=()
if [[ "$(id -u)" -ne 0 ]]; then
command -v sudo >/dev/null 2>&1 || {
echo 'non-root runner user requires sudo to expose trusted Node.js paths.' >&2
exit 1
}
sudo_command=(sudo -E)
fi
trusted_node_root='/usr/local/lib/genarrative-node'
"${sudo_command[@]}" install -d -m 0755 "${trusted_node_root}"
"${sudo_command[@]}" cp -a "${node_root}/." "${trusted_node_root}/"
"${sudo_command[@]}" ln -sfn "${trusted_node_root}/bin/node" /usr/local/bin/node
"${sudo_command[@]}" ln -sfn "${trusted_node_root}/bin/npm" /usr/local/bin/npm
/usr/local/bin/node --version
/usr/local/bin/npm --version
- name: Set up repository Rust toolchain
shell: bash
run: |
set -euo pipefail
if ! command -v rustup >/dev/null 2>&1; then
for attempt in $(seq 1 10); do
if curl --retry 3 --retry-all-errors --retry-delay 2 \
--proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \
| sh -s -- -y --profile minimal --default-toolchain none; then
break
fi
if [[ "${attempt}" -eq 10 ]]; then
echo 'rustup bootstrap failed after 10 attempts.' >&2
exit 1
fi
sleep $((attempt * 2))
done
fi
echo "${HOME}/.cargo/bin" >> "${GITHUB_PATH}"
export PATH="${HOME}/.cargo/bin:${PATH}"
toolchain="$(sed -n 's/^channel = "\([^"]*\)"/\1/p' rust-toolchain.toml)"
test -n "${toolchain}"
for attempt in $(seq 1 10); do
if rustup toolchain install "${toolchain}" --profile minimal --component rustfmt; then
break
fi
if [[ "${attempt}" -eq 10 ]]; then
echo 'Rust toolchain installation failed after 10 attempts.' >&2
exit 1
fi
sleep $((attempt * 2))
done
rustc --version
cargo --version
rustfmt --version
- name: Expose trusted Rust command paths
shell: bash
run: |
set -euo pipefail
rustup_path="$(command -v rustup)"
test -x "${rustup_path}"
rustup_home="$(rustup show home)"
test -d "${rustup_home}"
sudo_command=()
if [[ "$(id -u)" -ne 0 ]]; then
command -v sudo >/dev/null 2>&1 || {
echo 'non-root runner user requires sudo to expose trusted Rust paths.' >&2
exit 1
}
sudo_command=(sudo -E)
fi
if [[ "$(readlink -f "${rustup_path}")" != '/usr/local/bin/rustup' ]]; then
"${sudo_command[@]}" install -m 0755 "${rustup_path}" /usr/local/bin/rustup
fi
for command_name in cargo rustc rustdoc rustfmt; do
"${sudo_command[@]}" ln -sfn rustup "/usr/local/bin/${command_name}"
done
echo "RUSTUP_HOME=${rustup_home}" >> "${GITHUB_ENV}"
/usr/local/bin/cargo --version
/usr/local/bin/rustc --version
/usr/local/bin/rustfmt --version
- name: Install npm dependencies
run: npm ci
- name: Install AI game creator dependencies
run: npm ci --prefix apps/ai-game-creator-shell
- name: Run native shell gates
run: npm run check:native-shells
- name: Ensure native lockfiles are unchanged
run: git diff --exit-code -- apps/desktop-shell/src-tauri/Cargo.lock apps/ai-game-creator-shell/src-tauri/Cargo.lock