Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
runs-on: ubuntu-latest
outputs:
breaking: ${{ steps.check.outputs.breaking }}
migration-guide: ${{ steps.check.outputs.migration-guide }}
steps:
- uses: actions/checkout@v7
with:
Expand All @@ -43,6 +44,8 @@ jobs:
- name: Check Title and Release Type
id: check
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
PR_NUMBER: ${{ github.event.pull_request.number }}
PR_TITLE: ${{ github.event.pull_request.title }}
PR_BODY: ${{ github.event.pull_request.body }}
Expand All @@ -58,14 +61,13 @@ jobs:
env:
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
GUIDE: ${{ needs.title.outputs.migration-guide }}
run: |
guide='docs/docs/operator/help/migration.mdx'

if gh api --paginate "repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER/files?per_page=100" --jq '.[].filename' \
| grep -qxF "$guide"; then
echo "Breaking change with an update of $guide."
| grep -qxF "$GUIDE"; then
echo "Breaking change with an update of $GUIDE."
exit 0
fi

echo "::error file=$guide::Breaking changes must be documented in $guide, in the section for the next major version (e.g. \"Upgrading from v13 to v14\")."
echo "::error file=$GUIDE::Breaking changes must be documented in $GUIDE. The first breaking change of a major version creates the page."
exit 1
10 changes: 9 additions & 1 deletion .release/check-pull-request.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// Evaluates a pull request with the semantic-release configuration of release.base.mjs, so the
// PR checks and the release share one set of rules. PRs are squash-merged: the title becomes the
// commit header and the description the commit body.
import { execFileSync } from "node:child_process";
import { appendFileSync } from "node:fs";
import { analyzeCommits } from "@semantic-release/commit-analyzer";
import createPreset from "conventional-changelog-conventionalcommits";
import { CommitParser } from "conventional-commits-parser";
import config from "./release.base.mjs";
import config, { migrationGuide } from "./release.base.mjs";

const pluginConfig = (name) => config.plugins.find(([plugin]) => plugin === name)[1];
const analyzer = pluginConfig("@semantic-release/commit-analyzer");
Expand Down Expand Up @@ -34,3 +35,10 @@ const release = await analyzeCommits(analyzer, {
console.log(`This pull request results in: ${release ?? "no"} release`);
appendFileSync(process.env.GITHUB_STEP_SUMMARY, `This pull request results in: **${release ?? "no"} release**\n`);
appendFileSync(process.env.GITHUB_OUTPUT, `breaking=${release === "major"}\n`);

if (release === "major") {
// The next major version follows the latest stable release.
const latest = execFileSync("gh", ["release", "view", "--json", "tagName", "--jq", ".tagName"], { encoding: "utf8" });
const major = Number.parseInt(latest.replace(/^v/, ""), 10) + 1;
appendFileSync(process.env.GITHUB_OUTPUT, `migration-guide=${migrationGuide.page(major)}\n`);
}
11 changes: 7 additions & 4 deletions .release/release.base.mjs
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
const isStableRelease = process.env.SEMANTIC_RELEASE_STABLE === "true";
const migrationGuideUrl = "https://dotnet.github.io/dotnet-operator-sdk/docs/operator/help/migration";
// The migration guide has one page per major version; the PR check requires the page of the next one.
export const migrationGuide = {
page: (major) => `docs/docs/operator/help/migration/v${major}.mdx`,
url: (major) => `https://dotnet.github.io/dotnet-operator-sdk/docs/operator/help/migration/v${major}`,
};

// Conventional Commits requires the BREAKING CHANGE footer in upper case, but the parser default ignores case,
// so a description line starting with "Breaking change" would trigger a major release.
const parserOpts = {
notesPattern: (keywords) => new RegExp(`^[\\s|*]*(${keywords})[:\\s]+(.*)`),
};

// Every release with breaking changes links the migration guide section of its major version.
// Every release with breaking changes links the migration guide page of its major version.
const linkMigrationGuide = (context) => {
const breakingChanges = context.noteGroups?.find((group) => group.title === "BREAKING CHANGES");
const major = Number.parseInt(context.version, 10);

if (breakingChanges) {
const section = `upgrading-from-v${major - 1}-to-v${major}`;
breakingChanges.notes.unshift({
text: `See the [migration guide](${migrationGuideUrl}#${section}) for upgrading from v${major - 1} to v${major}.`,
text: `See the [migration guide](${migrationGuide.url(major)}) for upgrading from v${major - 1} to v${major}.`,
});
}

Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ breaking changes are well documented.

Mark breaking changes with `!` in the PR title or an upper-case
`BREAKING CHANGE: ...` line in the PR description, and document them in the
[Migration Guide](docs/docs/operator/help/migration.mdx). The
[Migration Guide](docs/docs/operator/help/migration/), on the page of the next major version. The
[contribution guide](https://dotnet.github.io/dotnet-operator-sdk/docs/operator/contribution/)
describes the rules and the checks that enforce them.

Expand Down
8 changes: 5 additions & 3 deletions docs/docs/operator/contribution/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ working on the project are volunteers.
spellings do not count as breaking. The title and description become the squash commit that decides
the release. The `PR Title` check evaluates both with the release configuration and shows in its
summary which release the PR results in.
- **Document breaking changes in the [Migration Guide](../help/migration.mdx)**, in the section for the next
major version, e.g. "Upgrading from v13 to v14". The `Migration Guide` check fails for a breaking PR
that does not update it.
- **Document breaking changes in the [Migration Guide](../help/migration/index.mdx)**, on the page of the next
major version, e.g. `help/migration/v16.mdx` for "Upgrading from v15 to v16". The first breaking change of a
major version creates the page from the newest one, with the negative major version as `sidebar_position`
(`-16`), and adds a row to `index.mdx`. The `Migration Guide` check fails for a breaking PR that does not
change the page of the next major version.

PRs are squashed and merged into the default branch.

Expand Down
Loading
Loading