Skip to content

Commit aff58fb

Browse files
committed
Add latest
1 parent a8d26e4 commit aff58fb

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

.github/workflows/semver-container.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ on:
1616
description: 'The release tag to derive semver from (e.g. 1.2.3 or v1.2.3)'
1717
required: true
1818
type: string
19+
tag-latest:
20+
description: 'Also push a latest tag (only applied to stable releases, not pre-releases)'
21+
required: false
22+
default: false
23+
type: boolean
1924

2025
env:
2126
image-name: ${{ inputs.image-name }}
@@ -91,6 +96,7 @@ jobs:
9196
type=raw,value=${{ steps.version.outputs.version }}
9297
type=raw,value=${{ steps.version.outputs.major }},enable=${{ steps.version.outputs.is-prerelease == 'false' }}
9398
type=raw,value=${{ steps.version.outputs.major-minor }},enable=${{ steps.version.outputs.is-prerelease == 'false' }}
99+
type=raw,value=latest,enable=${{ inputs.tag-latest && steps.version.outputs.is-prerelease == 'false' }}
94100
95101
# Rather than rebuilding the image, we retag the existing edge image (tagged with
96102
# the commit SHA by publish-container) with the semver tags computed above.

docs/workflows/semver-container.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
Reusable workflow that:
44

5-
- tags an existing container image with semver tags (`x.y.z`, `x`, `x.y`) based on a provided release tag
5+
- tags an existing container image with semver tags (`x.y.z`, `x`, `x.y`) based on a provided release tag, and optionally `latest`
66
- verifies that a corresponding container image (tagged with the commit SHA) already exists
77

88
Use this when you already have an "edge" or commit-SHA container image (for example from the `publish-container` workflow) and you want to promote it to a semver release.
99

10-
> **Note:** The `x` and `x.y` floating tags are only applied for stable releases. Pre-release versions (e.g. `1.0.0-beta.1`) receive only the full version tag.
10+
> **Note:** The `x`, `x.y`, and `latest` floating tags are only applied for stable releases. Pre-release versions (e.g. `1.0.0-beta.1`) receive only the full version tag.
1111
1212
## Inputs
1313

@@ -16,6 +16,7 @@ Use this when you already have an "edge" or commit-SHA container image (for exam
1616
| `image-name` | Yes || Image name, e.g. `my-app` or `services/api`. |
1717
| `registry` | No | `'ghcr.io'` | Registry host. |
1818
| `tag` | Yes || The release tag to derive semver from (e.g. `1.2.3` or `v1.2.3`). Typically passed from the `release-tag` output of the `semantic-release` workflow. |
19+
| `tag-latest` | No | `false` | Also push a `latest` tag. Only applied to stable releases, not pre-releases. |
1920

2021
## Secrets
2122

@@ -45,3 +46,17 @@ This will:
4546
4647
- check that an image `ghcr.io/<owner>/my-service:<sha>` exists
4748
- push additional tags like `1.2.3`, `1`, and `1.2` to that image (or just `1.2.3` for pre-releases)
49+
50+
To also push a `latest` tag on stable releases, set `tag-latest: true`:
51+
52+
```yaml
53+
semver-container:
54+
needs: release
55+
if: needs.release.outputs.release-created == 'true'
56+
uses: health-informatics-uon/workflows/.github/workflows/semver-container.yml@main
57+
with:
58+
image-name: my-service
59+
tag: ${{ needs.release.outputs.release-tag }}
60+
tag-latest: true
61+
secrets: inherit
62+
```

0 commit comments

Comments
 (0)