diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a24fbb7..c874dc9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -17,19 +17,33 @@ Use the latest version of Rust. ## Release Commands assume you are using [Git Bash](https://git-scm.com) on Windows: -* Add targets: - * 32-bit: `rustup target add i686-pc-windows-msvc` - * 64-bit: `rustup target add x86_64-pc-windows-msvc` -* Install tool for generating license bundle: - * `cargo install cargo-lichking` -* Prepare release: - ``` - export VERSION=$(cargo pkgid | cut -d# -f2 | cut -d: -f2) - rm -rf dist - mkdir dist - cargo build --release --target i686-pc-windows-msvc - cargo build --release --target x86_64-pc-windows-msvc - cp target/i686-pc-windows-msvc/release/shawl.exe dist/shawl-v$VERSION-win32.exe - cp target/x86_64-pc-windows-msvc/release/shawl.exe dist/shawl-v$VERSION-win64.exe - cargo lichking bundle --file dist/shawl-v$VERSION-legal.txt - ``` +### Dependencies (one-time) +```bash +pip install invoke +cargo install cargo-lichking +``` + +### Process +* Update version in `CHANGELOG.md` +* Update version in `Cargo.toml` +* Run `invoke prerelease` +* Run `git add` for all relevant changes +* Run `invoke release` + * This will create a new commit/tag and push them. + * Manually create a release on GitHub and attach the workflow build artifacts + (plus `dist/*-legal.zip`). +* Run `cargo publish` +* Run `invoke release-winget` + * When the script opens VSCode and pauses, + manually edit `manifests/m/mtkennerly/shawl/${VERSION}/mtkennerly.shawl.locale.en-US.yaml` + to add the `ReleaseNotes` and `ReleaseNotesUrl` fields: + + ```yaml + ReleaseNotes: |- + + ReleaseNotesUrl: https://github.com/mtkennerly/shawl/releases/tag/v${VERSION} + ``` + + Close the file, and the script will continue. + * This will automatically push a branch to a fork of https://github.com/microsoft/winget-pkgs . + * Manually open a pull request for that branch. diff --git a/tasks.py b/tasks.py index 4f7d5da..126c1df 100644 --- a/tasks.py +++ b/tasks.py @@ -1,9 +1,44 @@ +import re import shutil +import zipfile from pathlib import Path import tomli from invoke import task +ROOT = Path(__file__).parent +DIST = ROOT / "dist" + + +def get_version() -> str: + manifest = ROOT / "Cargo.toml" + return tomli.loads(manifest.read_bytes().decode("utf-8"))["package"]["version"] + + +@task +def clean(ctx): + if DIST.exists(): + shutil.rmtree(DIST, ignore_errors=True) + DIST.mkdir() + + +@task +def legal(ctx): + version = get_version() + txt_name = f"shawl-v{version}-legal.txt" + txt_path = DIST / txt_name + try: + ctx.run(f'cargo lichking bundle --file "{txt_path}"', hide=True) + except Exception: + pass + raw = txt_path.read_text("utf8") + normalized = re.sub(r"C:\\Users\\[^\\]+", "~", raw) + txt_path.write_text(normalized, "utf8") + + zip_path = DIST / f"shawl-v{version}-legal.zip" + with zipfile.ZipFile(zip_path, "w", zipfile.ZIP_DEFLATED) as zip: + zip.write(txt_path, txt_name) + @task def docs(ctx): @@ -37,17 +72,36 @@ def docs(ctx): @task -def release(ctx): - dist = Path("dist") - if dist.exists(): - shutil.rmtree(dist) - dist.mkdir() - +def prerelease(ctx): # Make sure that the lock file has the new version ctx.run("cargo build") + clean(ctx) + legal(ctx) docs(ctx) - manifest = Path("Cargo.toml") - version = tomli.loads(manifest.read_bytes().decode("utf-8"))["package"]["version"] - ctx.run(f"cargo lichking bundle --file dist/shawl-v{version}-legal.txt") + +@task +def release(ctx): + version = get_version() + ctx.run(f'git commit -m "Release v{version}"') + ctx.run(f'git tag v{version} -m "Release"') + ctx.run("git push") + ctx.run("git push --tags") + + +@task +def release_winget(ctx, target="/git/_forks/winget-pkgs"): + target = Path(target) + version = get_version() + + with ctx.cd(target): + ctx.run("git checkout master") + ctx.run("git pull upstream master") + ctx.run(f"git checkout -b mtkennerly.shawl-{version}") + ctx.run(f"wingetcreate update mtkennerly.shawl --version {version} --urls https://github.com/mtkennerly/shawl/releases/download/v{version}/shawl-v{version}-win64.zip https://github.com/mtkennerly/shawl/releases/download/v{version}/shawl-v{version}-win32.zip") + ctx.run(f"code --wait manifests/m/mtkennerly/shawl/{version}/mtkennerly.shawl.locale.en-US.yaml") + ctx.run(f"winget validate --manifest manifests/m/mtkennerly/shawl/{version}") + ctx.run("git add .") + ctx.run(f'git commit -m "mtkennerly.shawl version {version}"') + ctx.run("git push origin HEAD")