-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aef9ab7
commit f3e7536
Showing
10 changed files
with
383 additions
and
76 deletions.
There are no files selected for viewing
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,5 @@ | ||
--- | ||
"@osdk/tool.release": minor | ||
--- | ||
|
||
Prevent publishing patch from main and minor/major from release |
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,22 @@ | ||
/* | ||
* Copyright 2024 Palantir Technologies, Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
export class FailedWithUserMessage extends Error { | ||
constructor(message: string) { | ||
super(message); | ||
this.name = "FailedWithUserMessage"; | ||
} | ||
} |
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,103 @@ | ||
/* | ||
* Copyright 2024 Palantir Technologies, Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import type { ReleasePlan } from "@changesets/types"; | ||
import { describe, expect, it } from "vitest"; | ||
import { mutateReleasePlan } from "./mutateReleasePlan.js"; | ||
|
||
describe(mutateReleasePlan, () => { | ||
describe("for main", () => { | ||
it("promotes patches to minor", () => { | ||
const plan: ReleasePlan = { | ||
changesets: [ | ||
{ | ||
id: "5", | ||
releases: [ | ||
{ name: "foo", type: "patch" }, | ||
], | ||
summary: "foo summary", | ||
}, | ||
], | ||
preState: undefined, | ||
releases: [ | ||
{ | ||
changesets: ["5"], | ||
oldVersion: "2.1.3", | ||
newVersion: "2.1.4", | ||
name: "foo", | ||
type: "patch", | ||
}, | ||
], | ||
}; | ||
|
||
mutateReleasePlan(plan, "main"); | ||
|
||
expect(plan).toEqual({ | ||
changesets: [ | ||
{ | ||
id: "5", | ||
releases: [ | ||
{ name: "foo", type: "minor" }, | ||
], | ||
summary: "foo summary", | ||
}, | ||
], | ||
preState: undefined, | ||
releases: [ | ||
{ | ||
changesets: ["5"], | ||
oldVersion: "2.1.3", | ||
newVersion: "2.2.0", | ||
name: "foo", | ||
type: "minor", | ||
}, | ||
], | ||
}); | ||
}); | ||
}); | ||
|
||
describe("for patch", () => { | ||
it("fails to demote minor and major to patch", () => { | ||
const plan: ReleasePlan = { | ||
changesets: [ | ||
{ | ||
id: "5", | ||
releases: [ | ||
{ name: "foo", type: "minor" }, | ||
], | ||
summary: "foo summary", | ||
}, | ||
], | ||
preState: undefined, | ||
releases: [ | ||
{ | ||
changesets: ["5"], | ||
oldVersion: "2.1.3", | ||
newVersion: "2.1.4", | ||
name: "foo", | ||
type: "minor", | ||
}, | ||
], | ||
}; | ||
|
||
expect(() => { | ||
mutateReleasePlan(plan, "patch"); | ||
}).toThrowErrorMatchingInlineSnapshot( | ||
`[FailedWithUserMessage: Releasing requires converting a minor to a patch, but that may not be safe.]`, | ||
); | ||
}); | ||
}); | ||
}); |
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,46 @@ | ||
/* | ||
* Copyright 2024 Palantir Technologies, Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import type { ReleasePlan } from "@changesets/types"; | ||
import { inc } from "semver"; | ||
import { FailedWithUserMessage } from "./FailedWithUserMessage.js"; | ||
|
||
export function mutateReleasePlan( | ||
releasePlan: ReleasePlan, | ||
releaseType: "patch" | "main", | ||
) { | ||
for (const changeSet of releasePlan.changesets) { | ||
for (const release of changeSet.releases) { | ||
if (releaseType === "main" && release.type === "patch") { | ||
release.type = "minor"; | ||
} else if ( | ||
releaseType === "patch" && (release.type !== "patch") | ||
&& (release.type !== "none") | ||
) { | ||
throw new FailedWithUserMessage( | ||
`Releasing requires converting a ${release.type} to a patch, but that may not be safe.`, | ||
); | ||
} | ||
} | ||
} | ||
|
||
for (const q of releasePlan.releases) { | ||
if (releaseType === "main" && q.type === "patch") { | ||
q.type = "minor"; | ||
q.newVersion = inc(q.oldVersion, "minor")!; | ||
} | ||
} | ||
} |
Oops, something went wrong.