GitHub Actions workflow dispatch
With this recipe, you can trigger the entire release process manually by either clicking a button in GitHub Actions or by using the GitHub CLI. Once that trigger occurs:
- Knope calculates the new version of the project (using
PrepareRelease
) and updates versioned files and changelogs. - Knope commits the changes back to the branch and pushes.
- GitHub Actions builds assets from the new commit.
- Knope creates a release on GitHub with the new version, changelog, and assets.
You should also check out the Pull Request Releases recipe, which is similar, but includes release previews via pull requests.
Here’s the GitHub Actions workflow file:
There are three jobs here:
prepare-release
runs theprepare-release
Knope workflow and saves the new commit as an output for use later.build-artifacts
builds the assets for the release from the new commit thatprepare-release
created.release
runs therelease
Knope workflow which creates the GitHub Release.
Throughout, there’s use of a ${{ secrets.PAT }}
, this is a GitHub Token with write permissions to “contents” which
must be stored in GitHub Actions secrets.
For the minimum-possible required privileges,
you should create a fine-grained access token with read/write to “contents” for only this repo.
Here’s a Knope config which enables this GitHub workflow to work:
There’s a single [package]
, but this pattern should also work for multi-package setups, just make sure all your assets are ready at the same time.
In this case, there are two versioned files (Cargo.toml
and Cargo.lock
), the changelog (CHANGELOG.md
), and all
assets (four, in the example GitHub workflow).
There are two relevant workflows here, the third (document-change
) is for creating changesets during development. prepare-release
starts by running the PrepareRelease
step, which does the work of updating Cargo.toml
, Cargo.lock
, and CHANGELOG.md
based
on any conventional commits or changesets.
Knope then runs a command to commit the changes and push them back to the current branch (note that using the Version
variable isn’t supported for multi-package setups at this time). Once this workflow runs, the project is ready to build assets.
When ready, GitHub Actions calls into the release
workflow which runs a single step: Release
.
This will compare the latest stable tagged release to the version in Cargo.toml
(or any other versioned_files
)
and create releases as needed by parsing the contents of CHANGELOG.md
for the release’s body.
The release is initially created as a draft, then Knope uploads assets before publishing the release
(so your subscribers won’t be notified until it’s ready).