Pin the dependencies in Pharo Metacello baselines to commit SHAs, and lock the whole dependency tree
# pharo-metacello-pin A library and CLI that pins the dependencies in Pharo Metacello baselines to commit SHAs. ## The problem A Metacello baseline names each dependency by branch or tag, or by nothing at all, which means the default branch. For example, `BaselineOfAWS` in [aws-sdk-smalltalk](https://github.com/newapplesho/aws-sdk-smalltalk): ```smalltalk spec baseline: 'NeoJSON' with: [ spec repository: 'github://svenvc/NeoJSON/repository' ]. spec baseline: 'XMLParser' with: [ spec repository: 'github://pharo-contributions/XML-XMLParser:master/src' ]. ``` A branch moves with every push, and a tag can be moved or deleted. The same baseline can therefore load different code on different days. Builds are hard to reproduce, and a bad push upstream (a mistake, or a compromised account) ends up in your image even though you changed nothing. The baselines of your dependencies have the same problem, and you cannot edit them. ## The solution `metacello-pin` rewrites each reference to the commit SHA it points at now, and keeps the original ref as a comment: ```smalltalk spec baseline: 'NeoJSON' with: [ spec repository: 'github://svenvc/NeoJSON:11e274dd96dc9636cab90929937b7cd09719de7c/repository' "master" ]. spec baseline: 'XMLParser' with: [ spec repository: 'github://pharo-contributions/XML-XMLParser:26a888381174c154b02e908f27d9d5eead3d04ec/src' "master" ]. ``` `metacello-pin` replaces only the string, so the rest of the method keeps its formatting. `pin` cannot change the baselines of your dependencies, which name their own dependencies by branch or tag. For those, `metacello-pin lock` writes a Metacello script. The script locks every project in the dependency tree at a commit SHA, then loads them. `metacello-pin check` exits with status 1 if any reference is not pinned, so you can run it in CI. ### pin or lock? | | `pin` | `lock` | |---|---|---| | What it changes | Your `BaselineOf*` sources, in place | Nothing; it writes a separate script | | Which dependencies | The ones your baseline names directly | The whole tree, dependencies of dependencies included | | Who gets the fixed versions | Everyone who loads your project | Only an image where the script is evaluated | | To update | Edit the SHA, or set the ref back and pin again | Run `lock` again | Use `pin` for a library: people who load it get the same direct dependencies you tested. Use `lock` where you build an image yourself, such as CI or an application, to fix every dependency in the tree. The two work together: `lock` reuses the SHAs that `pin` wrote. The lock script loads each dependency's default group, even when your baseline asks for fewer packages with `loads:` (see [ROADMAP.md](ROADMAP.md)). ## Install Load it with Metacello: ```smalltalk Metacello new baseline: 'MetacelloPin'; repository: 'github://newapplesho/pharo-metacello-pin/src'; load. ``` The baseline has four groups: `Core` (the core and the CLI), `GUI`, `Tests` and `default` (everything). ## CLI ```sh ./pharo Pharo.image metacello-pin check src # list references; exit 1 if any is unpinned ./pharo Pharo.image metacello-pin pin src # rewrite BaselineOf*/*.class.st in place ./pharo Pharo.image metacello-pin lock src --output metacello.lock.st ``` Set `GITHUB_TOKEN` to avoid the GitHub API rate limit. ## Lock file The file that `lock` writes is Smalltalk code: Metacello statements that lock and load each dependency. No tool reads it; you run it in Pharo with `CodeImporter evaluateFileNamed:`. This is the output for aws-sdk-smalltalk, shortened: ```smalltalk "Generated by metacello-pin. Do not edit by hand. Evaluate this script, then load the project as usual." "WARNING: not locked: BaselineOfAWS>>baseline: Cryptography (repository scheme not supported: http://smalltalkhub.com/mc/Cryptography/Cryptography/main)" "1. Lock every baseline at its commit." Metacello new baseline: 'BitmapCharacterSet'; repository: 'github://pharo-contributions/BitmapCharacterSet:62ee106d7960646fa5b85577fe83f920a6bb6672/src' "v1.2.x, required by XMLParser"; lock. ... "2. Load them, dependencies first." Metacello new baseline: 'BitmapCharacterSet'; repository: 'github://pharo-contributions/BitmapCharacterSet:62ee106d7960646fa5b85577fe83f920a6bb6672/src' "v1.2.x, required by XMLParser"; load. ... ``` - The file starts with a header comment. A `WARNING` comment follows for each dependency that `lock` could not lock, here a smalltalkhub repository. The script does not fix those dependencies, so Metacello loads them from wherever their baselines point. - Section 1 locks every baseline in the dependency tree. Section 2 loads the same baselines, each dependency before the projects that need it. - Each statement gives the baseline name and its repository, with the ref replaced by a commit SHA. The comment after it shows the original ref and the baseline that required it. `root` means your own baseline, and `pinned` means the reference was already a SHA. The script also loads the baselines, because Metacello skips a locked project that has not been loaded yet. Evaluate the script, then load your project as usual. In the example below, replace `MyProject` and its repository with your own: ```smalltalk CodeImporter evaluateFileNamed: 'metacello.lock.st'. Metacello new baseline: 'MyProject'; repository: 'github://me/my-project/src'; load. ``` Loading your project does not replace the locked versions, even when a dependency asks for another version of a locked project (see [docs/verification.md](docs/verification.md#lock)). ## GUI Open it from the World menu (Library > Metacello Pin) or with `MPinPresenter new open`. - The left side lists every `BaselineOf*` class in the image. You can filter the list. - The right side shows the repository references of the selected baseline, each with its status, such as `unpinned`, `pinned` or `unsupported`. The line under the table counts them by status and says what to do next. If the baseline has no `repository:` reference, the line says so. - The Pin button recompiles the baseline in the image. Commit the change with Iceberg afterwards. - The Lock button shows the lock script for the selected baseline's dependency tree in the pane below. It does not write a file. The label above the script says whether it has been saved, and the Save... button writes it to a file that you choose. - Pin is enabled only when the selected baseline has a reference to pin, and Lock only when it has at least one reference. ## Development [docs/development.md](docs/development.md) describes the local setup (`make setup`, `load`, `test`), how to follow the code in the debugger, and the CI. ## Documentation - [docs/architecture.md](docs/architecture.md): how the code is organized, with diagrams - [docs/security.md](docs/security.md): trust boundaries and countermeasures - [docs/verification.md](docs/verification.md): what was checked by hand, and what was not - [ROADMAP.md](ROADMAP.md): what is done and what is planned ## License MIT. See [LICENSE](LICENSE).