Skip to content

Commit 865103f

Browse files
committed
attempting version-checking guard
1 parent f974dc4 commit 865103f

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

.github/workflows/release.yml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,87 @@ env:
99
BIN_NAME: mnemonic-hasher
1010

1111
jobs:
12+
version-check:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Verify versions match tag
21+
run: |
22+
python - <<'PY'
23+
import json, os, sys, re, pathlib
24+
try:
25+
import tomllib # Python 3.11+ on ubuntu-latest
26+
except Exception as e:
27+
print("Python >=3.11 required for tomllib", file=sys.stderr)
28+
sys.exit(2)
29+
30+
tag = os.environ.get("GITHUB_REF_NAME","")
31+
if not tag:
32+
print("GITHUB_REF_NAME not set; are we on a tag ref?", file=sys.stderr)
33+
sys.exit(2)
34+
35+
# Accept tags like v1.2.3 or 1.2.3 (keeps the numeric part)
36+
m = re.fullmatch(r'v?(\d+\.\d+\.\d+(?:[-+].*)?)', tag)
37+
if not m:
38+
print(f"Tag '{tag}' doesn't look like a semver (vMAJOR.MINOR.PATCH[prerelease+build])", file=sys.stderr)
39+
sys.exit(2)
40+
tagver = m.group(1)
41+
42+
root = pathlib.Path(".")
43+
errors = []
44+
45+
# package.json
46+
pkg_path = root / "package.json"
47+
try:
48+
pkgver = json.loads(pkg_path.read_text())["version"]
49+
except Exception as e:
50+
print(f"Failed reading version from {pkg_path}: {e}", file=sys.stderr); sys.exit(2)
51+
52+
# tauri.conf.json (either at repo root or under src-tauri/)
53+
tauri_path = root / "tauri.conf.json"
54+
if not tauri_path.exists():
55+
tauri_path = root / "src-tauri" / "tauri.conf.json"
56+
try:
57+
tauri = json.loads(tauri_path.read_text())
58+
# Tauri can store version at package.version or top-level version
59+
tauriver = (tauri.get("package") or {}).get("version") or tauri.get("version")
60+
except Exception as e:
61+
print(f"Failed reading version from {tauri_path}: {e}", file=sys.stderr); sys.exit(2)
62+
63+
# src-tauri/Cargo.toml (typical Tauri layout)
64+
cargo_path = root / "src-tauri" / "Cargo.toml"
65+
try:
66+
cargover = tomllib.loads(cargo_path.read_text())["package"]["version"]
67+
except Exception as e:
68+
print(f"Failed reading version from {cargo_path}: {e}", file=sys.stderr); sys.exit(2)
69+
70+
# Report and compare
71+
print(f"git tag : {tagver}")
72+
print(f"package.json : {pkgver}")
73+
print(f"Cargo.toml : {cargover}")
74+
print(f"tauri.conf.json: {tauriver}")
75+
76+
mismatches = []
77+
for name, v in [("package.json", pkgver), ("Cargo.toml", cargover), ("tauri.conf.json", tauriver)]:
78+
if v != tagver:
79+
mismatches.append((name, v))
80+
81+
if mismatches:
82+
print("\nVersion mismatch detected:", file=sys.stderr)
83+
for n, v in mismatches:
84+
print(f" - {n}: {v} != {tagver}", file=sys.stderr)
85+
sys.exit(1)
86+
else:
87+
print("\nAll versions match the tag.")
88+
PY
89+
1290
build:
1391
name: build (${{ matrix.target }})
92+
needs: version-check
1493
runs-on: ${{ matrix.os }}
1594
strategy:
1695
fail-fast: false

0 commit comments

Comments
 (0)