mirror of
https://github.com/changesets/action
synced 2026-10-26 16:39:56 +08:00
Compare commits
1
Commits
pr-release
..
v1.7.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6a0a831ff3 |
@@ -1,5 +0,0 @@
|
|||||||
---
|
|
||||||
"@changesets/action": minor
|
|
||||||
---
|
|
||||||
|
|
||||||
Support draft version PR modes with a new `prDraft` input. Use `create` to create new version PRs as drafts, or `always` to also convert existing version PRs back to draft when updating them.
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
---
|
|
||||||
"@changesets/action": patch
|
|
||||||
---
|
|
||||||
|
|
||||||
Fixed initial `.changeset` state being picked up, when `cwd` parameter is provided
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
---
|
|
||||||
"@changesets/action": patch
|
|
||||||
---
|
|
||||||
|
|
||||||
Fixed `.changeset` state being picked for the version command when `cwd` parameter is provided
|
|
||||||
@@ -14,7 +14,6 @@ This action for [Changesets](https://github.com/changesets/changesets) creates a
|
|||||||
- createGithubReleases - A boolean value to indicate whether to create Github releases after `publish` or not. Default to `true`
|
- createGithubReleases - A boolean value to indicate whether to create Github releases after `publish` or not. Default to `true`
|
||||||
- commitMode - Specifies the commit mode. Use `"git-cli"` to push changes using the Git CLI, or `"github-api"` to push changes via the GitHub API. When using `"github-api"`, all commits and tags are GPG-signed and attributed to the user or app who owns the `GITHUB_TOKEN`. Default to `git-cli`.
|
- commitMode - Specifies the commit mode. Use `"git-cli"` to push changes using the Git CLI, or `"github-api"` to push changes via the GitHub API. When using `"github-api"`, all commits and tags are GPG-signed and attributed to the user or app who owns the `GITHUB_TOKEN`. Default to `git-cli`.
|
||||||
- cwd - Changes node's `process.cwd()` if the project is not located on the root. Default to `process.cwd()`
|
- cwd - Changes node's `process.cwd()` if the project is not located on the root. Default to `process.cwd()`
|
||||||
- prDraft - Controls draft PR behavior. Use `create` to create new version PRs as draft, or `always` to also convert existing version PRs back to draft when updating them. By default, version PRs are not forced into draft mode.
|
|
||||||
|
|
||||||
### Outputs
|
### Outputs
|
||||||
|
|
||||||
|
|||||||
@@ -43,9 +43,6 @@ inputs:
|
|||||||
branch:
|
branch:
|
||||||
description: Sets the branch in which the action will run. Default to `github.ref_name` if not provided
|
description: Sets the branch in which the action will run. Default to `github.ref_name` if not provided
|
||||||
required: false
|
required: false
|
||||||
prDraft:
|
|
||||||
description: 'Controls draft PR behavior. Use "create" to create new version PRs as draft, or "always" to also convert existing version PRs back to draft when updating them.'
|
|
||||||
required: false
|
|
||||||
outputs:
|
outputs:
|
||||||
published:
|
published:
|
||||||
description: A boolean value to indicate whether a publishing is happened or not
|
description: A boolean value to indicate whether a publishing is happened or not
|
||||||
|
|||||||
Vendored
+13
-13
File diff suppressed because one or more lines are too long
@@ -1,28 +1,5 @@
|
|||||||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
||||||
|
|
||||||
exports[`version > creates a draft PR when prDraft is "create" 1`] = `
|
|
||||||
[
|
|
||||||
{
|
|
||||||
"base": "some-branch",
|
|
||||||
"body": "This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and publish to npm yourself or [setup this action to publish automatically](https://github.com/changesets/action#with-publishing). If you're not ready to do a release yet, that's fine, whenever you add more changesets to some-branch, this PR will be updated.
|
|
||||||
|
|
||||||
|
|
||||||
# Releases
|
|
||||||
## simple-project-pkg-a@1.1.0
|
|
||||||
|
|
||||||
### Minor Changes
|
|
||||||
|
|
||||||
- Awesome feature
|
|
||||||
",
|
|
||||||
"draft": true,
|
|
||||||
"head": "changeset-release/some-branch",
|
|
||||||
"owner": "changesets",
|
|
||||||
"repo": "action",
|
|
||||||
"title": "Version Packages",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`version > creates simple PR 1`] = `
|
exports[`version > creates simple PR 1`] = `
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
@@ -48,7 +25,6 @@ exports[`version > creates simple PR 1`] = `
|
|||||||
|
|
||||||
- Awesome feature
|
- Awesome feature
|
||||||
",
|
",
|
||||||
"draft": false,
|
|
||||||
"head": "changeset-release/some-branch",
|
"head": "changeset-release/some-branch",
|
||||||
"owner": "changesets",
|
"owner": "changesets",
|
||||||
"repo": "action",
|
"repo": "action",
|
||||||
@@ -67,7 +43,6 @@ exports[`version > does not include any release information if a message with si
|
|||||||
# Releases
|
# Releases
|
||||||
|
|
||||||
> All release information have been omitted from this message, as the content exceeds the size limit.",
|
> All release information have been omitted from this message, as the content exceeds the size limit.",
|
||||||
"draft": false,
|
|
||||||
"head": "changeset-release/some-branch",
|
"head": "changeset-release/some-branch",
|
||||||
"owner": "changesets",
|
"owner": "changesets",
|
||||||
"repo": "action",
|
"repo": "action",
|
||||||
@@ -90,7 +65,6 @@ exports[`version > does not include changelog entries if full message exceeds si
|
|||||||
## simple-project-pkg-a@1.1.0
|
## simple-project-pkg-a@1.1.0
|
||||||
|
|
||||||
",
|
",
|
||||||
"draft": false,
|
|
||||||
"head": "changeset-release/some-branch",
|
"head": "changeset-release/some-branch",
|
||||||
"owner": "changesets",
|
"owner": "changesets",
|
||||||
"repo": "action",
|
"repo": "action",
|
||||||
@@ -113,7 +87,6 @@ exports[`version > doesn't include ignored package that got a dependency update
|
|||||||
|
|
||||||
- Awesome feature
|
- Awesome feature
|
||||||
",
|
",
|
||||||
"draft": false,
|
|
||||||
"head": "changeset-release/some-branch",
|
"head": "changeset-release/some-branch",
|
||||||
"owner": "changesets",
|
"owner": "changesets",
|
||||||
"repo": "action",
|
"repo": "action",
|
||||||
@@ -136,7 +109,6 @@ exports[`version > only includes bumped packages in the PR body 1`] = `
|
|||||||
|
|
||||||
- Awesome feature
|
- Awesome feature
|
||||||
",
|
",
|
||||||
"draft": false,
|
|
||||||
"head": "changeset-release/some-branch",
|
"head": "changeset-release/some-branch",
|
||||||
"owner": "changesets",
|
"owner": "changesets",
|
||||||
"repo": "action",
|
"repo": "action",
|
||||||
@@ -144,94 +116,3 @@ exports[`version > only includes bumped packages in the PR body 1`] = `
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`version > updates an existing PR via GraphQL and converts it to draft when prDraft is "always" 1`] = `
|
|
||||||
[
|
|
||||||
"
|
|
||||||
mutation UpdatePullRequest(
|
|
||||||
$pullRequestId: ID!
|
|
||||||
$title: String!
|
|
||||||
$body: String!
|
|
||||||
) {
|
|
||||||
|
|
||||||
convertPullRequestToDraft(
|
|
||||||
input: {
|
|
||||||
pullRequestId: $pullRequestId
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
pullRequest {
|
|
||||||
id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
updatePullRequest(
|
|
||||||
input: {
|
|
||||||
pullRequestId: $pullRequestId
|
|
||||||
title: $title
|
|
||||||
body: $body
|
|
||||||
state: OPEN
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
pullRequest {
|
|
||||||
id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
",
|
|
||||||
{
|
|
||||||
"body": "This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and publish to npm yourself or [setup this action to publish automatically](https://github.com/changesets/action#with-publishing). If you're not ready to do a release yet, that's fine, whenever you add more changesets to some-branch, this PR will be updated.
|
|
||||||
|
|
||||||
|
|
||||||
# Releases
|
|
||||||
## simple-project-pkg-a@1.1.0
|
|
||||||
|
|
||||||
### Minor Changes
|
|
||||||
|
|
||||||
- Awesome feature
|
|
||||||
",
|
|
||||||
"pullRequestId": "PR_kwDOA",
|
|
||||||
"title": "Version Packages",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`version > updates an existing PR via GraphQL without converting it to draft when prDraft is "create" 1`] = `
|
|
||||||
[
|
|
||||||
"
|
|
||||||
mutation UpdatePullRequest(
|
|
||||||
$pullRequestId: ID!
|
|
||||||
$title: String!
|
|
||||||
$body: String!
|
|
||||||
) {
|
|
||||||
|
|
||||||
|
|
||||||
updatePullRequest(
|
|
||||||
input: {
|
|
||||||
pullRequestId: $pullRequestId
|
|
||||||
title: $title
|
|
||||||
body: $body
|
|
||||||
state: OPEN
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
pullRequest {
|
|
||||||
id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
",
|
|
||||||
{
|
|
||||||
"body": "This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and publish to npm yourself or [setup this action to publish automatically](https://github.com/changesets/action#with-publishing). If you're not ready to do a release yet, that's fine, whenever you add more changesets to some-branch, this PR will be updated.
|
|
||||||
|
|
||||||
|
|
||||||
# Releases
|
|
||||||
## simple-project-pkg-a@1.1.0
|
|
||||||
|
|
||||||
### Minor Changes
|
|
||||||
|
|
||||||
- Awesome feature
|
|
||||||
",
|
|
||||||
"pullRequestId": "PR_kwDOA",
|
|
||||||
"title": "Version Packages",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
`;
|
|
||||||
|
|||||||
+1
-9
@@ -20,19 +20,13 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
|
|||||||
}
|
}
|
||||||
|
|
||||||
const cwd = path.resolve(getOptionalInput("cwd") ?? "");
|
const cwd = path.resolve(getOptionalInput("cwd") ?? "");
|
||||||
core.info(`using resolved cwd: ${cwd}`);
|
|
||||||
|
|
||||||
const octokit = setupOctokit(githubToken);
|
const octokit = setupOctokit(githubToken);
|
||||||
const commitMode = getOptionalInput("commitMode") ?? "git-cli";
|
const commitMode = getOptionalInput("commitMode") ?? "git-cli";
|
||||||
const prDraft = getOptionalInput("prDraft");
|
|
||||||
if (commitMode !== "git-cli" && commitMode !== "github-api") {
|
if (commitMode !== "git-cli" && commitMode !== "github-api") {
|
||||||
core.setFailed(`Invalid commit mode: ${commitMode}`);
|
core.setFailed(`Invalid commit mode: ${commitMode}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (prDraft !== undefined && prDraft !== "always" && prDraft !== "create") {
|
|
||||||
core.setFailed(`Invalid prDraft: ${prDraft}`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const git = new Git({
|
const git = new Git({
|
||||||
octokit: commitMode === "github-api" ? octokit : undefined,
|
octokit: commitMode === "github-api" ? octokit : undefined,
|
||||||
cwd,
|
cwd,
|
||||||
@@ -51,7 +45,7 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
|
|||||||
`machine github.com\nlogin github-actions[bot]\npassword ${githubToken}`
|
`machine github.com\nlogin github-actions[bot]\npassword ${githubToken}`
|
||||||
);
|
);
|
||||||
|
|
||||||
let { changesets } = await readChangesetState(cwd);
|
let { changesets } = await readChangesetState();
|
||||||
|
|
||||||
let publishScript = core.getInput("publish");
|
let publishScript = core.getInput("publish");
|
||||||
let hasChangesets = changesets.length !== 0;
|
let hasChangesets = changesets.length !== 0;
|
||||||
@@ -148,11 +142,9 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
|
|||||||
githubToken,
|
githubToken,
|
||||||
git,
|
git,
|
||||||
octokit,
|
octokit,
|
||||||
cwd,
|
|
||||||
prTitle: getOptionalInput("title"),
|
prTitle: getOptionalInput("title"),
|
||||||
commitMessage: getOptionalInput("commit"),
|
commitMessage: getOptionalInput("commit"),
|
||||||
hasPublishScript,
|
hasPublishScript,
|
||||||
prDraft,
|
|
||||||
branch: getOptionalInput("branch"),
|
branch: getOptionalInput("branch"),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
-106
@@ -19,7 +19,6 @@ vi.mock("@actions/github", () => ({
|
|||||||
},
|
},
|
||||||
getOctokit: () => ({
|
getOctokit: () => ({
|
||||||
rest: mockedGithubMethods,
|
rest: mockedGithubMethods,
|
||||||
graphql: mockedGraphql,
|
|
||||||
}),
|
}),
|
||||||
}));
|
}));
|
||||||
vi.mock("./git.ts");
|
vi.mock("./git.ts");
|
||||||
@@ -34,7 +33,6 @@ let mockedGithubMethods = {
|
|||||||
createRelease: vi.fn(),
|
createRelease: vi.fn(),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
let mockedGraphql = vi.fn();
|
|
||||||
|
|
||||||
let f = fixturez(import.meta.dirname);
|
let f = fixturez(import.meta.dirname);
|
||||||
|
|
||||||
@@ -92,42 +90,6 @@ describe("version", () => {
|
|||||||
expect(mockedGithubMethods.pulls.create.mock.calls[0]).toMatchSnapshot();
|
expect(mockedGithubMethods.pulls.create.mock.calls[0]).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('creates a draft PR when prDraft is "create"', async () => {
|
|
||||||
let cwd = f.copy("simple-project");
|
|
||||||
await linkNodeModules(cwd);
|
|
||||||
|
|
||||||
mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({ data: [] }));
|
|
||||||
|
|
||||||
mockedGithubMethods.pulls.create.mockImplementationOnce(() => ({
|
|
||||||
data: { number: 123 },
|
|
||||||
}));
|
|
||||||
|
|
||||||
await writeChangesets(
|
|
||||||
[
|
|
||||||
{
|
|
||||||
releases: [
|
|
||||||
{
|
|
||||||
name: "simple-project-pkg-a",
|
|
||||||
type: "minor",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
summary: "Awesome feature",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
cwd
|
|
||||||
);
|
|
||||||
|
|
||||||
await runVersion({
|
|
||||||
octokit: setupOctokit("@@GITHUB_TOKEN"),
|
|
||||||
githubToken: "@@GITHUB_TOKEN",
|
|
||||||
git: new Git({ cwd }),
|
|
||||||
cwd,
|
|
||||||
prDraft: "create",
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(mockedGithubMethods.pulls.create.mock.calls[0]).toMatchSnapshot();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("only includes bumped packages in the PR body", async () => {
|
it("only includes bumped packages in the PR body", async () => {
|
||||||
let cwd = f.copy("simple-project");
|
let cwd = f.copy("simple-project");
|
||||||
await linkNodeModules(cwd);
|
await linkNodeModules(cwd);
|
||||||
@@ -315,72 +277,4 @@ fluminis divesque vulnere aquis parce lapsis rabie si visa fulmineis.
|
|||||||
/All release information have been omitted from this message, as the content exceeds the size limit/
|
/All release information have been omitted from this message, as the content exceeds the size limit/
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('updates an existing PR via GraphQL without converting it to draft when prDraft is "create"', async () => {
|
|
||||||
let cwd = f.copy("simple-project");
|
|
||||||
await linkNodeModules(cwd);
|
|
||||||
|
|
||||||
mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({
|
|
||||||
data: [{ number: 123, node_id: "PR_kwDOA" }],
|
|
||||||
}));
|
|
||||||
|
|
||||||
await writeChangesets(
|
|
||||||
[
|
|
||||||
{
|
|
||||||
releases: [
|
|
||||||
{
|
|
||||||
name: "simple-project-pkg-a",
|
|
||||||
type: "minor",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
summary: "Awesome feature",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
cwd
|
|
||||||
);
|
|
||||||
|
|
||||||
await runVersion({
|
|
||||||
octokit: setupOctokit("@@GITHUB_TOKEN"),
|
|
||||||
githubToken: "@@GITHUB_TOKEN",
|
|
||||||
git: new Git({ cwd }),
|
|
||||||
cwd,
|
|
||||||
prDraft: "create",
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(mockedGraphql.mock.calls[0]).toMatchSnapshot();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('updates an existing PR via GraphQL and converts it to draft when prDraft is "always"', async () => {
|
|
||||||
let cwd = f.copy("simple-project");
|
|
||||||
await linkNodeModules(cwd);
|
|
||||||
|
|
||||||
mockedGithubMethods.pulls.list.mockImplementationOnce(() => ({
|
|
||||||
data: [{ number: 123, node_id: "PR_kwDOA" }],
|
|
||||||
}));
|
|
||||||
|
|
||||||
await writeChangesets(
|
|
||||||
[
|
|
||||||
{
|
|
||||||
releases: [
|
|
||||||
{
|
|
||||||
name: "simple-project-pkg-a",
|
|
||||||
type: "minor",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
summary: "Awesome feature",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
cwd
|
|
||||||
);
|
|
||||||
|
|
||||||
await runVersion({
|
|
||||||
octokit: setupOctokit("@@GITHUB_TOKEN"),
|
|
||||||
githubToken: "@@GITHUB_TOKEN",
|
|
||||||
git: new Git({ cwd }),
|
|
||||||
cwd,
|
|
||||||
prDraft: "always",
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(mockedGraphql.mock.calls[0]).toMatchSnapshot();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
+4
-41
@@ -259,7 +259,6 @@ type VersionOptions = {
|
|||||||
commitMessage?: string;
|
commitMessage?: string;
|
||||||
hasPublishScript?: boolean;
|
hasPublishScript?: boolean;
|
||||||
prBodyMaxCharacters?: number;
|
prBodyMaxCharacters?: number;
|
||||||
prDraft?: "always" | "create";
|
|
||||||
branch?: string;
|
branch?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -278,7 +277,6 @@ export async function runVersion({
|
|||||||
hasPublishScript = false,
|
hasPublishScript = false,
|
||||||
prBodyMaxCharacters = MAX_CHARACTERS_PER_MESSAGE,
|
prBodyMaxCharacters = MAX_CHARACTERS_PER_MESSAGE,
|
||||||
branch = github.context.ref.replace("refs/heads/", ""),
|
branch = github.context.ref.replace("refs/heads/", ""),
|
||||||
prDraft,
|
|
||||||
}: VersionOptions): Promise<RunVersionResult> {
|
}: VersionOptions): Promise<RunVersionResult> {
|
||||||
let versionBranch = `changeset-release/${branch}`;
|
let versionBranch = `changeset-release/${branch}`;
|
||||||
|
|
||||||
@@ -378,7 +376,6 @@ export async function runVersion({
|
|||||||
head: versionBranch,
|
head: versionBranch,
|
||||||
title: finalPrTitle,
|
title: finalPrTitle,
|
||||||
body: prBody,
|
body: prBody,
|
||||||
draft: prDraft !== undefined,
|
|
||||||
...github.context.repo,
|
...github.context.repo,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -389,46 +386,12 @@ export async function runVersion({
|
|||||||
const [pullRequest] = existingPullRequests.data;
|
const [pullRequest] = existingPullRequests.data;
|
||||||
|
|
||||||
core.info(`updating found pull request #${pullRequest.number}`);
|
core.info(`updating found pull request #${pullRequest.number}`);
|
||||||
const convertPullRequestToDraftMutation =
|
await octokit.rest.pulls.update({
|
||||||
prDraft === "always"
|
pull_number: pullRequest.number,
|
||||||
? `
|
|
||||||
convertPullRequestToDraft(
|
|
||||||
input: {
|
|
||||||
pullRequestId: $pullRequestId
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
pullRequest {
|
|
||||||
id
|
|
||||||
}
|
|
||||||
}`
|
|
||||||
: "";
|
|
||||||
const updatePullRequestMutation = `
|
|
||||||
mutation UpdatePullRequest(
|
|
||||||
$pullRequestId: ID!
|
|
||||||
$title: String!
|
|
||||||
$body: String!
|
|
||||||
) {
|
|
||||||
${convertPullRequestToDraftMutation}
|
|
||||||
|
|
||||||
updatePullRequest(
|
|
||||||
input: {
|
|
||||||
pullRequestId: $pullRequestId
|
|
||||||
title: $title
|
|
||||||
body: $body
|
|
||||||
state: OPEN
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
pullRequest {
|
|
||||||
id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
await octokit.graphql(updatePullRequestMutation, {
|
|
||||||
pullRequestId: pullRequest.node_id,
|
|
||||||
title: finalPrTitle,
|
title: finalPrTitle,
|
||||||
body: prBody,
|
body: prBody,
|
||||||
|
...github.context.repo,
|
||||||
|
state: "open",
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user