diff --git a/.github/workflows/report-red-main.yml b/.github/workflows/report-red-main.yml index 159be53..fa1ceec 100644 --- a/.github/workflows/report-red-main.yml +++ b/.github/workflows/report-red-main.yml @@ -3,7 +3,8 @@ # A pull request runs only the fast tier (Linux x86-64, #443), so a failure that only macOS, Windows, arm64 or an example leg shows is first seen # on `main` after the merge. The badges in the README show it, but nobody has to look at them. This workflow is the push that does not wait for a look. # -# It reacts to the end of `Test JVM (arcadedb-jvm)`, `Test native (arcadedb)` and `Test Python Examples`, and only when the run was +# It reacts to the end of `Test JVM (arcadedb-jvm)`, `Test native (arcadedb)`, `Test native (engine snapshot)` (the weekly native run +# against upstream's engine snapshot) and `Test Python Examples`, and only when the run was # - on `main` (a push, the nightly schedule, or a manual run on `main`) and from this repository: never a pull request, and the # release workflows are other workflows (a workflow that another one calls does not start a `workflow_run` of its own); # - red: the run ended as `failure`, `timed_out` or `startup_failure`. A run that was `cancelled` is not red, because a newer push to `main` cancels @@ -32,6 +33,7 @@ on: workflows: - "Test JVM (arcadedb-jvm)" - "Test native (arcadedb)" + - "Test native (engine snapshot)" - "Test Python Examples" types: [completed] diff --git a/.github/workflows/test-native-snapshot.yml b/.github/workflows/test-native-snapshot.yml new file mode 100644 index 0000000..2064516 --- /dev/null +++ b/.github/workflows/test-native-snapshot.yml @@ -0,0 +1,32 @@ +# Once a week, the native build against upstream's current engine snapshot. +# +# Between releases test-native.yml links DEV_ENGINE, the newest engine release, so an engine change that breaks the native image or the +# parity suite would first show after the next release. test-jvm.yml already runs every night against upstream's newest snapshot. This +# workflow calls test-native.yml with `engine-snapshot: true`: the floating A.B.C-SNAPSHOT of the base of DEFAULT_VERSION (a pin that +# scripts/bump_engine.py moves after each release), on the legs of a pull request (linux-x86_64 only, no example). It is weekly and on +# one platform because the runners are shared with ArcadeData/arcadedb. It publishes nothing. report-red-main.yml opens the issue +# "Full CI is red on main: Test native (engine snapshot)" when it is red. +# +# REMOVE WHEN: test-native.yml itself links upstream's snapshot between releases. +name: Test native (engine snapshot) + +on: + schedule: + - cron: "40 4 * * 6" # Saturday, after the nightly runs of the other workflows have started + workflow_dispatch: + +permissions: + contents: read + +jobs: + native: + name: Native, engine snapshot + uses: ./.github/workflows/test-native.yml + # issues: write is for the `crash-report` job of test-native.yml alone. A called workflow cannot hold more permission than its caller + # gives it, so without this line the run would refuse to start; the called workflow's own `permissions: contents: read` keeps every + # other job read-only. + permissions: + contents: read + issues: write + with: + engine-snapshot: true diff --git a/.github/workflows/test-native.yml b/.github/workflows/test-native.yml index 98b2154..7b68f3d 100644 --- a/.github/workflows/test-native.yml +++ b/.github/workflows/test-native.yml @@ -11,6 +11,7 @@ # nightly all four platforms, Python 3.12 and 3.14, but only when something besides docs changed in the last 25 hours (a full run on Mondays) # dispatch all four platforms, Python 3.12 and 3.14 # workflow_call from release-native.yml with `release: true`: all four platforms, Python 3.11 to 3.14 +# weekly from test-native-snapshot.yml with `engine-snapshot: true`: the legs of a pull request against upstream's engine snapshot # This workflow never publishes: it has no id-token permission and no environment. # # Beside the full parity runs, the `pyver` job installs the already built linux-x86_64 wheel (py3-none: no rebuild) into the Pythons the full @@ -68,13 +69,19 @@ on: paths: *native_paths schedule: - cron: "40 3 * * *" - # Called by release-native.yml on a version tag. + # Called by release-native.yml on a version tag, and weekly by test-native-snapshot.yml. workflow_call: inputs: version: - description: "Wheel version to build (PEP 440: A.B.C.devN, A.B.C or A.B.C.postN); the release passes the tag" - required: true + description: "Wheel version to build (PEP 440: A.B.C.devN, A.B.C or A.B.C.postN); the release passes the tag; empty = DEFAULT_VERSION" + required: false + default: "" type: string + engine-snapshot: + description: "Link the floating A.B.C-SNAPSHOT of the base of a devN version, on the legs of a pull request (the weekly run)" + required: false + default: false + type: boolean engine: description: "Engine release (Maven Central) the image links; empty = the release segment of a final version, else the newest release" required: false @@ -117,13 +124,15 @@ on: # The group names the workflow literally: github.workflow is the CALLER's name in a workflow_call, and the group of release-native.yml # must differ from this one or the two would wait for each other. # +# The weekly engine-snapshot run has a group of its own, so it and the nightly run (both scheduled) never cancel each other. # Per event: a pull request has one group per PR; a push to main and the nightly schedule each have their own group (a newer run # supersedes an older one); a workflow_dispatch has a group of its own per run, so a manual run and a push can never cancel each other # (they used to share the ref of main); a run for a tag (the release calls this workflow, and github.event_name is then the caller's # push) is never cancelled, a half-done release is worse than a queued one. concurrency: group: >- - ${{ github.event_name == 'pull_request' && format('test-native-{0}', github.event.pull_request.number) + ${{ inputs.engine-snapshot && format('test-native-snapshot-{0}', github.ref) + || github.event_name == 'pull_request' && format('test-native-{0}', github.event.pull_request.number) || github.event_name == 'workflow_dispatch' && format('test-native-dispatch-{0}', github.run_id) || github.event_name == 'schedule' && 'test-native-schedule' || format('test-native-{0}', github.ref) }} @@ -172,6 +181,7 @@ jobs: INPUT_ENGINE: ${{ inputs.engine }} INPUT_MAVEN_ENGINE: ${{ inputs.maven-engine }} INPUT_RELEASE: ${{ inputs.release }} + INPUT_ENGINE_SNAPSHOT: ${{ inputs.engine-snapshot }} run: | set -euo pipefail version="${INPUT_VERSION:-$DEFAULT_VERSION}" @@ -193,6 +203,9 @@ jobs: # Maven resolves the pinned TIMESTAMPED snapshot, not the floating A.B.C-SNAPSHOT: upstream deploys a new snapshot most days pin_snapshot="$(printf '%s\n' "$pin_env" | sed -n 's/^SNAPSHOT=//p')" [ -n "$pin_snapshot" ] || { echo "::error::no snapshot in the pin" >&2; exit 1; } + elif [ "${INPUT_ENGINE_SNAPSHOT:-}" = true ]; then + # the weekly run (test-native-snapshot.yml): upstream's current snapshot of this base, floating + engine="$base-SNAPSHOT" else engine="${INPUT_ENGINE:-$DEV_ENGINE}" fi @@ -228,6 +241,7 @@ jobs: EVENT: ${{ github.event_name }} RELEASE: ${{ inputs.release }} LEGS: ${{ inputs.legs }} + ENGINE_SNAPSHOT: ${{ inputs.engine-snapshot }} GH_TOKEN: ${{ github.token }} PR_NUMBER: ${{ github.event.pull_request.number }} PR_AUTHOR: ${{ github.event.pull_request.user.login }} @@ -244,7 +258,9 @@ jobs: if [ "$RELEASE" = true ]; then event=release; fi # a manual run may ask for the legs of a pull request (one platform, one Python): the runner cap is shared with upstream if [ "$EVENT" = workflow_dispatch ] && [ "${LEGS:-full}" = pull-request ]; then event=pull_request; fi - if [ "$EVENT" = "schedule" ]; then + # the weekly engine-snapshot run: one platform, one Python, and never skipped (what changes is upstream, not this repository) + if [ "${ENGINE_SNAPSHOT:-}" = true ]; then event=pull_request; fi + if [ "$EVENT" = "schedule" ] && [ "${ENGINE_SNAPSHOT:-}" != true ]; then changed="$(git log --since='25 hours ago' --format=%h -- src native tests scripts examples pyproject.toml .github/workflows/test-native.yml | wc -l)" monday="$(date -u +%u)" if [ "$changed" = 0 ] && [ "$monday" != 1 ]; then diff --git a/docs/modules/ROOT/pages/development/ci.adoc b/docs/modules/ROOT/pages/development/ci.adoc index 1f869fc..395a59d 100644 --- a/docs/modules/ROOT/pages/development/ci.adoc +++ b/docs/modules/ROOT/pages/development/ci.adoc @@ -80,7 +80,8 @@ The names of the test jobs do not change: `Test arcadedb (, Python -f arcadedb-tag=26.11.1` (the engine of `26.11.1` and its `.postN` releases). Without the input the jars come from `latest`, the wheel carries another engine than the release, and a comparison with the release measures the engine as well as the change. The native build needs no such input, because it links a release engine by default. @@ -110,7 +111,7 @@ These workflows follow ArcadeData/arcadedb and need no secret. Issues and pull r | `dependabot-auto-merge.yml` | Every hour, squash-merges Dependabot pull requests that are patch or minor updates, mergeable, and have a non-empty list of checks that all succeeded. Majors and grouped updates stay open. Logic in `.github/scripts/dependabot_merge.py`. | `dependency-review.yml` | Fails a pull request that adds a dependency with a known vulnerability (moderate or worse) or a GPL, AGPL or SSPL licence. Policy in `.github/dependency-review-config.yml`. | `gitignore-hygiene.yml` | Fails when a `.gitignore` pattern matches a tracked file. -| `report-red-main.yml` | After `test-jvm.yml`, `test-native.yml` or `test-python-examples.yml` ends on `main` (a push, the nightly run or a manual run, never a pull request or a release), opens the issue "Full CI is red on main: " when the run was red, or comments on it when it is open. A green run of the same workflow adds a comment "Green again"; nothing is closed. A run that a newer run or a person cancelled is not red, except when a job hit its time limit. It holds `issues: write` and `contents: read` only and runs no code of a pull request. +| `report-red-main.yml` | After `test-jvm.yml`, `test-native.yml`, `test-native-snapshot.yml` or `test-python-examples.yml` ends on `main` (a push, the nightly run or a manual run, never a pull request or a release), opens the issue "Full CI is red on main: " when the run was red, or comments on it when it is open. A green run of the same workflow adds a comment "Green again"; nothing is closed. A run that a newer run or a person cancelled is not red, except when a job hit its time limit. It holds `issues: write` and `contents: read` only and runs no code of a pull request. | `assign-maintainer.yml` | Assigns every new issue and pull request to the maintainer when it is opened. Nothing from a pull request head is checked out or run. |=== diff --git a/tests/test_dev_engine_pin.py b/tests/test_dev_engine_pin.py index 11586a3..5bc5f22 100644 --- a/tests/test_dev_engine_pin.py +++ b/tests/test_dev_engine_pin.py @@ -22,17 +22,13 @@ PIN = pin_mod.load_pin() -def _plan_step() -> str: +def _plan_step(name: str = "Resolve the version and the engine") -> str: lines = ( (ROOT / ".github/workflows/test-native.yml") .read_text(encoding="utf-8") .splitlines() ) - start = next( - i - for i, ln in enumerate(lines) - if ln.strip() == "- name: Resolve the version and the engine" - ) + start = next(i for i, ln in enumerate(lines) if ln.strip() == f"- name: {name}") run = next(i for i in range(start, len(lines)) if lines[i].strip() == "run: |") indent = len(lines[run + 1]) - len(lines[run + 1].lstrip()) body = [] @@ -43,7 +39,9 @@ def _plan_step() -> str: return "\n".join(body) + "\n" -def _run_plan(tmp_path, version, engine="", release="true", maven_engine=""): +def _run_plan( + tmp_path, version, engine="", release="true", maven_engine="", snapshot="" +): out = tmp_path / "out" out.write_text("") env = { @@ -52,6 +50,7 @@ def _run_plan(tmp_path, version, engine="", release="true", maven_engine=""): "INPUT_ENGINE": engine, "INPUT_RELEASE": release, "INPUT_MAVEN_ENGINE": maven_engine, + "INPUT_ENGINE_SNAPSHOT": snapshot, "DEV_ENGINE": "26.11.1", "DEFAULT_VERSION": "26.12.1.dev0", "GITHUB_OUTPUT": str(out), @@ -131,6 +130,49 @@ def test_a_manual_final_run_still_refuses_a_snapshot(tmp_path): assert r.returncode != 0 +def test_the_weekly_run_links_the_floating_snapshot_of_the_default_version(tmp_path): + # test-native-snapshot.yml passes no version and no engine, only engine-snapshot + r, out = _run_plan(tmp_path, "", release="false", snapshot="true") + assert r.returncode == 0, r.stderr + assert "version=26.12.1.dev0\n" in out + assert "engine=26.12.1-SNAPSHOT\n" in out + # floating: Maven resolves the newest deploy, not the timestamped snapshot of a dev release + assert "maven-engine=26.12.1-SNAPSHOT\n" in out + + +def test_a_run_without_the_weekly_input_still_links_the_engine_release(tmp_path): + r, out = _run_plan(tmp_path, "", release="false", snapshot="false") + assert r.returncode == 0, r.stderr + assert "engine=26.11.1\n" in out and "SNAPSHOT" not in out + + +def test_the_weekly_run_is_never_skipped_and_builds_one_platform(tmp_path): + out = tmp_path / "out" + out.write_text("") + env = { + "PATH": "/usr/bin:/bin:/usr/local/bin", + "EVENT": "schedule", + "RELEASE": "false", + "LEGS": "", + "ENGINE_SNAPSHOT": "true", + "GITHUB_OUTPUT": str(out), + } + r = subprocess.run( # nosec B603 B607 + ["bash", "-c", _plan_step("Choose the legs")], + env=env, + cwd=ROOT, + capture_output=True, + text=True, + timeout=60, + ) + assert r.returncode == 0, r.stderr + lines = dict(line.split("=", 1) for line in out.read_text().splitlines()) + assert lines["run"] == "true" + assert [leg["key"] for leg in json.loads(lines["build"])] == ["linux-x86_64"] + assert [leg["python"] for leg in json.loads(lines["test"])] == ["3.12"] + assert json.loads(lines["examples"]) == [] + + def _hashes(**changes): h = copy.deepcopy(PIN["jars"]) h.update(changes) diff --git a/tests/test_select_native_matrix.py b/tests/test_select_native_matrix.py index b0baea7..56b6eb3 100644 --- a/tests/test_select_native_matrix.py +++ b/tests/test_select_native_matrix.py @@ -235,6 +235,20 @@ def test_a_release_needs_a_marker_from_every_leg_of_the_python_version_job(): assert "INFORMATIONAL for now" not in test_native +def test_the_weekly_engine_snapshot_run_calls_the_native_workflow_once_a_week_and_is_reported(): + workflows = ROOT / ".github" / "workflows" + weekly = (workflows / "test-native-snapshot.yml").read_text(encoding="utf-8") + crons = re.findall(r'^\s+- cron: "([^"]+)"', weekly, re.M) + # one schedule, on one day of the week: the runners are shared with upstream + assert len(crons) == 1 and crons[0].split()[4].isdigit(), crons + assert "uses: ./.github/workflows/test-native.yml" in weekly + assert re.search(r"^ engine-snapshot: true$", weekly, re.M) + # a called workflow starts no workflow_run of its own, so the report listens for the name of the caller + name = re.search(r"^name: (.+)$", weekly, re.M).group(1) + report = (workflows / "report-red-main.yml").read_text(encoding="utf-8") + assert f'\n - "{name}"\n' in report + + def test_the_linux_legs_build_in_the_manylinux_container_of_the_tag_and_the_workflow_gates_that_floor(): linux = {k: leg for k, leg in sel.PLATFORMS.items() if leg["kind"] == "linux"} assert set(linux) == {"linux-x86_64", "linux-aarch64"} diff --git a/tests/test_workflow_concurrency.py b/tests/test_workflow_concurrency.py index 1822f2f..ad8550e 100644 --- a/tests/test_workflow_concurrency.py +++ b/tests/test_workflow_concurrency.py @@ -36,7 +36,12 @@ def fmt(template: str, *values: str) -> str: return template.format(*values) translated = re.sub( - r"github\.([a-z_.]+)", lambda m: repr(context.get(m.group(1), "")), expression + r"inputs\.([a-z-]+)", + lambda m: repr(context.get(f"inputs.{m.group(1)}", "")), + expression, + ) + translated = re.sub( + r"github\.([a-z_.]+)", lambda m: repr(context.get(m.group(1), "")), translated ) translated = translated.replace("&&", " and ").replace("||", " or ") # only literals, operators and format() are left; nothing else may run @@ -44,7 +49,14 @@ def fmt(template: str, *values: str) -> str: return eval(translated, {"__builtins__": {}, "format": fmt}) # nosec B307 -def _run(workflow: str, event: str, ref: str, run_id: str = "1", pr: str = ""): +def _run( + workflow: str, + event: str, + ref: str, + run_id: str = "1", + pr: str = "", + engine_snapshot: bool = False, +): group, cancel = _concurrency(WORKFLOWS[workflow].read_text(encoding="utf-8")) context = { "event_name": event, @@ -52,10 +64,28 @@ def _run(workflow: str, event: str, ref: str, run_id: str = "1", pr: str = ""): "ref_type": "tag" if ref.startswith("refs/tags/") else "branch", "run_id": run_id, "event.pull_request.number": pr, + "inputs.engine-snapshot": engine_snapshot, } return _evaluate(group, context), bool(_evaluate(cancel, context)) +def test_the_weekly_engine_snapshot_run_and_the_nightly_run_never_cancel_each_other(): + # test-native-snapshot.yml calls test-native.yml: both runs are scheduled, so only the input tells them apart + nightly = _run("test-native", "schedule", "refs/heads/main", "1") + weekly = _run( + "test-native", "schedule", "refs/heads/main", "2", engine_snapshot=True + ) + assert weekly[0] != nightly[0] + by_hand = _run( + "test-native", + "workflow_dispatch", + "refs/heads/main", + "3", + engine_snapshot=True, + ) + assert by_hand[0] != nightly[0] and by_hand[1] is False + + @pytest.mark.parametrize("workflow", sorted(WORKFLOWS)) def test_a_new_push_to_a_pull_request_cancels_the_old_run(workflow): old = _run(workflow, "pull_request", "refs/pull/7/merge", "1", "7")