forked from knope-dev/knope
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New
CreatePullRequest
workflow (knope-dev#579)
Co-authored-by: Dylan Anthony <[email protected]>
- Loading branch information
Showing
45 changed files
with
1,179 additions
and
561 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
.changeset/add_a_changelogsection_variable_for_substitution.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
default: minor | ||
--- | ||
|
||
#### Add a `ChangelogEntry` variable for substitution | ||
|
||
Anywhere that the existing `Version` variable can be used (for example, in [the `Command` step]), you can now also use `ChangelogEntry` to get the section of the changelog that corresponds to the current version. For example, you could (almost) replicate Knope's GitHub Release creation _without_ Knope's GitHub integration with a workflow like this: | ||
|
||
```toml | ||
[[workflows]] | ||
name = "release" | ||
|
||
[[workflows.steps]] | ||
type = "PrepareRelease" | ||
|
||
[[workflows.steps]] | ||
type = "Command" | ||
command = "git commit -m \"chore: prepare release $version\" && git push" | ||
|
||
[workflows.steps.variables] | ||
"$version" = "Version" | ||
|
||
[[workflows.steps]] | ||
type = "Command" | ||
command = "gh release create --title '$version' --notes '$changelog'" | ||
|
||
[workflows.steps.variables] | ||
"$version" = "Version" | ||
"$changelog" = "ChangelogEntry" | ||
``` | ||
|
||
[the `Command` step]: https://knope-dev.github.io/knope/config/step/Command.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
default: minor | ||
--- | ||
|
||
#### New `CreatePullRequest` step | ||
|
||
The new [`CreatePullRequest` step] allows you to create or update a pull request on GitHub. It's designed to be a nice way to preview and accept new releases via a pull request workflow, but could certainly work for more contexts as well! To see an example of the new PR-based release workflow, check out [Knope's prepare-release workflow] and [Knope's release workflow]. | ||
|
||
[`CreatePullRequest step]: https://knope-dev.github.io/knope/docs/config/step/CreatePullRequest | ||
[Knope's prepare-release workflow]: https://github.com/knope-dev/knope/blob/e7292fa746fe1d81b84e5848815c02a0d8fc6f95/.github/workflows/prepare_release.yml | ||
[knope's release workflow]: https://github.com/knope-dev/knope/blob/e7292fa746fe1d81b84e5848815c02a0d8fc6f95/.github/workflows/release.yml |
7 changes: 7 additions & 0 deletions
7
.changeset/only_consider_prereleases_newer_than_the_last_stable.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
default: patch | ||
--- | ||
|
||
#### Only consider prereleases newer than the last stable | ||
|
||
This fixes a regression in the previous version of Knope where _all_ prereleases would be considered, rather than just those tagged after the latest stable version. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
on: | ||
push: | ||
branches: [main] | ||
name: Create Release PR | ||
jobs: | ||
prepare-release: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4 | ||
with: | ||
fetch-depth: 0 | ||
token: ${{ secrets.PAT }} | ||
- name: Configure Git | ||
run: | | ||
git config --global user.name GitHub Actions | ||
git config user.email [email protected] | ||
- uses: Swatinem/rust-cache@v2 | ||
with: | ||
shared-key: "release" | ||
- run: cargo run -- prepare-release --verbose | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.PAT }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# `CreatePullRequest` | ||
|
||
Create a pull request on GitHub from the current branch to a specified branch. If a pull request for those already exists, this step will overwrite the title and body of the existing pull request. | ||
|
||
## Parameters | ||
|
||
### `base` | ||
|
||
The branch to create the pull request against. This is **required**. | ||
|
||
### `title.template` | ||
|
||
A template string for the title of the pull request. This is **required**. | ||
|
||
### `title.variables` | ||
|
||
An optional map of variables to use in the title template. | ||
|
||
### `body.template` | ||
|
||
A template string for the body of the pull request. This is **required**. | ||
|
||
### `body.variables` | ||
|
||
An optional map of variables to use in the body template. | ||
|
||
## Example | ||
|
||
An example workflow which creates a pull request from the current branch to `main` using the current version of the package as the title and the changelog entry for the current version as the body: | ||
|
||
```toml | ||
[[workflows]] | ||
name = "create-release-pull-request" | ||
|
||
[[workflows.steps]] | ||
type = "CreatePullRequest" | ||
|
||
[workflows.steps.base] | ||
default = "main" | ||
|
||
[workflows.steps.title] | ||
template = "chore: Release $version" | ||
variables = { "$version" = "Version" } | ||
|
||
[workflows.steps.body] | ||
template = "Merging this PR will release the following:\n\n$changelog" | ||
variables = { "$changelog" = "ChangelogEntry" } | ||
``` | ||
|
||
For a full example of how this might be used with GitHub Actions to help automate releases, check out [Knope's prepare-release workflow] and [Knope's release workflow]. | ||
|
||
[Knope's prepare-release workflow]: https://github.com/knope-dev/knope/blob/e7292fa746fe1d81b84e5848815c02a0d8fc6f95/.github/workflows/prepare_release.yml | ||
[knope's release workflow]: https://github.com/knope-dev/knope/blob/e7292fa746fe1d81b84e5848815c02a0d8fc6f95/.github/workflows/release.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Variables | ||
|
||
Some steps, notably [`Command`] and [`CreatePullRequest`] allow you to use variables in their configuration. Typically, this allows for string substitution with some context that Knope has. Variables are always configured by providing both the string that should be replaced and the name of the variable that should replace it, so you can customize your own syntax. For example, if you wanted to insert the current package version into a command, you might provide a `{"version": "Version"}` variable config. This would replace any instance of the string `version` with `Version`. If you wanted a bash-like syntax, you might use `{"$version": "Version"}` instead—pick whatever works best for you. | ||
|
||
## `Version` | ||
|
||
`Version` will attempt to parse the current package version and substitute that string. For example, you might use this to get the new version after running a [`PrepareRelease`] step. | ||
|
||
```admonish warning | ||
This variable can only be used when a single `[package]` is configured, there is currently no equivalent for multi-package projects. | ||
``` | ||
|
||
## `ChangelogEntry` | ||
|
||
`ChangelogEntry` is the content of the changelog (if any) for the version that is indicated by the [`Version`](#version) variable. This follows the same rules as the [`Release`] step for creating a [GitHub changelog](./step/Release.md#github-release-notes), with the exception that it cannot use GitHub's auto-generated release notes. If no changelog entry can be found, the step fails. | ||
|
||
```admonish warning | ||
This variable can only be used when a single `[package]` is configured, there is currently no equivalent for multi-package projects. | ||
``` | ||
|
||
## `IssueBranch` | ||
|
||
`IssueBranch` will provide the same branch name that the [`SwitchBranches`] step would produce. You must have already selected an issue in this workflow using [`SelectJiraIssue`], [`SelectGitHubIssue`], or [`SelectIssueFromBranch`] before using this variable. | ||
|
||
[`Command`]: ./step/Command.md | ||
[`CreatePullRequest`]: ./step/CreatePullRequest.md | ||
[`PrepareRelease`]: ./step/PrepareRelease.md | ||
[`Release`]: ./step/Release.md | ||
[`SwitchBranches`]: ./step/SwitchBranches.md | ||
[`SelectJiraIssue`]: ./step/SelectJiraIssue.md | ||
[`SelectGitHubIssue`]: ./step/SelectGitHubIssue.md | ||
[`SelectIssueFromBranch`]: ./step/SelectIssueFromBranch.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.