Skip to content

Commit b76eda7

Browse files
committed
Merge remote-tracking branch 'origin/main' into esm
2 parents 586fbaa + 7ed1955 commit b76eda7

9 files changed

Lines changed: 57 additions & 16 deletions

File tree

.changeset/big-cougars-mate.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"@changesets/action": patch
3+
---
4+
5+
Fix PRs sometimes not getting reopened with `commitMode: github-api`
6+
7+
There was a race-condition that means sometimes existing PRs would not be found,
8+
and new PRs would be opened. This has now been fixed by fetching existing PRs
9+
before making any changes.
10+

.changeset/lemon-garlics-sell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@changesets/action": patch
3+
---
4+
5+
Fixed situations in which `cwd` was specified as a relative path and used with (default) `commitMode: git-cli`
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) Changesets team and other contributors
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"@actions/core": "^1.11.1",
3535
"@actions/exec": "^1.1.1",
3636
"@actions/github": "^6.0.1",
37-
"@changesets/ghcommit": "1.4.0",
37+
"@changesets/ghcommit": "^2.0.0",
3838
"@changesets/pre": "^2.0.2",
3939
"@changesets/read": "^0.6.5",
4040
"@manypkg/get-packages": "^1.1.3",

src/git.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ export class Git {
117117
base: {
118118
commit: github.context.sha,
119119
},
120-
addFromDirectory,
120+
cwd: this.cwd,
121121
force: true,
122122
});
123123
}

src/index.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as core from "@actions/core";
22
import fs from "node:fs/promises";
3+
import path from "node:path";
34
import { Git } from "./git.ts";
45
import { setupOctokit } from "./octokit.ts";
56
import readChangesetState from "./readChangesetState.ts";
@@ -16,12 +17,7 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
1617
return;
1718
}
1819

19-
const inputCwd = getOptionalInput("cwd");
20-
if (inputCwd) {
21-
core.info("changing directory to the one given as the input");
22-
process.chdir(inputCwd);
23-
}
24-
const cwd = inputCwd || process.cwd();
20+
const cwd = path.resolve(getOptionalInput("cwd") ?? "");
2521

2622
const octokit = setupOctokit(githubToken);
2723
const commitMode = getOptionalInput("commitMode") ?? "git-cli";

src/run.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,15 +327,22 @@ export async function runVersion({
327327
!!preState ? ` (${preState.tag})` : ""
328328
}`;
329329

330-
await git.pushChanges({ branch: versionBranch, message: finalCommitMessage });
331-
332-
let existingPullRequests = await octokit.rest.pulls.list({
330+
/**
331+
* Fetch any existing pull requests that are open against the branch,
332+
* before we push any changes that may inadvertently close the existing PRs.
333+
*
334+
* (`@changesets/ghcommit` has to reset the branch to the same commit as the base,
335+
* which GitHub will then react to by closing the PRs)
336+
*/
337+
const existingPullRequests = await octokit.rest.pulls.list({
333338
...github.context.repo,
334339
state: "open",
335340
head: `${github.context.repo.owner}:${versionBranch}`,
336341
base: branch,
337342
});
338-
core.info(JSON.stringify(existingPullRequests.data, null, 2));
343+
core.info(`Existing pull requests: ${JSON.stringify(existingPullRequests.data, null, 2)}`);
344+
345+
await git.pushChanges({ branch: versionBranch, message: finalCommitMessage });
339346

340347
const changedPackagesInfo = (await changedPackagesInfoPromises)
341348
.filter((x) => x)

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,10 @@
212212
resolved "https://registry.yarnpkg.com/@changesets/get-version-range-type/-/get-version-range-type-0.4.0.tgz#429a90410eefef4368502c41c63413e291740bf5"
213213
integrity sha512-hwawtob9DryoGTpixy1D3ZXbGgJu1Rhr+ySH2PvTLHvkZuQ7sRT4oQwMh0hbqZH1weAooedEjRsbrWcGLCeyVQ==
214214

215-
"@changesets/ghcommit@1.4.0":
216-
version "1.4.0"
217-
resolved "https://registry.yarnpkg.com/@changesets/ghcommit/-/ghcommit-1.4.0.tgz#61a8bcdad1e78140ad69b6c6980e9c82471c8993"
218-
integrity sha512-gG4QZsMwply4wFxqjfO7oI70lAb579zRbKB2EgjkVo+olWzXvmcQb52zkLpL3L9+QrAGD0QP8fNER9Wn3CmcHw==
215+
"@changesets/ghcommit@^2.0.0":
216+
version "2.0.0"
217+
resolved "https://registry.yarnpkg.com/@changesets/ghcommit/-/ghcommit-2.0.0.tgz#a3d8f733ad7ec9bb1f17c7dc0b64c3f62636305f"
218+
integrity sha512-UFS7mCjh3B8KfiDQi6JbZNDoANdTqLgBKHCwMASZ25A3yfxaFVKURGzwdMdlcYx5k6dHN1igDHzgXuwOyZ9xKg==
219219
dependencies:
220220
isomorphic-git "^1.27.1"
221221

0 commit comments

Comments
 (0)