# Releasing a bundle and building the installer

"Releasing" a bundle version means freezing it: recording its checksum and git commit in `released.json`, because from then on a real database may carry it. Delphi installers ship **only released versions**.

[![Release order](https://docs.improvize.eu/uploads/images/gallery/2026-11/d4-release.png)](https://docs.improvize.eu/uploads/images/gallery/2026-11/d4-release.png)

## Checklist

### On the Linux host

1. **Version bumped**: `lesage/sql/version` is above the last entry of `lesage/released.json` (same for `common` if you changed it). New steps are named `NNNN-*.sql` with that number.
2. **Everything passes**: ```bash
    cd ~/dev/improvize/common
    export PGHOST=/var/run/postgresql
    npm run check -- all
    ```
3. **Commit the bundle** (and `functions.list`, `data/`) and push. `check release` refuses a bundle folder with uncommitted changes, and records the current `HEAD`. ```bash
    cd ~/dev/improvize/lesage
    git add sql data-src && git commit -m "feat(sql): …" && git push
    ```
4. **Release**: runs lint and apply again, then writes the new entry in each `released.json` whose version is new (an already released version is just reported). ```bash
    cd ~/dev/improvize/common
    npm run check -- release sql ../lesage/sql
    ```
    
    Last line expected: `lesage: released version N sha256:… at <commit> — commit released.json`.
5. **Commit `released.json`** in each repo it touched, and push: ```bash
    cd ~/dev/improvize/lesage
    git add released.json && git commit -m "chore(release): lesage bundle version 2" && git push
    ```
    
    The lesage-web commit hook runs prettier on `released.json` and reflows it: harmless, the lint compares the values only (`node scripts/lint-bundles.mjs` still says `ok`). If `common` was released too: same in `~/dev/improvize/common`, and tag it (`v1.x.y`) when the web apps must pick it up (they pin `improvize-db-bundles#semver:^1.0.0`, then `npm update improvize-db-bundles`).

### In the Windows VM

6. **Compile `Sage.exe`** with its new exe version (`versionprefix.txt` → `genversion.cmd`, which writes `version.RES` and the `version.ini` the `.iss` reads).
7. **Compile `LeSage13.iss`**. It copies `Z:\dev\improvize\common\sql\*` → `{app}\common\sql` and `Z:\dev\improvize\lesage\sql\*` → `{app}\lesage\sql`, after wiping both folders (`[InstallDelete]`) so no stale file survives. Output: `K:\Dev\Delphi\Sage13\Le Sage 13.000.xx.exe`.

### Back on the host

8. **Publish**: `./deployupdate.sh "Le Sage 13.000.xx.exe"` in `Sage13/` (Mercurial commit + push, upload to `…/lesage/program/v13/`, `makelatest.pl`, announcement mail).

## Why the bundle comes first

- The `.iss` does no check at all: it packs whatever is in the two folders at compile time. If you compile it while you have uncommitted or unreleased SQL there, that SQL goes to clients and becomes a version nobody can reproduce.
- Before step 7: `git -C ~/dev/improvize/lesage status sql` and `git -C ~/dev/improvize/common status sql` must be clean.
- The exe has no bundle version compiled in. Compiling `Sage.exe` before the release is fine; **packaging** before it is not.

## Common situations

<table id="bkmrk-situationdo-exe-only"><thead><tr><th>Situation</th><th>Do</th></tr></thead><tbody><tr><td>Exe-only fix, no SQL change</td><td>No release. Bundles are already at a released commit; just steps 6–8.</td></tr><tr><td>Bug in a released version N</td><td>Never edit N. Bump to N+1 and fix it with a new step or a corrected function.</td></tr><tr><td>`check release` says "uncommitted changes in the bundle folder"</td><td>Commit (or stash) first: it records the commit, so the folder must match it.</td></tr><tr><td>Lint: `released` rule fails</td><td>You changed a released version's content without bumping `version`.</td></tr><tr><td>Changed only `common`</td><td>Release `common`, then rebuild the installer of **every** product (Le Sage, Inpro, Aïda): each ships its own copy.</td></tr></tbody></table>

<p class="callout warning">Never put a 13 exe in `program/v12/`: `makelatest.pl` would offer it to every 12.x, ready database or not. 13 goes in `v13/` only.</p>