From e15ca88fafae724a25f338c5c7f5b709460050c1 Mon Sep 17 00:00:00 2001 From: Sam Lanning Date: Mon, 12 May 2025 18:44:48 +0100 Subject: [PATCH 1/3] fix: use latest ghcommit and fix cwd for git-cli - `cwd` was not working correctly when commitMode was set to `git-cli`, as it was attempting to resolve the `cwd` twice. (This problem only occured when specifying a relative path for `cwd`.) - Update `ghcommit`, and avoid calling `process.chdir()` to change the working directory. Instead, we now pass the `cwd` option everywhere. fixes #475 --- .changeset/lemon-garlics-sell.md | 9 +++++++++ .changeset/sour-elephants-switch.md | 7 +++++++ package.json | 2 +- src/git.ts | 2 +- src/index.ts | 7 ++----- yarn.lock | 8 ++++---- 6 files changed, 24 insertions(+), 11 deletions(-) create mode 100644 .changeset/lemon-garlics-sell.md create mode 100644 .changeset/sour-elephants-switch.md diff --git a/.changeset/lemon-garlics-sell.md b/.changeset/lemon-garlics-sell.md new file mode 100644 index 00000000..db971be3 --- /dev/null +++ b/.changeset/lemon-garlics-sell.md @@ -0,0 +1,9 @@ +--- +"@changesets/action": patch +--- + +fix: cwd now works again with relative paths and commitMode: git-cli + +v1.5.2 introduced a bug where specifying `cwd` +when using the default `commitMode` would break things, +as it tried to resolve the path twice. \ No newline at end of file diff --git a/.changeset/sour-elephants-switch.md b/.changeset/sour-elephants-switch.md new file mode 100644 index 00000000..3d899860 --- /dev/null +++ b/.changeset/sour-elephants-switch.md @@ -0,0 +1,7 @@ +--- +"@changesets/action": patch +--- + +Update @changesets/ghcommit, and avoid calling `process.chdir()` + +fixes #475 diff --git a/package.json b/package.json index a2e61e96..1ac8855f 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "@actions/core": "^1.11.1", "@actions/exec": "^1.1.1", "@actions/github": "^6.0.1", - "@changesets/ghcommit": "1.4.0", + "@changesets/ghcommit": "^2.0.0", "@changesets/pre": "^1.0.9", "@changesets/read": "^0.5.3", "@manypkg/get-packages": "^1.1.3", diff --git a/src/git.ts b/src/git.ts index de313afc..82c50544 100644 --- a/src/git.ts +++ b/src/git.ts @@ -117,7 +117,7 @@ export class Git { base: { commit: github.context.sha, }, - addFromDirectory, + cwd: this.cwd, force: true, }); } diff --git a/src/index.ts b/src/index.ts index c5b0dc92..1369839c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,6 +4,7 @@ import { Git } from "./git"; import { setupOctokit } from "./octokit"; import readChangesetState from "./readChangesetState"; import { runPublish, runVersion } from "./run"; +import { resolve } from "path"; const getOptionalInput = (name: string) => core.getInput(name) || undefined; @@ -16,11 +17,7 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined; } const inputCwd = getOptionalInput("cwd"); - if (inputCwd) { - core.info("changing directory to the one given as the input"); - process.chdir(inputCwd); - } - const cwd = inputCwd || process.cwd(); + const cwd = inputCwd ? resolve(inputCwd) : process.cwd(); const octokit = setupOctokit(githubToken); const commitMode = getOptionalInput("commitMode") ?? "git-cli"; diff --git a/yarn.lock b/yarn.lock index ff294486..b7f16cd6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -219,10 +219,10 @@ resolved "https://registry.yarnpkg.com/@changesets/get-version-range-type/-/get-version-range-type-0.3.2.tgz#8131a99035edd11aa7a44c341cbb05e668618c67" integrity sha512-SVqwYs5pULYjYT4op21F2pVbcrca4qA/bAA3FmFXKMN7Y+HcO8sbZUTx3TAy2VXulP2FACd1aC7f2nTuqSPbqg== -"@changesets/ghcommit@1.4.0": - version "1.4.0" - resolved "https://registry.yarnpkg.com/@changesets/ghcommit/-/ghcommit-1.4.0.tgz#61a8bcdad1e78140ad69b6c6980e9c82471c8993" - integrity sha512-gG4QZsMwply4wFxqjfO7oI70lAb579zRbKB2EgjkVo+olWzXvmcQb52zkLpL3L9+QrAGD0QP8fNER9Wn3CmcHw== +"@changesets/ghcommit@^2.0.0": + version "2.0.0" + resolved "https://registry.yarnpkg.com/@changesets/ghcommit/-/ghcommit-2.0.0.tgz#a3d8f733ad7ec9bb1f17c7dc0b64c3f62636305f" + integrity sha512-UFS7mCjh3B8KfiDQi6JbZNDoANdTqLgBKHCwMASZ25A3yfxaFVKURGzwdMdlcYx5k6dHN1igDHzgXuwOyZ9xKg== dependencies: isomorphic-git "^1.27.1" From 0c3b8682678e36a7135f411715e75cdab4e7e900 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Thu, 15 May 2025 21:52:46 +0200 Subject: [PATCH 2/3] simplify --- src/index.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index b108b6e1..7aa4c559 100644 --- a/src/index.ts +++ b/src/index.ts @@ -17,8 +17,7 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined; return; } - const inputCwd = getOptionalInput("cwd"); - const cwd = inputCwd ? path.resolve(inputCwd) : process.cwd(); + const cwd = path.resolve(getOptionalInput("cwd") ?? ""); const octokit = setupOctokit(githubToken); const commitMode = getOptionalInput("commitMode") ?? "git-cli"; From 4924a424d2c8f4b7eb8a3b6181f4cb9763dd98bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Fri, 16 May 2025 11:24:46 +0200 Subject: [PATCH 3/3] Apply suggestions from code review --- .changeset/lemon-garlics-sell.md | 6 +----- .changeset/sour-elephants-switch.md | 5 ----- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/.changeset/lemon-garlics-sell.md b/.changeset/lemon-garlics-sell.md index db971be3..e892bc61 100644 --- a/.changeset/lemon-garlics-sell.md +++ b/.changeset/lemon-garlics-sell.md @@ -2,8 +2,4 @@ "@changesets/action": patch --- -fix: cwd now works again with relative paths and commitMode: git-cli - -v1.5.2 introduced a bug where specifying `cwd` -when using the default `commitMode` would break things, -as it tried to resolve the path twice. \ No newline at end of file +Fixed situations in which `cwd` was specified as a relative path and used with (default) `commitMode: git-cli` diff --git a/.changeset/sour-elephants-switch.md b/.changeset/sour-elephants-switch.md index 3d899860..a845151c 100644 --- a/.changeset/sour-elephants-switch.md +++ b/.changeset/sour-elephants-switch.md @@ -1,7 +1,2 @@ --- -"@changesets/action": patch --- - -Update @changesets/ghcommit, and avoid calling `process.chdir()` - -fixes #475