Files
Nemera/docs/technical/RELEASING.md

197 lines
23 KiB
Markdown

# Releasing
## Contents
- [Overview](#overview)
- [Required GitHub settings](#required-github-settings)
- [Release branch ruleset](#release-branch-ruleset)
- [Release environment](#release-environment)
- [Secrets](#secrets)
- [Workflows](#workflows)
- [Cutting a release](#cutting-a-release)
- [Revoking a bundled plugin hash](#revoking-a-bundled-plugin-hash)
- [Rotating credentials](#rotating-credentials)
- [Troubleshooting](#troubleshooting)
## Overview
Releases are cut only by the repository owner. There is one official build, and it runs on the release branch.
1. The owner creates a `release/x.y.z` branch from `master`.
2. The `Publish Release` workflow builds and publishes the official artifacts with `OfficialReleaseBuild=true`.
3. The same workflow verifies the embedded plugin manifest against every published API folder, records the release's plugin hashes in the append-only trust list, builds the release images from the verified publish output, and opens a pull request to `master`.
4. The owner downloads the release archives and creates the GitHub release and tag.
5. The owner merges the trust-list pull request. The current release already embeds its own official plugin manifest, so this pull request keeps the release's plugin binaries Official in future releases.
The full test suite runs on normal pull requests to `master`. The release build does not rerun the full suite. It runs the manifest verification tests for the official build, publishes, verifies the embedded plugin manifest against every published API folder, checks the native folders and files of every runtime, verifies every archive against its publish folder, records the hashes and builds the release images from the verified publish output.
The repository pins the .NET SDK in `global.json`. The workflows install that exact SDK, and the Docker build stage uses the matching `10.0.100` SDK image, so root-level and container builds use the same toolchain.
The `Publish` target produces two archives for each supported runtime identifier: an API archive and a web archive. The names are `Nemera-<version>-<platform>-<architecture>-api.<extension>` and `Nemera-<version>-<platform>-<architecture>-web.<extension>`, for example `Nemera-1.2.3-linux-x64-web.tar.gz` and `Nemera-1.2.3-windows-x64-api.zip`. Windows archives are `.zip` files; Linux and macOS archives are `.tar.gz` files, so the executable permission survives the download. Each archive contains the application files, the native apphost and the native libraries for that runtime identifier only. The supported runtime identifiers are `linux-x64`, `linux-arm64`, `linux-musl-x64`, `osx-x64`, `osx-arm64`, `win-x64`, `win-x86` and `win-arm64`, and the workflow builds them all on `ubuntu-latest`. The API archive also contains the bundled plugins, so the API can run directly from the extracted folder. The plugin deployment copies only the native runtime folders the catalog declares for that runtime: the identifier's own folder and the shared `osx` folder for the macOS archives, so the PDF plugin's native libraries for the other operating systems are not shipped. The macOS archives keep their shared SkiaSharp library in the `osx` fallback folder, which the build retains automatically even though no device reports that identifier. The runtime list is defined by the `BundledPluginRuntime` items and the native folder mapping by `BundledPluginRuntimeDirectory` in `build/RuntimeIdentifiers.props`. The catalog must list exactly the folders the bundled plugins deploy: verification fails when the staging folder is missing a declared folder or contains an undeclared one, and each release must contain exactly the folders declared for its runtime identifier. The PDF plugin validates its required native libraries for every identifier in it, accepting a library from either the identifier's own folder or its OS family fallback. The plugin resolves the matching native library at runtime from its dependency manifest. Verification runs the embedded manifest test against every published API folder, requires exactly the declared native runtime folders and their files, and extracts every archive to compare its contents and hashes with the publish folder it was built from. The trust list records the published plugin hashes from the verified `linux-x64` folder; every other runtime folder is verified against the same embedded manifest and its plugin binaries are compared with that reference folder, so the recorded hashes describe every shipped platform. The publish output excludes `.pdb` files. The API listens on `http://localhost:5214` and the web client on `http://localhost:5012` by default. The `Publish Release` workflow builds the release images from the `linux-x64` publish folders to validate the image definitions, and does not upload them. The images you ship are built manually from the extracted `Nemera-<version>-linux-x64-api` and `Nemera-<version>-linux-x64-web` archives with `--platform linux/amd64`, or from the `linux-arm64` archives with `--platform linux/arm64`; the `linux-musl-x64` archives cannot be used with these images, because their base image is a glibc distribution. The Linux and macOS archives must be created on Linux or macOS, because Windows cannot store the executable bit in a tar archive: `Publish` on Windows creates only the Windows archives and warns that the others were skipped.
`Publish` restores the API and web projects once for all supported runtimes and publishes each runtime with `--no-restore`, so the projects keep a multi-RID assets file. The restore reads the runtime list from an environment variable set only for that command, so normal builds are unaffected.
The presentation host does not compile against the concrete plugin projects, and it does not own the bundled plugin catalog. The plugin projects are part of the solution and copy their outputs to the API plugin folder. `build.proj` owns the release catalog: it builds and hashes the plugin binaries, writes the current manifest, passes that manifest to the API publish, and copies the binaries into the published plugin folder. Adding or removing a bundled plugin changes the release catalog and the solution, not the host project.
## Required GitHub settings
### Release branch ruleset
Create a repository ruleset under **Settings > Rules > Rulesets > New branch ruleset**:
- Target branches: `refs/heads/release/*`.
- Enable **Restrict creations**, **Restrict updates**, **Restrict deletions**, and **Block force pushes**.
- Bypass list: add only the owner's user account. Do not add the repository admin role if more than one administrator exists.
This prevents write collaborators from creating or pushing release branches. The ruleset enforces who can create the branch. The owner can create it from the GitHub Branches page or by pushing it.
The `Publish Release` workflow runs only when a branch matching `release/x.y.z` is created, and only when the actor is the repository owner.
### Release environment
Create an environment under **Settings > Environments > New environment** named `release`:
- Required reviewers: the owner.
- Deployment branches: allow `master` and `release/*`. A `create` event runs on the branch that was created, so the `publish` job runs on the release branch; the `record-manifest` job checks out `master` in that same release-branch run.
- Environment secrets:
- `SIXLABORS_LICENSE_KEY`
- `RELEASE_PR_TOKEN`
The `publish` job uses the license secret and has a read-only token. The `record-manifest` job uses the pull request token and does not have the license secret. The environment approval is the gate for both jobs.
### Secrets
#### SIXLABORS_LICENSE_KEY
This is the Six Labors license key content.
- The value to be put in the secret is the content of the license file, or the value already stored in the existing repository secret used by `Run All Tests`.
- `Run All Tests` uses the repository secret `SIXLABORS_LICENSE_KEY`.
- `Publish Release` uses the environment secret `SIXLABORS_LICENSE_KEY` in the `release` environment.
- `Publish Release` also exposes the secret as the `SixLaborsLicenseKey` MSBuild environment property, so every project that references ImageSharp validates the license, not only `Nemera.Domain`.
If the key is missing or expired, the build fails with a message such as `No Six Labors license found` or an expired license error.
#### RELEASE_PR_TOKEN
This is a fine-grained GitHub personal access token owned by the repository owner.
Create it under **Settings > Developer settings > Personal access tokens > Fine-grained tokens > Generate new token**:
- Resource owner: the owner's account.
- Repository access: only `BinaryAlley/Nemera`.
- Permissions:
- `Contents: Read and write`
- `Pull requests: Read and write`
- `Metadata: Read-only` is added automatically.
- Expiration: set an explicit date, for example 90 days, and add a calendar reminder.
Copy the generated `github_pat_...` value immediately. GitHub shows it only once. Store it as the `RELEASE_PR_TOKEN` environment secret in the `release` environment.
Why a personal access token is needed: pull requests created with the workflow `GITHUB_TOKEN` do not trigger `pull_request` workflows. The trust-list pull request must run `Run All Tests` and the branch validators, so the `record-manifest` job pushes and creates the pull request with this token.
The token is used only by the `record-manifest` job. It is not available to the build job, and the build job's token is read-only. The `record-manifest` checkout uses the token as its git token, so the persisted git credential is the PAT and both `git push` and `gh pr create` authenticate with it.
## Workflows
- `Publish Release` runs when the owner creates a `release/x.y.z` branch. It has two jobs:
- `publish`: builds and publishes the official artifacts with `OfficialReleaseBuild=true`, runs the manifest verification tests, verifies the embedded plugin manifest against every published API folder, checks every runtime's native folders and files, verifies every archive against its publish folder, records the released plugin hashes, builds the release images from the verified publish output, and uploads the `release-archives` and `bundled-plugins-manifest` artifacts. The `release-archives` artifact contains the API and web archives for every supported runtime. It has the license secret and a read-only token.
- `record-manifest`: downloads the manifest artifact, appends only the release entries that are missing from master's current trust list, and opens the `other/record-release-x.y.z` pull request to `master` with the `RELEASE_PR_TOKEN`. It does not have the license secret.
- `Run All Tests` runs on pull requests to `master` and uses the repository `SIXLABORS_LICENSE_KEY` secret.
- `Branch Push Naming Convention Check` and `Pull Request Source Branch Validation Check` allow `feature/`, `bugfix/`, `hotfix/`, `documentation/`, `refactor/`, `other/`, and `release/x.y.z`.
The release branch is built from `master` after the normal pull request checks have passed. The release build does not rerun the full test suite. It runs the manifest verification tests, because that is the only part of the build that changes when the official plugin manifest and the official release marker are embedded. It then verifies the embedded plugin manifest against every published API folder, the native folders and files of every runtime, and the contents of every archive before recording hashes or building images. The trust-list pull request runs the full suite before it can be merged.
Recording is CI-only. The publish job checks that the worktree is clean and that `HEAD` matches `origin/master` before it appends to the trust list. A local `RecordBundledPlugins` run is rejected by the guard.
The trust list `build/BundledPlugins.manifest` is append-only. Never remove existing entries. The record job uses master's current file as the base and appends only the entries that are missing from it, skipping duplicates, so the record pull request diff contains additions only. Use the release workflow, which calls `RecordBundledPlugins`, instead of editing the file by hand. The deny list `build/BundledPlugins.deny.manifest` is the revocation path: add an entry to stop trusting a hash, and remove the entry to restore trust.
## Cutting a release
1. Ensure that everything you want in the release is on `master`, that the previous release's trust-list pull request is merged, and that the normal pull request checks have passed.
2. Verify that `SIXLABORS_LICENSE_KEY` and `RELEASE_PR_TOKEN` are present and current in the `release` environment, and that the repository `SIXLABORS_LICENSE_KEY` secret is current.
3. Create the `release/x.y.z` branch from the current `master` as the owner. The publish job requires the branch to point at the current `origin/master`. The check is exact: if anything merges to `master` before the job runs, the job fails and the branch must be recreated from the new `master`.
4. Approve the `release` environment for the `publish` and `record-manifest` jobs.
5. Wait for `Publish Release` to publish and verify the official artifacts, record the trust list and build the release images.
6. Download the `release-archives` artifact. It contains one API archive and one web archive for each supported runtime identifier.
7. Create the GitHub release and tag manually from those archives. The workflow does not create the release.
8. Wait for `Run All Tests` and both branch validators on the `other/record-release-1.2.3` pull request. Review the trust-list diff and merge it.
9. The workflow builds the release images from the verified publish output to validate the image definitions, but it does not upload them. Build the images you ship from the extracted archives, so they contain exactly the plugin binaries whose hashes were recorded:
```bash
docker build --platform linux/amd64 -t nemera-api:1.2.3 -f src/Nemera.Presentation.Api/Dockerfile.release <extracted-api-folder>
docker build --platform linux/amd64 -t nemera-web:1.2.3 -f src/Nemera.Presentation.Web/Dockerfile.release <extracted-web-folder>
```
Extract `Nemera-1.2.3-linux-x64-api.tar.gz` and `Nemera-1.2.3-linux-x64-web.tar.gz` first. Each archive contains its publish files at the root, so the extracted folder is the Docker context. Use `--platform linux/arm64` with the `linux-arm64` archives. The `linux-musl-x64` archives cannot be used with these images, because their base image is a glibc distribution.
To publish, verify and build in one local step instead, run:
```bash
dotnet msbuild build/build.proj -t:Docker -p:Configuration=Release -p:OfficialReleaseBuild=true -p:Version=1.2.3
```
That target publishes from source, verifies the publish output and builds the images from the `linux-x64` publish folder with the `linux/amd64` platform derived from `ApiReleaseRuntimeIdentifier`. Pass `-p:ApiReleaseRuntimeIdentifier=linux-arm64` to build from the arm64 publish folder instead. Those images are not the exact released artifacts unless the build is byte-identical, so prefer the downloaded archives for the images you ship.
The local equivalent of the official build is verification only. Recording is CI-only. The release workflow checks that the checkout is clean and that `HEAD` matches `origin/master` exactly before it appends to the trust list.
```bash
dotnet msbuild build/build.proj -t:VerifyPublishedBundledPlugins -p:Configuration=Release -p:OfficialReleaseBuild=true -p:Version=1.2.3
```
`VerifyPublishedBundledPlugins` checks the publish folders and does not require `bin/release`. `CreateReleaseArchives` can run on its own after a publish, and `VerifyReleaseArchives` creates the archives if needed and verifies every archive against its publish folder; both must run on Linux or macOS, because Windows cannot create `.tar.gz` archives with the executable bit. The Docker target only needs the publish folders, so `-t:Docker -p:ReusePublishedBundledPlugins=true` works even when `bin/release` is absent. `ReusePublishedBundledPlugins=true` skips both the publish and its verification, so pass it only after the publish folders were just verified, as the release workflow does. The release Docker target derives `--platform` from `ApiReleaseRuntimeIdentifier`, which must be `linux-x64` (`linux/amd64`) or `linux-arm64` (`linux/arm64`); `linux-musl-x64` has no matching glibc image base.
For a local Release build, set `SixLaborsLicenseKey` to the content of `src/Nemera.Domain/sixlabors.lic` first. The file alone is only discovered by `Nemera.Domain`, and projects that reference ImageSharp through it fail license validation otherwise.
## Revoking a bundled plugin hash
The main trust list is append-only, so revoke a bad hash instead of removing it:
1. Add a `<assembly file name>|<SHA-256>` line to `build/BundledPlugins.deny.manifest`.
2. Merge the change to `master`.
3. The next build embeds the deny list. The reader removes the hash from both the historical and the current trust lists, so a plugin with that hash is no longer marked Official. It still loads.
The deny list is intentionally not append-only. Remove the line to restore trust if the revocation was a mistake.
## Rotating credentials
### Six Labors license
When the license is renewed or replaced:
1. Put the new value in the repository secret `SIXLABORS_LICENSE_KEY` used by `Run All Tests`.
2. Put the same value in the environment secret `SIXLABORS_LICENSE_KEY` in the `release` environment.
3. Re-run the failed workflow.
The local `src/Nemera.Domain/sixlabors.lic` file is only a local copy. Update it for local Release builds, but never commit it.
### RELEASE_PR_TOKEN
When the token expires, is revoked or is compromised:
1. Generate a new fine-grained token with the same repository access and permissions.
2. Replace the `RELEASE_PR_TOKEN` environment secret in the `release` environment.
3. Re-create the release branch or re-run the failed `Publish Release` workflow, depending on where it failed.
4. Revoke the old token.
If the token is compromised, also review recent branches, pull requests and workflow runs. The token has only `Contents` and `Pull requests` write access to this repository.
## Troubleshooting
| Symptom | Cause | Fix |
| --- | --- | --- |
| `Publish Release` does not run | The created ref is not a `release/x.y.z` branch, or the actor is not the repository owner. | Create the branch as the owner using the three-part version. |
| The workflow waits for approval | The `release` environment has required reviewers. | Approve the `publish` and `record-manifest` jobs as the owner. |
| `No Six Labors license found` | The secret is missing or empty. | Check the repository secret and the `release` environment secret. |
| Six Labors license expired | The license key is no longer valid. | Renew it, update both secrets and re-run. |
| `git push` or `gh pr create` fails with 401 or 403 | `RELEASE_PR_TOKEN` is missing, expired or lacks `Contents` or `Pull requests` write, or the `record-manifest` checkout does not use it as the git token. | Generate a new token if needed, update the environment secret, and ensure the `record-manifest` checkout passes it as `token`. |
| The trust-list pull request has no CI | It was created with `GITHUB_TOKEN` instead of the PAT. | Verify that the `record-manifest` job uses `RELEASE_PR_TOKEN` and that the secret is current. |
| A release branch is rejected by the ruleset | The branch was not created by the owner. | Create it as the owner. The bypass list must contain only the owner's account. |
| The branch validator rejects a release branch | The branch is not `release/x.y.z`. | Use three numeric parts, for example `release/1.2.3`. |
| The branch validator rejects the trust-list pull request | The branch prefix is not allowed. | The workflow uses `other/record-release-x.y.z`, which is allowed. |
| `Official` is false in a release | The build did not use `OfficialReleaseBuild=true`, or the plugin binary does not match the trust manifest. | Use the `Publish Release` workflow, or pass `-p:OfficialReleaseBuild=true` with `Configuration=Release`. |
| `RecordBundledPlugins` fails | Recording is attempted outside GitHub Actions, from a dirty worktree, from a commit that is not the current `origin/master`, or without `Configuration=Release` and `OfficialReleaseBuild=true`. | Use the `Publish Release` workflow. Commit or stash changes, merge the previous trust-list pull request, and recreate the release branch from `master`, if the guard reports a tree or history problem. |
| `RecordBundledPlugins` fails because `master` moved | The release branch no longer matches the current `origin/master`. | Recreate the `release/x.y.z` branch from the new `master` and approve the new run. |
| The record-list pull request removes trust-list lines | The merge step was skipped, or master's current manifest was replaced with an older artifact. | The record job only appends missing entries and fails if the staged diff removes a line. Rerun the workflow. |
| A known good plugin is not Official | A deny-list entry matches its hash. | Remove the matching line from `build/BundledPlugins.deny.manifest`. |
| `VerifyPublishedBundledPlugins` fails | The bundled plugin staging folder is missing a native folder the catalog declares or contains an undeclared one, a published runtime folder is missing its assembly, apphost, plugin binary or native file, still contains a PDB or an undeclared native runtime folder or an unexpected number of plugin binaries, its embedded plugin manifest does not match its plugin binaries, or its plugin binaries differ from the reference `linux-x64` folder. | Re-run the release build from the same commit. Do not mix artifacts from different builds. If the staging folder and the catalog disagree, align `build/RuntimeIdentifiers.props` with the native folders the bundled plugins deploy. |
| `VerifyReleaseArchives` fails | A platform archive is missing, or its files or hashes differ from the publish folder it was built from, or the Linux or macOS app host is not executable inside the archive. | Re-run the release build from the same commit, so the archives and the publish folders come from the same build. Build Linux and macOS archives on Linux or macOS. |
| The Linux or macOS archives are missing after `Publish` | `Publish` ran on Windows, which cannot store the executable bit in a tar archive, so those archives are skipped with a warning. | Run `Publish` on Linux or macOS. The `Publish Release` workflow builds the released archives on `ubuntu-latest`. |
| The release build rejects the version | `Version` or `ReleaseVersion` is not three numeric parts. | Pass a version such as `-p:Version=1.2.3`. |
| The release image build fails with an official configuration error | `Docker` was called with `OfficialReleaseBuild=true` and a configuration other than `Release`, or with an `ApiReleaseRuntimeIdentifier` that is not a glibc runtime (`linux-x64` or `linux-arm64`; the musl runtime has no matching image base). | Pass `-p:Configuration=Release` and a glibc runtime identifier such as `linux-x64`. |