|
| 1 | +# Release Container Workflow Sample |
| 2 | + |
| 3 | +This sample workflow demonstrates a complete release pipeline that combines semantic versioning, container publishing, and automated tagging. It's designed to be copied into your project's `.github/workflows/` directory and customised for your specific needs. |
| 4 | + |
| 5 | +The idea is to provide a drop-in model for releasing software, where developers can focus on code, rather than the mechanics of releases. The developer only has to make the decision of what type of release (patch, minor, major, none) and communicate this through their PR title. The workflow then takes care of the rest - generating release notes, creating GitHub releases, building and publishing container images, and tagging them appropriately. |
| 6 | + |
| 7 | +This exists within the existing constraints of Github, mostly that [automated releases cannot trigger other workflows](https://github.com/orgs/community/discussions/25281), so by composing reusable workflows together we can achieve a full release pipeline that is still easy to understand and maintain. The workflow is also designed to be flexible, so you can easily swap out the container publishing step for other types of release artifacts if needed. |
| 8 | + |
| 9 | +## Overview |
| 10 | + |
| 11 | +The workflow performs the following steps: |
| 12 | + |
| 13 | +1. **Semantic Release**: Analyses commits since the last release to determine if a new version should be created, and if so, generates a new Github release with an automatically generated changelog. |
| 14 | +2. **Container Publishing**: Builds and pushes a container image with an `edge` tag (we avoid latest, so this is a pre-release build) |
| 15 | +3. **Semver Tagging**: If a release was created, promotes the edge image to semantic version tags (e.g., `1.2.3`, `1.2`, `1`) |
| 16 | + |
| 17 | +## Prerequisites |
| 18 | + |
| 19 | +- Your repository must follow [conventional commit](https://conventionalcommits.org/) format |
| 20 | +- We recommend `samples/check.pr-title.yaml` to enforce this on pull requests |
| 21 | +- Your repository settings should only allow squash merges, and use the PR title as the commit message for commit messages to be correctly parsed by semantic-release |
| 22 | +- You need a `samples/release.config.js` in your repository root to configure semantic-release |
| 23 | +- You need a `Dockerfile` in your repository root (or update the `dockerfile` parameter) |
| 24 | + |
| 25 | +## Workflow Jobs |
| 26 | + |
| 27 | +### semantic-release |
| 28 | + |
| 29 | +Uses the [`semantic-release.yml`](../semantic-release.md) reusable workflow to: |
| 30 | + |
| 31 | +- Install and run semantic-release |
| 32 | +- Create GitHub releases with automatically generated changelogs |
| 33 | +- Output `release-created` (boolean) and `release-tag` (version string) |
| 34 | + |
| 35 | +### publish-container |
| 36 | + |
| 37 | +Uses the [`publish-container.yml`](../publish-container.md) reusable workflow to: |
| 38 | + |
| 39 | +- Build a multi-architecture container image |
| 40 | +- Tag it with SHA, timestamp, and "edge" |
| 41 | +- Push to the specified container registry |
| 42 | + |
| 43 | +**Parameters:** |
| 44 | + |
| 45 | +- `image-name`: Name of your container image |
| 46 | +- `image-description`: Description for the image |
| 47 | +- `registry`: Container registry (e.g., `ghcr.io`, `docker.io`) |
| 48 | +- `context`: Build context path (usually `.`) |
| 49 | +- `dockerfile`: Path to Dockerfile |
| 50 | +- `platforms`: Target architectures (comma-separated) |
| 51 | + |
| 52 | +### semver-container |
| 53 | + |
| 54 | +Uses the [`semver-container.yml`](../semver-container.md) reusable workflow to: |
| 55 | + |
| 56 | +- Promote the edge image to semantic version tags |
| 57 | +- Only runs if `semantic-release` created a new release |
| 58 | + |
| 59 | +**Parameters:** |
| 60 | + |
| 61 | +- `image-name`: Must match the `publish-container` job |
| 62 | +- `registry`: Must match the `publish-container` job |
| 63 | +- `tag`: Release tag from semantic-release (do not modify) |
| 64 | + |
| 65 | +### Version Pinning |
| 66 | + |
| 67 | +For production use, pin to specific versions: |
| 68 | + |
| 69 | +```yaml |
| 70 | +uses: health-informatics-uon/workflows/.github/workflows/semantic-release.yml@v1.3.0 |
| 71 | +``` |
| 72 | +
|
| 73 | +Check the [releases](https://github.com/health-informatics-uon/workflows/releases) for available versions. |
| 74 | +
|
| 75 | +## Usage |
| 76 | +
|
| 77 | +1. Copy `samples/release.container.yaml` to your repository's `.github/workflows/release.yaml` |
| 78 | +2. Copy `samples/release.config.js` to your repository root and customise it for your repository |
| 79 | +3. Update the workflow parameters in `release.yaml` (image name, etc.) |
| 80 | +4. Ensure your repository follows the prerequisites (conventional commits, squash merges, etc.) |
0 commit comments