Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reject changesets with major bumps #1509

Merged
merged 4 commits into from
Nov 23, 2023
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
7 changes: 7 additions & 0 deletions .changeset/mighty-hounds-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@siteimprove/alfa-toolchain": minor
---

**Added:** Structure validation can now optionally check that changeset contain no "major" bump.

The option can be turned on for pre-1.0.0 projects, and turned off when moving to 1.0.0.
1 change: 1 addition & 0 deletions config/validate-structure.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"has-api-extractor-config": true,
"validate-changesets": true,
"forbid-major": true,
"validate-package-json": {
"organisation": "@siteimprove",
"homepage": "https://alfa.siteimprove.com",
Expand Down
3 changes: 2 additions & 1 deletion docs/review/api/alfa-toolchain.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

```ts

import { Array as Array_2 } from '@siteimprove/alfa-array';
import type { ChangelogFunctions } from '@changesets/types';
import { PackageJSON } from '@changesets/types';

Expand Down Expand Up @@ -31,7 +32,7 @@ export { individualChangelog }
function validate(cwd: string): Promise<void>;

// @public
function validateChangesets(cwd: string): Promise<Array<string>>;
function validateChangesets(cwd: string, forbidMajor?: boolean): Promise<Array_2<string>>;

// Warning: (ae-forgotten-export) The symbol "Config" needs to be exported by the entry point index.d.ts
//
Expand Down
2 changes: 2 additions & 0 deletions packages/alfa-toolchain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
"@changesets/git": "^2.0.0",
"@changesets/read": "^0.5.9",
"@manypkg/get-packages": "=1.1.3",
"@siteimprove/alfa-array": "workspace:^0.69.0",
"@siteimprove/alfa-option": "workspace:^0.69.0",
"@siteimprove/alfa-result": "workspace:^0.69.0",
"@svitejs/changesets-changelog-github-compact": "^1.1.0",
"resolve-from": "^5.0.0"
Expand Down
4 changes: 3 additions & 1 deletion packages/alfa-toolchain/src/validation/validate-all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ export async function validate(cwd: string) {
const packages = await getPackages(cwd);

if (config["validate-changesets"] ?? false) {
errors.push(...(await validateChangesets(cwd)));
errors.push(
...(await validateChangesets(cwd, config["forbid-major"] ?? false)),
);
}

if (config["has-api-extractor-config"] ?? false) {
Expand Down
40 changes: 35 additions & 5 deletions packages/alfa-toolchain/src/validation/validate-changesets.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import getChangeSets from "@changesets/read";
import { NewChangeset } from "@changesets/types";
import { Array } from "@siteimprove/alfa-array";
import { None, Option } from "@siteimprove/alfa-option";
import { Err, Result } from "@siteimprove/alfa-result";

import { Changeset } from "../changeset/get-changeset-details";
Expand All @@ -8,9 +11,36 @@ import { Changeset } from "../changeset/get-changeset-details";
*
* @public
*/
export async function validateChangesets(cwd: string): Promise<Array<string>> {
return (await getChangeSets(cwd))
.map(Changeset.getDetails)
.filter<Err<string>>(Result.isErr)
.map((err) => err.getErr());
export async function validateChangesets(
cwd: string,
forbidMajor: boolean = false,
): Promise<Array<string>> {
const errors: Array<string> = [];

const changesets = await getChangeSets(cwd);

errors.push(
...changesets
.map(Changeset.getDetails)
.filter<Err<string>>(Result.isErr)
.map((err) => err.getErr()),
);

if (forbidMajor) {
errors.push(
...Array.collect(changesets, (changeset) =>
isMajor(changeset)
? Option.of(
`Major bumps not allowed while on version 0: ${changeset.id}`,
)
: None,
),
);
}

return errors;
}

function isMajor(changeset: NewChangeset): boolean {
return changeset.releases.some((release) => release.type === "major");
}
2 changes: 2 additions & 0 deletions packages/alfa-toolchain/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
"test/changeset/get-changeset-details.spec.tsx"
],
"references": [
{ "path": "../alfa-array" },
{ "path": "../alfa-option" },
{ "path": "../alfa-result" },
{ "path": "../alfa-test" }
]
Expand Down
2 changes: 2 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1762,6 +1762,8 @@ __metadata:
"@changesets/read": "npm:^0.5.9"
"@changesets/types": "npm:^5.2.1"
"@manypkg/get-packages": "npm:=1.1.3"
"@siteimprove/alfa-array": "workspace:^0.69.0"
"@siteimprove/alfa-option": "workspace:^0.69.0"
"@siteimprove/alfa-result": "workspace:^0.69.0"
"@siteimprove/alfa-test": "workspace:^0.69.0"
"@svitejs/changesets-changelog-github-compact": "npm:^1.1.0"
Expand Down