diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 745eabd..5b44767 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,6 @@ name: ci -# Gate for EXFA-Engine. Also a reusable workflow: sde-update.yml calls this file via `workflow_call` +# Gate for EXFA-Engine. Also a reusable workflow (`workflow_call`; SDE updates are prepared locally with ci/sde_update.py) # with `sde_tag` (override the tag pinned in sde.lock) and `skip_round1_sha` (new data legitimately # changes the round-1 byte checks). on: @@ -167,7 +167,13 @@ jobs: - name: Build wasip1 run: cargo build --release --locked --target wasm32-wasip1 -p exfa-cli - name: Install wasmtime - run: curl -fsSL https://wasmtime.dev/install.sh | bash -s -- --version v33.0.0 + run: | + # wasmtime.dev / GitHub release downloads 504 now and then: retry instead of failing the whole job. + for i in 1 2 3 4 5; do + curl -fsSL https://wasmtime.dev/install.sh | bash -s -- --version v33.0.0 && break + echo "wasmtime install attempt $i failed; retrying"; sleep $((i*15)) + done + test -x "$HOME/.wasmtime/bin/wasmtime" - name: Suites run: | export PATH="$HOME/.wasmtime/bin:$PATH" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9b5289c..89dfbb5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -152,7 +152,7 @@ jobs: ref: ${{ inputs.tag || github.ref }} - uses: actions/download-artifact@v4 with: - # pkg-* only: a caller run (sde-update) also carries the gate's ci-results-* artifacts + # pkg-* only: a caller run also carries the gate's ci-results-* artifacts pattern: 'pkg-*' path: dist merge-multiple: true diff --git a/.github/workflows/sde-update.yml b/.github/workflows/sde-update.yml deleted file mode 100644 index 3cb0a8a..0000000 --- a/.github/workflows/sde-update.yml +++ /dev/null @@ -1,240 +0,0 @@ -name: sde-update - -# Drives a new EXFA-Data SDE release through the engine. EXFA-Data's sde.yml sends a -# repository_dispatch (type sde-release, client_payload {tag, sde_build, revision}) after each -# dataset release; this workflow can also be run manually with the same tag. -# -# Flow: if sde.lock already pins the tag -> exit. Otherwise run the whole ci.yml gate against the -# new dataset (workflow_call, skip_round1_sha: new data legitimately changes the round-1 bytes). -# On green: update sde.lock, regenerate the two round-1 shas from the new output, bump the workspace -# patch version, commit "Update SDE to ", tag v and call release.yml (GITHUB_TOKEN-pushed -# tags do not fire on:push tag triggers). On gate failure: open an issue, main untouched. -# -# The repository_dispatch path needs a PAT (EXFA_DISPATCH_TOKEN) on the EXFA-Data side; the 6-hourly -# schedule below polls the latest public sde-* release instead, so upgrades happen either way. -on: - repository_dispatch: - types: [sde-release] - schedule: - - cron: '23 */6 * * *' - workflow_dispatch: - inputs: - tag: - description: 'EXFA-Data SDE release tag (default: latest sde-* release)' - required: false - default: '' - bench_sha: - description: 'EXFA-Bench commit to gate against (default: bench.lock); also written into bench.lock on update' - required: false - default: '' - -concurrency: - group: sde-update - -permissions: - contents: write - issues: write - -env: - NEW_TAG: ${{ github.event_name == 'repository_dispatch' && github.event.client_payload.tag || inputs.tag }} - -jobs: - check: - runs-on: ubuntu-latest - outputs: - proceed: ${{ steps.c.outputs.proceed }} - tag: ${{ steps.c.outputs.tag }} - env: - GH_TOKEN: ${{ github.token }} - steps: - - uses: actions/checkout@v4 - - id: c - run: | - set -euo pipefail - cur=$(cut -d= -f2 sde.lock) - tag="$NEW_TAG" - # scheduled run or manual dispatch without a tag: poll the latest sde-* release - if [ -z "$tag" ]; then - tag=$(gh release list -R EX-CT/EXFA-Data --json tagName --jq '[.[] | select(.tagName | startswith("sde-"))][0].tagName') - echo "polled latest EXFA-Data SDE release: ${tag:-}" - fi - echo "sde.lock pins $cur; incoming ${tag:-}" - if [ -z "$tag" ]; then - echo "::notice::no sde-* release found — nothing to do" - echo "proceed=0" >> "$GITHUB_OUTPUT" - exit 0 - fi - echo "tag=$tag" >> "$GITHUB_OUTPUT" - if [ "$tag" = "$cur" ]; then - echo "sde.lock already at $tag — nothing to do" - echo "proceed=0" >> "$GITHUB_OUTPUT" - else - echo "proceed=1" >> "$GITHUB_OUTPUT" - fi - - gate: - needs: check - if: needs.check.outputs.proceed == '1' - uses: ./.github/workflows/ci.yml - secrets: inherit - with: - sde_tag: ${{ needs.check.outputs.tag }} - bench_sha: ${{ inputs.bench_sha }} - skip_round1_sha: true - - update: - needs: [check, gate] - runs-on: ubuntu-latest - outputs: - tag: ${{ steps.b.outputs.tag }} - env: - GH_TOKEN: ${{ github.token }} - NEW_TAG: ${{ needs.check.outputs.tag }} - steps: - - uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@stable - - uses: Swatinem/rust-cache@v2 - - uses: actions/setup-python@v5 - with: - python-version: '3.13' - - name: bench.lock + EXFA-Bench checkout - env: - BENCH_OVERRIDE: ${{ inputs.bench_sha }} - run: | - set -euo pipefail - grep '^BENCH_' bench.lock - echo "BENCH_SHA=${BENCH_OVERRIDE:-$(grep '^BENCH_SHA=' bench.lock | cut -d= -f2)}" >> "$GITHUB_ENV" - - uses: actions/checkout@v4 - with: - repository: EX-CT/EXFA-Bench - path: _bench - fetch-depth: 0 - - name: Pin EXFA-Bench - run: git -C _bench checkout -q "$BENCH_SHA" - - name: New dataset ($NEW_TAG) - run: | - set -euo pipefail - gh release download "$NEW_TAG" -R EX-CT/EXFA-Data --pattern 'dataset-*.json.gz' -D _data - echo "EXFA_DATASET=$(ls $PWD/_data/dataset-*.json.gz | head -1)" >> "$GITHUB_ENV" - - name: Refresh embedded price snapshot (its sde_build stamp should match this build) - # EXFA-Data's sde.yml produces a snapshot on this SDE right after the dataset release, so the newest - # prices-* tag normally carries the same sde_build. If it doesn't (snapshot failed / not published - # yet) embed it anyway — freshest prices beat a stale file; the engine just warns at runtime. - run: | - set -euo pipefail - B=${NEW_TAG#sde-}; B=${B%%-*} - PTAG=$(gh release list -R EX-CT/EXFA-Data --json tagName --jq '[.[] | select(.tagName | startswith("prices-"))][0].tagName') - echo "price snapshot release: ${PTAG:-}" - [ -z "$PTAG" ] && { echo "::warning::no prices-* release in EXFA-Data — keeping the current embedded snapshot"; exit 0; } - gh release download "$PTAG" -R EX-CT/EXFA-Data -D _prices -p 'prices-*.json.gz' - python3 - "$(ls _prices/prices-*.json.gz | head -1)" "$B" <<'EOF' - import gzip, json, re, sys, pathlib - f, want_build = sys.argv[1], int(sys.argv[2]) - s = json.loads(gzip.decompress(pathlib.Path(f).read_bytes())) - sid, mtime, chash, ntypes = s["snapshot_id"], s["market_time"], s["content_hash"], s["type_count"] - data = pathlib.Path("crates/exfa-core/data") - for old in data.glob("prices-*.json.gz"): - old.unlink() - dest = data / f"prices-{sid}.json.gz" - dest.write_bytes(pathlib.Path(f).read_bytes()) - p = pathlib.Path("crates/exfa-core/src/price.rs"); t = p.read_text(encoding="utf-8") - t = re.sub(r'include_bytes!\("\.\./data/prices-[^"]+"\)', f'include_bytes!("../data/{dest.name}")', t) - t = re.sub(r'EMBEDDED_ID: &str = "[^"]+"', f'EMBEDDED_ID: &str = "{sid}"', t) - t = re.sub(r'EMBEDDED_TIME: &str = "[^"]+"', f'EMBEDDED_TIME: &str = "{mtime}"', t) - t = re.sub(r'EMBEDDED_HASH: &str = "[^"]+"', f'EMBEDDED_HASH: &str = "{chash}"', t) - t = re.sub(r'EMBEDDED_TYPES: usize = \d+', f'EMBEDDED_TYPES: usize = {ntypes}', t) - p.write_text(t, encoding="utf-8") - print(f"embedded snapshot -> {sid} ({ntypes} types, sde_build {s.get('sde_build')}, market_time {mtime})") - if s.get("sde_build") != want_build: - print(f"::warning::snapshot sde_build {s.get('sde_build')} != dataset build {want_build} — embedded anyway (freshest available)") - EOF - - name: sde.lock + version bump + rebuild - id: b - env: - BENCH_OVERRIDE: ${{ inputs.bench_sha }} - run: | - set -euo pipefail - sed -i "s/^SDE_TAG=.*/SDE_TAG=$NEW_TAG/" sde.lock - # keep bench.lock consistent with the pin the gate ran against (workflow_dispatch override) - if [ -n "${BENCH_OVERRIDE:-}" ]; then - sed -i "s/^BENCH_SHA=.*/BENCH_SHA=$BENCH_OVERRIDE/" bench.lock - echo "bench.lock -> $BENCH_OVERRIDE" - fi - NEW_VER=$(python3 - <<'EOF' - import re, pathlib - p = pathlib.Path("Cargo.toml"); t = p.read_text() - m = re.search(r'(?ms)^\[workspace\.package\].*?^version\s*=\s*"(\d+)\.(\d+)\.(\d+)"', t) - maj, mi, pa = map(int, m.groups()); new = f"{maj}.{mi}.{pa+1}" - span = t[m.start():m.end()] - p.write_text(t[:m.start()] + span.replace(f"{maj}.{mi}.{pa}", new, 1) + t[m.end():]) - print(new) - EOF - ) - echo "version bump -> $NEW_VER" - # build without --locked so Cargo.lock picks up the workspace version bump - cargo build --release -p exfa-cli - echo "tag=v$NEW_VER" >> "$GITHUB_OUTPUT" - - name: Regenerate round-1 shas on the new dataset - run: | - set -euo pipefail - for f in _bench/suites/round1/cases/*.json; do python3 -c "import json,sys;print(json.dumps(json.load(open(sys.argv[1]))))" "$f"; done > /tmp/round1.jsonl - ./target/release/exfa batch < /tmp/round1.jsonl > /tmp/round1.out.jsonl - sha256sum < /tmp/round1.out.jsonl | cut -d' ' -f1 > ci/round1.sha256 - python3 ci/strip_keys.py $(grep -v '^#' ci/round1-new-keys.txt) < /tmp/round1.out.jsonl | sha256sum | cut -d' ' -f1 > ci/round1-base.sha256 - echo "round1.sha256 = $(cat ci/round1.sha256)" - echo "round1-base.sha256 = $(cat ci/round1-base.sha256)" - - name: Commit + tag - run: | - set -euo pipefail - git config user.name "github-actions[bot]" - git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - git add sde.lock bench.lock Cargo.toml Cargo.lock ci/round1.sha256 ci/round1-base.sha256 crates/exfa-core/data crates/exfa-core/src/price.rs crates/exfa-core/tests/batch_prices.rs - git commit -m "Update SDE to $NEW_TAG" - git push origin main - git tag "$TAG_OUT" - git push origin "refs/tags/$TAG_OUT" - env: - TAG_OUT: ${{ steps.b.outputs.tag }} - - release: - needs: update - uses: ./.github/workflows/release.yml - secrets: inherit - with: - tag: ${{ needs.update.outputs.tag }} - dry_run: false - - blocked: - needs: [check, gate] - if: needs.check.outputs.proceed == '1' && failure() - runs-on: ubuntu-latest - env: - GH_TOKEN: ${{ github.token }} - NEW_TAG: ${{ needs.check.outputs.tag }} - steps: - - name: Open a blocking issue with the gate summary - run: | - set -uo pipefail - run_url="https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" - # find the reusable ci.yml run spawned by this workflow_call and pull its step summaries - summary="" - cid=$(gh run list -R "$GITHUB_REPOSITORY" --workflow ci.yml --event workflow_call --limit 5 \ - --json databaseId,createdAt --jq 'sort_by(.createdAt) | last | .databaseId' 2>/dev/null || true) - if [ -n "$cid" ]; then - for cr in $(gh api "repos/$GITHUB_REPOSITORY/actions/runs/$cid/jobs" --jq '.jobs[].check_run_url | split("/")[-1]' 2>/dev/null); do - t=$(gh api "repos/$GITHUB_REPOSITORY/check-runs/$cr" --jq '.output.text // empty' 2>/dev/null || true) - [ -n "$t" ] && summary="$summary - $t" - done - fi - { - echo "EXFA-Data released SDE \`$NEW_TAG\` but the engine gate rejected it." - echo "" - echo "- sde-update run: $run_url" - [ -n "$cid" ] && echo "- gate run: https://github.com/$GITHUB_REPOSITORY/actions/runs/$cid" - echo "" - echo "## Gate summary" - [ -n "$summary" ] && echo "$summary" || echo "(no step summaries found — see the gate run logs)" - } > /tmp/issue.md - cat /tmp/issue.md - gh issue create -R "$GITHUB_REPOSITORY" --title "SDE $NEW_TAG blocked by the gate" --body-file /tmp/issue.md diff --git a/.gitignore b/.gitignore index 2ddb486..f1e2208 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ target/ ci-results/ _suites/ _data/ +_bench/ diff --git a/Cargo.lock b/Cargo.lock index fd799b0..a8c2736 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -25,7 +25,7 @@ dependencies = [ [[package]] name = "exfa-cli" -version = "0.2.1" +version = "0.2.2" dependencies = [ "exfa-core", "exfa-formats", @@ -35,7 +35,7 @@ dependencies = [ [[package]] name = "exfa-codegen" -version = "0.2.1" +version = "0.2.2" dependencies = [ "flate2", "serde_json", @@ -43,7 +43,7 @@ dependencies = [ [[package]] name = "exfa-core" -version = "0.2.1" +version = "0.2.2" dependencies = [ "exfa-codegen", "flate2", @@ -55,7 +55,7 @@ dependencies = [ [[package]] name = "exfa-formats" -version = "0.2.1" +version = "0.2.2" dependencies = [ "exfa-core", "serde_json", @@ -63,7 +63,7 @@ dependencies = [ [[package]] name = "exfa-formats-wasm" -version = "0.2.1" +version = "0.2.2" dependencies = [ "exfa-formats", "serde_json", @@ -71,7 +71,7 @@ dependencies = [ [[package]] name = "exfa-optimizer" -version = "0.2.1" +version = "0.2.2" dependencies = [ "exfa-core", "serde", @@ -80,7 +80,7 @@ dependencies = [ [[package]] name = "exfa-wasm" -version = "0.2.1" +version = "0.2.2" dependencies = [ "exfa-core", "exfa-formats", diff --git a/Cargo.toml b/Cargo.toml index af8f18a..c7f12df 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ default-members = [ ] [workspace.package] -version = "0.2.1" +version = "0.2.2" edition = "2021" license = "LGPL-3.0-or-later" repository = "https://github.com/EX-CT/EXFA-Engine" diff --git a/README.md b/README.md index a30e627..9edf470 100644 --- a/README.md +++ b/README.md @@ -80,8 +80,10 @@ sha256 checks (`ci/round1.sha256` + `ci/round1-base.sha256` after stripping `ci/ run first: `exfa-formats` (`crates/exfa-formats/tests/roundtrip.rs`: per format import→export and export→import round trips and error paths), `exfa-optimizer` property tests, then the whole workspace. Locally: `BENCH=/path/to/EXFA-Bench ci/run_suites.sh native ./target/release/exfa`. The dataset tag is pinned in `sde.lock` -and downloaded from `EX-CT/EXFA-Data`; `sde-update.yml` consumes EXFA-Data `sde-release` dispatches, re-gates and -releases automatically. +and downloaded from `EX-CT/EXFA-Data`; new SDE builds are adopted **locally and by hand**: `python ci/sde_update.py` downloads the +latest `sde-*` release, runs the gate (build, `cargo test`, `ci/run_suites.sh` against the pinned Bench), embeds the newest +price snapshot, bumps `sde.lock`/version/round-1 shas and commits on `sde/`; push it as a PR (CI re-gates native + +wasm), merge, then tag `v` to release. There is no scheduled auto-update. ### Bench diff --git a/bench.lock b/bench.lock index 353562f..06e37b7 100644 --- a/bench.lock +++ b/bench.lock @@ -1,2 +1,2 @@ BENCH_REPO=EX-CT/EXFA-Bench -BENCH_SHA=c6b6b4f9825beefbe2361f3752b978155de39660 +BENCH_SHA=c8c82f4d52eb8998a1c575ff3dcab46d74a586f1 diff --git a/ci/round1-base.sha256 b/ci/round1-base.sha256 index fd06ae6..8e14b11 100644 --- a/ci/round1-base.sha256 +++ b/ci/round1-base.sha256 @@ -1 +1 @@ -acb53102089a16f530aba278fac2403ed100dbf083377ed90e58f1f34914b514 +dd3f1da2d1735cc9d3f49b5c537de3290031c795178a6fef2de0657e4e2f9fd1 diff --git a/ci/round1.sha256 b/ci/round1.sha256 index cd0fff3..9cd0b2c 100644 --- a/ci/round1.sha256 +++ b/ci/round1.sha256 @@ -1 +1 @@ -de9e5d28a2a7b81d26ba0daf05b1519b0364aa94a90dcd6086b75d451b754916 +41b78d38919a0f70ea53e7e04cd0ff6745be6b8a691464430cf5f9f6a2d1508e diff --git a/ci/sde_update.py b/ci/sde_update.py new file mode 100644 index 0000000..c942ff8 --- /dev/null +++ b/ci/sde_update.py @@ -0,0 +1,206 @@ +#!/usr/bin/env python3 +"""Adopt a new EXFA-Data SDE release into the engine -- run locally, by hand (or by an agent). + +Replaces the old `sde-update` GitHub workflow (6-hourly poll + auto-release), which could only ever +open an issue when the gate failed. Adopting an SDE needs a human/agent decision (data change vs bench +fixture vs engine bug), so it is a local, reviewed step. The PR that this prepares is still gated by +the normal `ci` workflow (native + wasm suites on the new dataset). + + python ci/sde_update.py # latest sde-* release, gate, update, commit on branch sde/ + python ci/sde_update.py --tag sde-3670638-r7 + python ci/sde_update.py --bench-sha # gate against another EXFA-Bench commit (written to bench.lock) + python ci/sde_update.py --gate-only # download + build + test + suites, change nothing in the repo + python ci/sde_update.py --no-commit # update files but leave them uncommitted + +Steps: download dataset + pyfa presets -> pin _bench (bench.lock) -> cargo build --locked + cargo test +-> ci/run_suites.sh native (skip-round1: new data legitimately changes those bytes) -> embed the newest +prices-* snapshot -> sde.lock + patch version bump -> rebuild (Cargo.lock) -> regenerate the two round-1 +shas -> commit "Update SDE to ". Afterwards: push the branch, open a PR, merge when CI is green, +then `git tag v && git push origin v` (release.yml builds + publishes the binaries). +""" +import argparse, gzip, json, os, pathlib, re, shutil, subprocess, sys, hashlib + +ROOT = pathlib.Path(__file__).resolve().parent.parent +os.chdir(ROOT) +DATA_REPO = "EX-CT/EXFA-Data" + + +def run(cmd, check=True, capture=False, env=None, **kw): + print("+ " + " ".join(str(c) for c in cmd), flush=True) + r = subprocess.run([str(c) for c in cmd], check=False, capture_output=capture, env=env, **kw) + if check and r.returncode != 0: + if capture: + sys.stderr.write((r.stdout or b"").decode(errors="replace") + (r.stderr or b"").decode(errors="replace")) + sys.exit(f"FAILED ({r.returncode}): {' '.join(str(c) for c in cmd)}") + return r + + +def out(cmd): + return run(cmd, capture=True).stdout.decode().strip() + + +def lock(name): + return dict(l.strip().split("=", 1) for l in pathlib.Path(name).read_text(encoding="utf-8").splitlines() if "=" in l) + + +def posix(p): + # forward slashes work for python, cargo and Git Bash alike (C:/Users/...) + return str(pathlib.Path(p).resolve()).replace("\\", "/") + + +def find_bash(): + # a bare `bash` on Windows may be the WSL launcher; prefer Git for Windows' bash + for c in (os.environ.get("EXFA_BASH"), r"C:\Program Files\Git\bin\bash.exe", r"C:\Program Files (x86)\Git\bin\bash.exe"): + if c and pathlib.Path(c).exists(): + return c + return shutil.which("bash") or sys.exit("no bash found (install Git for Windows or set EXFA_BASH)") + + +def latest_release(prefix): + tags = json.loads(out(["gh", "release", "list", "-R", DATA_REPO, "--limit", "100", "--json", "tagName,createdAt"])) + tags = [t for t in tags if t["tagName"].startswith(prefix)] + if not tags: + sys.exit(f"no {prefix}* release in {DATA_REPO}") + # sde--r: highest build wins; prices-jita44-