feat(ci): typecheck Lean payment ceilings when lean/ changes
Gitea ignores path filters, so the job diffs the previous push and skips unless lean/ or the workflow changed. Lean 4.34.0 comes from the GitHub release; mathlib is the olean cache.
This commit is contained in:
109
.gitea/workflows/lean-pay.yml
Normal file
109
.gitea/workflows/lean-pay.yml
Normal file
@@ -0,0 +1,109 @@
|
||||
# DO NOT EDIT — generated by gen_config.py from stack.toml
|
||||
# Re-generate: uv run python dev/scripts/gen_config.py
|
||||
|
||||
name: Lean Pay
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches: [main]
|
||||
|
||||
jobs:
|
||||
pay:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: https://github.com/actions/checkout@v4
|
||||
|
||||
- name: Detect Lean changes
|
||||
id: filter
|
||||
run: |
|
||||
set -euo pipefail
|
||||
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
|
||||
echo "pay=true" >> "$GITHUB_OUTPUT"
|
||||
exit 0
|
||||
fi
|
||||
# github.event.before misses files from a push that was cancelled
|
||||
# before this job started. workflow_dispatch above is the rerun.
|
||||
before="${{ github.event.before }}"
|
||||
changed=__all__
|
||||
if [ -n "$before" ] && [ "$before" != "0000000000000000000000000000000000000000" ]; then
|
||||
git fetch --quiet --depth=1 origin "$before" || true
|
||||
if git cat-file -e "${before}^{commit}" 2>/dev/null; then
|
||||
changed="$(git diff --name-only "$before" "$GITHUB_SHA")" || changed=__all__
|
||||
fi
|
||||
fi
|
||||
hit=false
|
||||
if [ "$changed" = __all__ ]; then
|
||||
hit=true
|
||||
else
|
||||
while IFS= read -r f; do
|
||||
[ -n "$f" ] || continue
|
||||
case "$f" in
|
||||
lean/*|.gitea/workflows/lean-pay.yml) hit=true ;;
|
||||
esac
|
||||
done <<< "$changed"
|
||||
fi
|
||||
echo "pay=$hit" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Install Lean 4.34.0 from the GitHub release
|
||||
if: steps.filter.outputs.pay == 'true'
|
||||
run: |
|
||||
set -euo pipefail
|
||||
root="$HOME/.local/lean-4.34.0-linux"
|
||||
if [ ! -x "$root/bin/lake" ]; then
|
||||
curl -fL --retry 3 -o /tmp/lean.tar.zst \
|
||||
"https://github.com/leanprover/lean4/releases/download/v4.34.0/lean-4.34.0-linux.tar.zst"
|
||||
mkdir -p "$HOME/.local"
|
||||
tar --zstd -xf /tmp/lean.tar.zst -C "$HOME/.local"
|
||||
rm -f /tmp/lean.tar.zst
|
||||
fi
|
||||
if [ ! -x "$HOME/.elan/bin/elan" ]; then
|
||||
curl -fsSL https://raw.githubusercontent.com/leanprover/elan/master/elan-init.sh \
|
||||
| sh -s -- -y --default-toolchain none
|
||||
fi
|
||||
# shellcheck disable=SC1091
|
||||
. "$HOME/.elan/env"
|
||||
echo "$HOME/.elan/bin" >> "$GITHUB_PATH"
|
||||
elan toolchain unlink "leanprover/lean4:v4.34.0" >/dev/null 2>&1 || true
|
||||
elan toolchain link "leanprover/lean4:v4.34.0" "$root"
|
||||
lean --version
|
||||
lake --version
|
||||
|
||||
- name: Typecheck Pay and compare pay-cases
|
||||
if: steps.filter.outputs.pay == 'true'
|
||||
run: |
|
||||
set -euo pipefail
|
||||
export PATH="$HOME/.elan/bin:$PATH"
|
||||
cd lean/Pay
|
||||
lake update
|
||||
lake exe cache get
|
||||
lake build
|
||||
lake exe pay-cases > /tmp/pay-cases.json
|
||||
diff -u cases.json /tmp/pay-cases.json
|
||||
|
||||
- name: File failure issue
|
||||
if: failure() && steps.filter.outputs.pay == 'true' && !startsWith(github.head_ref || github.ref_name, 'renovate/')
|
||||
env:
|
||||
GITEA_TOKEN: ${{ secrets.DEPLOY_TOKEN }}
|
||||
run: |
|
||||
py=python3
|
||||
command -v python3 >/dev/null 2>&1 || { command -v uv >/dev/null 2>&1 || curl -LsSf https://astral.sh/uv/install.sh | sh; export PATH="$HOME/.local/bin:$PATH"; py="uv run --no-project python"; }
|
||||
$py src/api/diag/ci.py \
|
||||
--workflow "Lean Pay" --job "pay" \
|
||||
--run "${{ github.run_number }}" \
|
||||
--sha "${{ github.sha }}" \
|
||||
--ref "${{ github.ref }}" || true
|
||||
- name: Close resolved issue
|
||||
if: success() && steps.filter.outputs.pay == 'true' && !startsWith(github.head_ref || github.ref_name, 'renovate/')
|
||||
env:
|
||||
GITEA_TOKEN: ${{ secrets.DEPLOY_TOKEN }}
|
||||
run: |
|
||||
py=python3
|
||||
command -v python3 >/dev/null 2>&1 || { command -v uv >/dev/null 2>&1 || curl -LsSf https://astral.sh/uv/install.sh | sh; export PATH="$HOME/.local/bin:$PATH"; py="uv run --no-project python"; }
|
||||
$py src/api/diag/ci.py \
|
||||
--close \
|
||||
--workflow "Lean Pay" --job "pay" \
|
||||
--run "${{ github.run_number }}" \
|
||||
--sha "${{ github.sha }}" \
|
||||
--ref "${{ github.ref }}" || true
|
||||
@@ -990,6 +990,123 @@ jobs:
|
||||
return (".gitea/workflows/bcda-vendor.yml", content)
|
||||
|
||||
|
||||
def _gen_lean_pay(runner: str, uv_version: str, **_kw: object) -> tuple[str, str]:
|
||||
"""Typecheck ``lean/Pay`` and fail if ``pay-cases`` drifts from ``cases.json``.
|
||||
|
||||
``releases.lean-lang.org`` times out from this network, so the job
|
||||
downloads the Lean 4.34.0 tarball from the GitHub release and links
|
||||
it with elan (``--default-toolchain none``; the init script must not
|
||||
fetch a toolchain itself). ``lake exe cache get`` supplies mathlib's
|
||||
oleans. Do not build mathlib from source.
|
||||
|
||||
Gitea Actions ignores ``paths:`` on push. Diff ``github.event.before``
|
||||
and skip the download unless ``lean/`` or this workflow changed.
|
||||
A cancelled push's files can fall out of that range; ``workflow_dispatch``
|
||||
always typechecks. A skipped push is a green job and must not close
|
||||
an open Lean Pay issue.
|
||||
"""
|
||||
gate = "!startsWith(github.head_ref || github.ref_name, 'renovate/')"
|
||||
ran = "steps.filter.outputs.pay == 'true'"
|
||||
report = f"""\
|
||||
- name: File failure issue
|
||||
if: failure() && {ran} && {gate}
|
||||
env:
|
||||
GITEA_TOKEN: ${{{{ secrets.DEPLOY_TOKEN }}}}
|
||||
run: |
|
||||
{_filer_run("Lean Pay", "pay")}
|
||||
- name: Close resolved issue
|
||||
if: success() && {ran} && {gate}
|
||||
env:
|
||||
GITEA_TOKEN: ${{{{ secrets.DEPLOY_TOKEN }}}}
|
||||
run: |
|
||||
{_filer_run("Lean Pay", "pay", close=True)}"""
|
||||
content = f"""\
|
||||
{_HEADER}
|
||||
name: Lean Pay
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches: [main]
|
||||
|
||||
jobs:
|
||||
pay:
|
||||
runs-on: {runner}
|
||||
steps:
|
||||
{_checkout_step()}
|
||||
|
||||
- name: Detect Lean changes
|
||||
id: filter
|
||||
run: |
|
||||
set -euo pipefail
|
||||
if [ "${{{{ github.event_name }}}}" = "workflow_dispatch" ]; then
|
||||
echo "pay=true" >> "$GITHUB_OUTPUT"
|
||||
exit 0
|
||||
fi
|
||||
# github.event.before misses files from a push that was cancelled
|
||||
# before this job started. workflow_dispatch above is the rerun.
|
||||
before="${{{{ github.event.before }}}}"
|
||||
changed=__all__
|
||||
if [ -n "$before" ] && [ "$before" != "{_NULL_SHA}" ]; then
|
||||
git fetch --quiet --depth=1 origin "$before" || true
|
||||
if git cat-file -e "${{before}}^{{commit}}" 2>/dev/null; then
|
||||
changed="$(git diff --name-only "$before" "$GITHUB_SHA")" || changed=__all__
|
||||
fi
|
||||
fi
|
||||
hit=false
|
||||
if [ "$changed" = __all__ ]; then
|
||||
hit=true
|
||||
else
|
||||
while IFS= read -r f; do
|
||||
[ -n "$f" ] || continue
|
||||
case "$f" in
|
||||
lean/*|.gitea/workflows/lean-pay.yml) hit=true ;;
|
||||
esac
|
||||
done <<< "$changed"
|
||||
fi
|
||||
echo "pay=$hit" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Install Lean 4.34.0 from the GitHub release
|
||||
if: {ran}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
root="$HOME/.local/lean-4.34.0-linux"
|
||||
if [ ! -x "$root/bin/lake" ]; then
|
||||
curl -fL --retry 3 -o /tmp/lean.tar.zst \\
|
||||
"https://github.com/leanprover/lean4/releases/download/v4.34.0/lean-4.34.0-linux.tar.zst"
|
||||
mkdir -p "$HOME/.local"
|
||||
tar --zstd -xf /tmp/lean.tar.zst -C "$HOME/.local"
|
||||
rm -f /tmp/lean.tar.zst
|
||||
fi
|
||||
if [ ! -x "$HOME/.elan/bin/elan" ]; then
|
||||
curl -fsSL https://raw.githubusercontent.com/leanprover/elan/master/elan-init.sh \\
|
||||
| sh -s -- -y --default-toolchain none
|
||||
fi
|
||||
# shellcheck disable=SC1091
|
||||
. "$HOME/.elan/env"
|
||||
echo "$HOME/.elan/bin" >> "$GITHUB_PATH"
|
||||
elan toolchain unlink "leanprover/lean4:v4.34.0" >/dev/null 2>&1 || true
|
||||
elan toolchain link "leanprover/lean4:v4.34.0" "$root"
|
||||
lean --version
|
||||
lake --version
|
||||
|
||||
- name: Typecheck Pay and compare pay-cases
|
||||
if: {ran}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
export PATH="$HOME/.elan/bin:$PATH"
|
||||
cd lean/Pay
|
||||
lake update
|
||||
lake exe cache get
|
||||
lake build
|
||||
lake exe pay-cases > /tmp/pay-cases.json
|
||||
diff -u cases.json /tmp/pay-cases.json
|
||||
|
||||
{report}
|
||||
"""
|
||||
return (".gitea/workflows/lean-pay.yml", content)
|
||||
|
||||
|
||||
def _gen_release(runner: str, uv_version: str, **_kw: object) -> tuple[str, str]:
|
||||
content = f"""\
|
||||
{_HEADER}
|
||||
@@ -1060,6 +1177,7 @@ def emit(
|
||||
_gen_comment_pull,
|
||||
_gen_llm_golden,
|
||||
_gen_bcda_vendor,
|
||||
_gen_lean_pay,
|
||||
_gen_release,
|
||||
):
|
||||
path, content = gen_fn(**common) # type: ignore[arg-type]
|
||||
|
||||
@@ -46,6 +46,11 @@ lake build
|
||||
lake exe pay-cases > cases.json
|
||||
```
|
||||
|
||||
`.gitea/workflows/lean-pay.yml` runs that check when `lean/` or the
|
||||
workflow file changes. The runner downloads Lean 4.34.0 from the GitHub
|
||||
release (`releases.lean-lang.org` times out from this network) and uses
|
||||
the mathlib olean cache.
|
||||
|
||||
`tests/pay/test_ceiling.py` runs the Python functions on these inputs
|
||||
and requires the rationals in `cases.json`. When `lake` is on `PATH` it
|
||||
also requires `pay-cases` to reprint that file.
|
||||
|
||||
69
tests/dev/test_gen_config_lean_pay.py
Normal file
69
tests/dev/test_gen_config_lean_pay.py
Normal file
@@ -0,0 +1,69 @@
|
||||
"""The Lean Pay typecheck is emitted by the Gitea backend.
|
||||
|
||||
Gitea Actions ignores ``paths:`` filters on push, so the job itself
|
||||
diffs ``github.event.before`` and skips the toolchain unless ``lean/``
|
||||
or this workflow changed. ``workflow_dispatch`` always typechecks.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
sys.path.insert(0, str(ROOT / "dev" / "scripts"))
|
||||
|
||||
from backends import gitea # noqa: E402
|
||||
|
||||
|
||||
def test_lean_pay_workflow() -> None:
|
||||
path, content = gitea._gen_lean_pay(runner="ubuntu-latest", uv_version="0.5")
|
||||
assert path == ".gitea/workflows/lean-pay.yml"
|
||||
assert "name: Lean Pay" in content
|
||||
assert "workflow_dispatch:" in content
|
||||
assert "branches: [main]" in content
|
||||
assert "schedule:" not in content
|
||||
assert "releases.lean-lang.org" not in content
|
||||
assert (
|
||||
"https://github.com/leanprover/lean4/releases/download/"
|
||||
"v4.34.0/lean-4.34.0-linux.tar.zst"
|
||||
) in content
|
||||
assert "--default-toolchain none" in content
|
||||
assert 'elan toolchain link "leanprover/lean4:v4.34.0"' in content
|
||||
assert "lake update" in content
|
||||
assert "lake exe cache get" in content
|
||||
assert "lake build" in content
|
||||
assert "lake exe pay-cases" in content
|
||||
assert "diff -u cases.json" in content
|
||||
assert "github.event.before" in content
|
||||
assert "lean/*" in content
|
||||
assert ".gitea/workflows/lean-pay.yml" in content
|
||||
assert "steps.filter.outputs.pay == 'true'" in content
|
||||
# A skipped push is a green job. It must not close a real Lean Pay issue.
|
||||
close = next(
|
||||
line
|
||||
for line in content.splitlines()
|
||||
if line.strip().startswith("if:")
|
||||
and "Close" not in line
|
||||
and "success()" in line
|
||||
)
|
||||
assert "steps.filter.outputs.pay == 'true'" in close
|
||||
assert '--workflow "Lean Pay" --job "pay"' in content
|
||||
|
||||
|
||||
def test_emitted_with_the_others() -> None:
|
||||
files = gitea.emit(
|
||||
images=[],
|
||||
scans=[],
|
||||
platform={
|
||||
"registry": "r",
|
||||
"domain": "d",
|
||||
"host_ip": "1.1.1.1",
|
||||
"image_prefix": "p",
|
||||
"repo": "o/n",
|
||||
},
|
||||
ci_cfg={"runner": "ubuntu-latest", "registry": "r", "uv_version": "0.5"},
|
||||
)
|
||||
assert ".gitea/workflows/lean-pay.yml" in files
|
||||
committed = (ROOT / ".gitea" / "workflows" / "lean-pay.yml").read_text()
|
||||
assert committed == files[".gitea/workflows/lean-pay.yml"]
|
||||
Reference in New Issue
Block a user