Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Tests on every pull request and push to main; the Linux, Windows and macOS builds
# and a GitHub Release with the AppImage, the Windows .exe, the macOS .dmg and a source archive for every tag
# v<version> (matching "version" in src-tauri/tauri.conf.json). Running the
# v<version> (the version comes from the tag: tools/set_version.py writes it in). Running the
# workflow by hand (workflow_dispatch) builds all three without releasing: do that
# before tagging, since merges no longer build.
#
Expand Down Expand Up @@ -123,14 +123,12 @@ jobs:
- name: Install Tauri CLI
run: cargo install tauri-cli --version "^2" --locked

- name: Check the tag matches the app version
# A release's version is its tag's (v0.2.0 → 0.2.0), written into
# tauri.conf.json, Cargo.toml and Cargo.lock before building: nothing to
# bump by hand. A tag that isn't v<major>.<minor>.<patch> fails here.
- name: Set the version from the tag
if: startsWith(github.ref, 'refs/tags/v')
run: |
version=$(python3 -c "import json; print(json.load(open('src-tauri/tauri.conf.json'))['version'])")
if [ "v$version" != "$GITHUB_REF_NAME" ]; then
echo "::error::tag $GITHUB_REF_NAME doesn't match version $version in src-tauri/tauri.conf.json"
exit 1
fi
run: python3 tools/set_version.py "$GITHUB_REF_NAME"

- name: Build the AppImage
env:
Expand Down Expand Up @@ -177,6 +175,11 @@ jobs:
- name: Install Tauri CLI
run: cargo install tauri-cli --version "^2" --locked

- name: Set the version from the tag
if: startsWith(github.ref, 'refs/tags/v')
shell: bash
run: python tools/set_version.py "$GITHUB_REF_NAME"

- name: Build the app
env:
KIVI_GITHUB_CLIENT_ID: ${{ vars.KIVI_GITHUB_CLIENT_ID }}
Expand Down Expand Up @@ -229,6 +232,10 @@ jobs:
- name: Install Tauri CLI
run: cargo install tauri-cli --version "^2" --locked

- name: Set the version from the tag
if: startsWith(github.ref, 'refs/tags/v')
run: python3 tools/set_version.py "$GITHUB_REF_NAME"

- name: Build the .dmg
env:
KIVI_GITHUB_CLIENT_ID: ${{ vars.KIVI_GITHUB_CLIENT_ID }}
Expand Down Expand Up @@ -263,12 +270,17 @@ jobs:
- uses: actions/checkout@v4
with:
path: src
# With the tag's version written in, like the binaries: `git stash create`
# makes a commit of the tagged tree plus that change, without touching
# any branch, and the archive is made from it.
- name: Source archive
run: |
version="${GITHUB_REF_NAME#v}"
python3 src/tools/set_version.py "$GITHUB_REF_NAME"
tree=$(git -C src -c user.name=KiVi -c user.email=ci@localhost stash create)
mkdir -p bundles/source
git -C src archive --format=tar.gz --prefix="KiVi-${version}/" \
-o "$PWD/bundles/source/KiVi_${version}_source.tar.gz" HEAD
-o "$PWD/bundles/source/KiVi_${version}_source.tar.gz" "${tree:-HEAD}"

- uses: softprops/action-gh-release@v2
with:
Expand Down
6 changes: 5 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,11 @@ tests/smoke.sh # pages load cleanly, viewer opens
with a hint if they're missing. This machine's connection is slow
(~0.2 MB/s): a full fetch takes ~6 min here.
- CI is `.github/workflows/ci.yml` (see README): tests and Rust tests (with the notices check) on PRs and main → Linux, Windows and macOS builds (artifacts; tags and manual runs only, the user's choice to save Actions minutes on the private repo)
→ GitHub Release on `v*` tags. Keep its commands in sync with this list;
→ GitHub Release on `v*` tags. The release version is the tag's (the user's
choice): every build job and the source archive run `tools/set_version.py
<tag>` first (tauri.conf.json, Cargo.toml [package], the kivi-desktop entry
of Cargo.lock); the files in the repository aren't bumped and only matter for
local and manual builds. Keep its commands in sync with this list;
it was written without a way to run it locally (no act/actionlint here), so
the first run on GitHub is its real test.
- `kicad-cli` (KiCad's own SVG export, for `tools/compare.py`) is the one
Expand Down
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -454,11 +454,16 @@ ok diff
`KiVi_<version>_universal.dmg` (Apple Silicon and Intel; `LICENSE` and
`THIRD-PARTY-NOTICES.md` are inside the app). Not code-signed or notarised.

Pushing a tag `v<version>` (matching `version` in `src-tauri/tauri.conf.json`,
checked) runs all five and publishes a GitHub Release with the AppImage, the
Pushing a tag `v<version>` (for example `v0.2.0`) runs all five and publishes a
GitHub Release. The version comes from the tag: each build first runs
`tools/set_version.py`, which writes it into `src-tauri/tauri.conf.json`,
`src-tauri/Cargo.toml` and `src-tauri/Cargo.lock`, so there's nothing to bump
by hand (the versions in the repository are only for local and manual builds;
a tag that isn't `v<major>.<minor>.<patch>`, optionally with `-beta.1` and the
like, fails the build). The release has the AppImage, the
Windows `.exe`, the macOS `.dmg`, `LICENSE`, `THIRD-PARTY-NOTICES.md`,
`appimage-libraries.md` and `KiVi_<version>_source.tar.gz` (`git archive` of
the tag). Merges don't build, so run the workflow by hand on `main` before
the tag, with the version written in). Merges don't build, so run the workflow by hand on `main` before
tagging and check all three builds pass.

## Licence
Expand Down
66 changes: 66 additions & 0 deletions tools/set_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env python3
"""Set KiVi's version everywhere it's written down.

python3 tools/set_version.py v0.2.0 # or 0.2.0

A release takes its version from the tag: CI runs this with the pushed tag
(`v0.2.0`) before building, so the AppImage, the .exe, the .dmg and the source
archive all carry it, and nobody has to bump the files by hand first. The
files in the repository keep whatever version they have; it's only used for
local and manual builds.

It changes, keeping everything else as it is:
src-tauri/tauri.conf.json "version" (the app, bundle and file names)
src-tauri/Cargo.toml [package] version
src-tauri/Cargo.lock the kivi-desktop entry (so a --locked build agrees)
"""
import re
import sys
from pathlib import Path

ROOT = Path(__file__).resolve().parent.parent
# Semantic versions, as Tauri and Cargo accept them: 1.2.3, or 1.2.3-beta.1.
VERSION = re.compile(r"^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$")

# (file, pattern whose group 2 is the version, what it is)
PLACES = [
("src-tauri/tauri.conf.json", re.compile(r'^(\s*"version"\s*:\s*")([^"]*)(")', re.M), "tauri.conf.json version"),
("src-tauri/Cargo.toml", re.compile(r'(\[package\][^\[]*?^version\s*=\s*")([^"]*)(")', re.M | re.S), "Cargo.toml [package] version"),
("src-tauri/Cargo.lock", re.compile(r'(^name = "kivi-desktop"\nversion = ")([^"]*)(")', re.M), "Cargo.lock kivi-desktop entry"),
]


def set_version(version: str, root: Path = ROOT) -> list[str]:
"""Write `version` into every place; returns what changed. Raises ValueError for a bad version or a place not found."""
version = version.strip().removeprefix("v")
if not VERSION.match(version):
raise ValueError(f'"{version}" isn\'t a version like 1.2.3 (tags are v1.2.3)')
changed = []
for rel, pattern, what in PLACES:
path = root / rel
text = path.read_text(encoding="utf-8")
m = pattern.search(text)
if not m:
raise ValueError(f"no {what} found in {rel}")
if m.group(2) != version:
changed.append(f"{what}: {m.group(2)} → {version}")
text = text[: m.start(2)] + version + text[m.end(2) :]
path.write_text(text, encoding="utf-8")
return changed


def main() -> int:
if len(sys.argv) != 2:
print(__doc__.strip().splitlines()[2].strip(), file=sys.stderr)
return 2
try:
changed = set_version(sys.argv[1])
except ValueError as e:
print(f"set_version: {e}", file=sys.stderr)
return 1
print("\n".join(changed) if changed else "already that version")
return 0


if __name__ == "__main__":
sys.exit(main())
Loading