permissions:
# To publish Docker images on GHCR, npm packages and Helm charts on OCI registry
packages: write
# To publish Python packages using OIDC and for cosign keyless signing
id-token: write
# To publish Helm charts (chart-releaser) and send repository dispatch notifications
contents: write
Install the package in the worklow, with only the extras you need (see
Extras below), to reduce the attack surface during the publishing:
To reduce the attack surface, the dependencies are split into optional extras, one
per kind of publishing. Only install the extras you actually use: a plain
pip install tag-publish installs the core only (PyYAML, security-md,
githubkit) and will fail with an explicit message if you try a publishing whose
extra is missing.
The Node (npm) publishing needs no extra, it only uses the npm CLI.
The validation extra is optional: without it the schema validation of
.github/publish.yaml is skipped with a warning.
Install several extras at once, e.g. pip install 'tag-publish[pypi,docker,helm]'.
New version
To create a new version you should create a Git tag with the version number.
New stabilization branch
To create a new minor version you just should run tag-publish-new --version=<version>.
This will create the stabilization branch and will create a new pull request to update
the SECURITY.md file and the Renovate configuration.
This will also create the tags for the backport.
You are welcome to run tag-publish-new --help to see what's it's done.
Note that it didn't create a tag, you should do it manually.
To create a patch version you should just create tag.
Kind of publishing
This tool can publish on different kind of versions:
tag: Related to a Git tag.
default_branch: Related to the default branch.
stabilization_branch: Related to a stabilization branch (including the default branch).
feature_branch: Related to a feature branch or a pull request.
We can also publish on different kind of versions like rebuild by using the --type argument.
SECURITY.md
The SECURITY.md file should contain the security policy of the repository, especially the end of
support dates.
For compatibility with security.md it should contain an array
with at least the columns Version and Supported Until. The Version column will contain the concerned
version.
The Supported Until will contain the date of end of support dd/mm/yyyy.
It can also contain the following sentences:
Unsupported: no longer supported => no audit, no rebuild.
Best effort: the support is ended, it is still rebuilt and audited, but this can be stopped without any notice.
To be defined: not yet released or the date will be set related of another project release date (like for GeoMapFish).
The configuration file is .github/publish.yaml, the schema is https://raw.githubusercontent.com/camptocamp/tag-publish/<version>/tag_publish/schema.json.
Dry run
Dry run publish: GITHUB_REF=... tag-publish --dry-run ...
By default the package will be published only on tag, if you want to publish on stabilization branch you should add
a versions key with the list of versions you want to publish, that can be:
rebuild (specified with --type), tag, default_branch, stabilization_branch, feature_branch, pull_request (for pull request merge: number)
It we have a setup.py file, we will be in legacy mode:
When publishing, the version computed from arguments or GITHUB_REF is put in environment variable VERSION, thus you should use it in setup.py, example:
Note that we can access to the environment variables VERSION,VERSION_TYPE.
Then by default:
Tag with 1.2.3 => release 1.2.3
Commit on feature branch just do a validation
Commit on master branch after the tag 1.3.0 => release 1.4.0.dev1
Commit on 1.3 branch after the tag 1.3.0 => release 1.3.1.dev1
Authentication
If the file ~/.pypirc exists we consider that we ar already logged in also
we will do the login with the pypi server with OpenID Connect (OIDC).
The OIDC login is recommended because it didn't needs any additional secrets,
but it need some configuration on pypi in the package,
see the GitHub Documentation.
The required permissions is id-token: write.
Integration if the package directly in a Docker image
To make it working in the Dockerfile you should have in the poetry stage:
VERSION = $(strip $(shell poetry version --short))
.PHONY: build
build: ## Build the Docker images
docker build --build-arg=VERSION=$(VERSION) --tag=$(GITHUB_REPOSITORY) .
Docker image to registry
The minimal config is like this:
docker:
images:
- name: camptocamp/tag-publish
If you want to use the GitHub token to be logged in on ghcr you should set auto_login to True, the
requires the permissions are packages: write.
With that the image initially named camptocamp/tag-publish:latest will be published on GitHub GHCR and on Docker hub.
The full config is like this:
docker:
github_oidc_login: True
latest: True
images:
- # The base name of the image we want to publish
name:
repository:
<internal_name>:
# The fqdn name of the server if not Docker hub
server:
# List of kinds of versions you want to publish, that can be: rebuild (specified using --type),
# tag, stabilization_branch, feature_branch, pull_request (for pull request merge: number)
version:
# List of tags we want to publish interpreted with `format(version=version)`
# e.g. if you use `{version}-lite` when you publish the version `1.2.3` the source tag
# (that should be built by the application build) is `latest-lite`, and it will be published
# with the tag `1.2.3-lite`.
tags:
# If your images are published by different jobs you can separate them in different groups
# and publish them with `tag-publish --group=<group>`
group:
# Publish the SBOM of the image, `True` by default
sbom:
By default, the last line of the SECURITY.md file will be published (docker) with the tag
latest. Set latest to False to disable it.
SBOM attestation
By default (sbom: True), once the image is pushed, tag-publish generates a CycloneDX SBOM with
syft from the local image (without downloading it again from the
registry) and attaches it to every published image, referenced by its digest, as a keyless
cosign attestation (cosign attest) on the registry.
The publishing job requires the packages: write permission (to push the image and the
attestation) and the id-token: write permission (for the keyless signature), and applications-download
is required, so the docker extra must be installed: pip install 'tag-publish[docker]'.
By default the chart is published on both destinations, this is configurable with types:
helm:
packages:
- {}
types:
- oci # Push the chart to an OCI registry, signed with cosign
- cr # Attach the chart to a GitHub release and update the gh-pages index
The gh-pages branch and the contents: write permission are only required by the cr destination.
Removing cr is required to enable the GitHub release immutability option on the repository: chart
releaser creates the release and attaches the chart in a second API call, and that second call is
rejected once the release is immutable.
OCI registry publishing
By default, the Helm chart is also published to an OCI registry (ghcr.io/<owner>/<repo>) and signed with cosign using keyless signing.
The chart is pushed to ghcr.io/<owner>/<repo>/<chart-name>:<version>, e.g.
ghcr.io/camptocamp/tag-publish/tag-publish:1.2.2.
The required permissions are packages: write (for pushing to ghcr.io) and id-token: write (for cosign keyless signing).
If the first push fails with 403: denied: installation not allowed to Create organization package,
the packages: write permission is missing in the workflow, and the package must be created by a first
push or manually before the GITHUB_TOKEN is allowed to write on it.