mirror of
https://github.com/norandom/OpenUltraSAST.git
synced 2026-12-03 02:08:18 +00:00
By the maintainer's decision of 2026-11-25, recorded in the handover: "dagger/ci.py syncs the
git-ignored .env into the local container when run locally, and step 9 runs that script locally
for the first time. I have not read how CI supplies what .env holds; that is checked first, so
CI keeps what it needs."
`.env` is the first entry of the exclude list of the one upload in dagger/ci.py,
`client.host().directory(".", exclude=[...])`. The script is CI's dagger job and the same
script run locally; the entry matches nothing in CI and removes the root `.env` of the tree
when the script runs on a machine that has one.
CI keeps what it needs, read before the change: `.github/workflows/ci.yml` (97 lines) sets two
literal variables (`UV_NO_SYNC`, `DAGGER_VERSION`), uses no `secrets.*` and no `vars.*`, and
has no step that creates or copies a `.env`; the container gets one variable, `UV_NO_SYNC=1`.
The names `.env.example` lists, the two API keys, the `VALID_BENCHMARK_*` S3 settings and the
two Discord values, are supplied by no workflow. A checkout has no `.env`, because the file is
git-ignored; `.env.example` is not matched and stays in the upload. No test reads a `.env` from
the tree.
That the pattern removes the root `.env` rests on reading, not on a run: the SDK passes the
list unchanged to the engine, whose filter matches a pattern without wildcards against the
whole relative path (the independent reviewer traced it at v0.21.7, the version CI pins, and
ran that filter over a scratch tree; no engine and no container was started).
Tests: the new tests/test_dagger_ci_upload.py parses dagger/ci.py as text, so it needs no
dagger engine, and asserts that the one exclude list holds `.env`. It failed before the change
(the list without the entry, 1 failed) and passes after; with the two test files that read the
workflow files, 16 passed. ruff, mypy, the three gates and compileall pass, and the gates print
what they printed before the change. An independent reviewer approved the change in one round;
its remarks on the wording of the comment and of the test, and on the failure message of the
test, are applied.
Left for the maintainer's menu, not decided: excluding `.env.*` files as well (a bare pattern
would also drop `.env.example`, which a test reads), an in-container check that fails the
pipeline if the file ever got in, and `__pycache__` directories, which a local run uploads.
90 lines
3.4 KiB
Python
90 lines
3.4 KiB
Python
from __future__ import annotations
|
|
|
|
import sys
|
|
|
|
import anyio
|
|
|
|
import dagger
|
|
|
|
# Substrings that mark a transient registry / image-pull failure (e.g. a Docker
|
|
# Hub 5xx on the python:3.11-bookworm pull, or a registry.dagger.io timeout) that
|
|
# is worth retrying rather than failing the whole pipeline.
|
|
_TRANSIENT_MARKERS = (
|
|
"pull image",
|
|
"failed to authorize",
|
|
"failed to fetch oauth",
|
|
"TransportQueryError",
|
|
"i/o timeout",
|
|
"connection reset",
|
|
"context deadline exceeded",
|
|
" 502",
|
|
" 503",
|
|
" 520",
|
|
" 429",
|
|
)
|
|
|
|
|
|
async def _run_checks() -> None:
|
|
config = dagger.Config(log_output=sys.stderr)
|
|
async with dagger.Connection(config) as client:
|
|
source = client.host().directory(
|
|
".",
|
|
exclude=[
|
|
".env", # local settings and keys (.env.example lists them); CI has no .env: a checkout has only tracked files
|
|
".git",
|
|
".mypy_cache",
|
|
".pytest_cache",
|
|
".ruff_cache",
|
|
".venv",
|
|
"**/.openultrasast",
|
|
"dist",
|
|
],
|
|
)
|
|
checks = (
|
|
client.container()
|
|
.from_("python:3.11-bookworm")
|
|
.with_directory("/src", source)
|
|
.with_workdir("/src")
|
|
# The mounted tree carries no `.git` (excluded above), and tests that enumerate tracked
|
|
# files, such as the detection-core migration gate, need an index: give them this tree's.
|
|
# The tree can be owned by another user than the container's, so git must trust it first.
|
|
.with_exec(["git", "config", "--system", "--add", "safe.directory", "/src"])
|
|
.with_exec(["git", "init", "-q"])
|
|
.with_exec(["git", "add", "-A"])
|
|
.with_exec(["python", "-m", "pip", "install", "uv"])
|
|
# uv run re-syncs the environment to the lockfile's default extras unless told not to, which silently
|
|
# removed the extras below before pytest ran.
|
|
.with_env_variable("UV_NO_SYNC", "1")
|
|
.with_exec(["uv", "sync", "--group", "dev", "--extra", "hunt", "--extra", "semantic"])
|
|
.with_exec(["uv", "run", "ruff", "format", "--check", "."])
|
|
.with_exec(["uv", "run", "ruff", "check", "."])
|
|
.with_exec(["uv", "run", "mypy", "src/openultrasast"])
|
|
.with_exec(["uv", "run", "pytest"])
|
|
.with_exec(["uv", "run", "python", "-m", "openultrasast.gate"])
|
|
.with_exec(["uv", "run", "python", "-m", "openultrasast.map_gate"])
|
|
.with_exec(["uv", "run", "python", "-m", "openultrasast.pair_gate"])
|
|
.with_exec(["uv", "run", "python", "-m", "compileall", "src", "tests"])
|
|
.with_exec(["uv", "build"])
|
|
)
|
|
await checks.sync()
|
|
|
|
|
|
async def main() -> None:
|
|
attempts = 3
|
|
for attempt in range(1, attempts + 1):
|
|
try:
|
|
await _run_checks()
|
|
return
|
|
except Exception as exc: # noqa: BLE001 — retry only transient registry/pull failures
|
|
message = str(exc)
|
|
transient = any(marker in message for marker in _TRANSIENT_MARKERS)
|
|
if attempt < attempts and transient:
|
|
print(f"dagger: transient registry/pull failure on attempt {attempt}; retrying in 20s", file=sys.stderr)
|
|
await anyio.sleep(20)
|
|
continue
|
|
raise
|
|
|
|
|
|
if __name__ == "__main__":
|
|
anyio.run(main)
|