Repository navigation
67 lines (57 loc) · 1.94 KB
/
Copy pathversion-guard.yml
File metadata and controls
67 lines (57 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
name: Version Guard
on:
pull_request:
branches:
- main
push:
branches:
- main
workflow_dispatch:
permissions:
contents: read
jobs:
block-1-0:
name: Block automatic 1.0 releases
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Reject versions at or above 1.0.0
run: |
python - <<'PY'
import sys
import tomllib
from pathlib import Path
with open("pyproject.toml", "rb") as pyproject:
project = tomllib.load(pyproject)["project"]
version = project["version"]
cli_dependency = next(
item for item in project["dependencies"] if item.startswith("sqlclean-cli==")
).partition("==")[2]
with Path("packages/sqlclean-cli/pyproject.toml").open("rb") as pyproject:
cli_package_version = tomllib.load(pyproject)["project"]["version"]
with Path("Cargo.toml").open("rb") as cargo:
workspace_version = tomllib.load(cargo)["workspace"]["package"]["version"]
versions = {
version,
cli_dependency,
cli_package_version,
workspace_version,
}
if len(versions) != 1:
print(f"SQLClean package versions are not locked: {sorted(versions)}", file=sys.stderr)
sys.exit(1)
parts = version.split(".")
try:
major = int(parts[0])
except (IndexError, ValueError):
print(f"Invalid project version: {version}", file=sys.stderr)
sys.exit(1)
if major >= 1:
print(
f"Refusing automatic release version {version}. "
"Crossing to 1.0.0 requires an explicit manual decision.",
file=sys.stderr,
)
sys.exit(1)
print(f"Project version {version} is below 1.0.0.")
PY