setdef/Cutter/.github/workflows/version.yml is a reusable workflow. A job early in your CI workflow calls it with uses:, and the jobs that build your project read its version output, so that each run builds with the version it would release as. In a run for a version tag, the version is the tag's. In a run for trunk or a release/X.Y branch, it is the version the commit would release as, which the release workflow shows in that run's summary, and which that run releases, with no tag pushed, as Releasing a commit with no tag pushed describes. A run with no job that calls this workflow releases nothing that way.
Call it from a job that your build jobs and your release job need, pinned at the same commit of Cutter as the release workflow:
version:
uses: setdef/Cutter/.github/workflows/version.yml@39106f347420ac7dd0f274dac8cbcb7c419fd427 # v0.10.0
permissions:
contents: readThe job pins Cutter by commit, as Pinning Cutter says.
Keep changelog and packages in the settings file, .config/cutter.yml, which this job and the release job both read, and give this job no inputs. When the file holds at least one of the release workflow's five settings, the job reads changelog and packages from it, as the release workflow does, and none of its inputs. A file that holds none of the five, such as one that holds only a build-cop key, leaves the job on its inputs, and then you give it the same changelog and packages inputs as the release workflow, or leave both out of both.
The changelog and packages inputs are deprecated, and a later major version of Cutter will remove them: Deprecated settings. This workflow writes no notice of it. The release workflow's release step does, once for the run, when the settings come from inputs.
| Input | Type | Default | What it is |
|---|---|---|---|
changelog |
string | CHANGELOG.md |
The path of your changelog, from the repository's root, as the release workflow's changelog input gives it. Not read when the settings file holds any of the release workflow's five settings. Deprecated: give changelog in the settings file instead. |
packages |
string | empty | The packages of a repository that holds several, one line each, as the release workflow's packages input gives them. Not read when the settings file holds any of the release workflow's five settings. Deprecated: give packages in the settings file instead. |
| Output | Holds |
|---|---|
version |
The version to build with, such as 0.4.0, or empty. |
tag |
The tag of that version, such as v0.4.0 or invoice/v0.4.0, or empty. |
commit |
The full SHA of the commit the run is for, or empty when version is. |
| The run is for | version |
|---|---|
A push of a tag named v plus a version, or a package's tag prefix, v, and a version |
The tag's version. The run asks GitHub for nothing but the settings file, whose packages say which package the tag is of. |
A push to, or workflow_dispatch on, trunk or a release/X.Y branch, or a package's release branch |
The version the commit would release as, when the changelog lists something new and a tag of that version could be released from the commit. Otherwise empty, as the release workflow's summary of a run on a branch says why. With two or more packages in the packages input, empty. |
| Any other branch, or a tag whose name isn't a version's | Empty. |
When version is empty, build with the version your project has. When GitHub answers a request with an error, the run writes a warning, sets every output to empty, and succeeds.
The run writes one line to its summary, such as Build 4f2a9c1 with the version 0.4.0: it would release as v0.4.0.
A run for an event other than push and workflow_dispatch, a tag by any event but push, a packages input that Cutter can't read, or a settings file it can't use, stops with the error that the release workflow gives for it, and uploads no cutter-version artifact.
The job uploads an artifact named cutter-version to the run, which holds what the job named, the commit of Cutter it ran, and the changelog and packages it read, from its inputs or from the settings file. The release job of the same run reads it, and releases its commit only when the artifact holds the version that job would release, the same commit of Cutter, and the same changelog and packages, since only then do your files carry that version. Give none of your artifacts that name. If you merge artifacts into the one your release publishes, with actions/upload-artifact/merge, give the merge a pattern that matches only your artifacts, so that cutter-version stays out of the release.
Grant the calling job contents: read, to read your tags, your changelog, and the history of the commit.