Fixed situations in which cwd was specified as a relative path and used with (default) commitMode: git-cli (#486)

* 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

* simplify

* Apply suggestions from code review

---------

Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
This commit is contained in:
Sam Lanning
2025-05-16 11:25:00 +02:00
committed by GitHub
co-authored by Mateusz Burzyński
parent 9690d7b6f2
commit 7ed1955546
6 changed files with 15 additions and 12 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@changesets/action": patch
---
Fixed situations in which `cwd` was specified as a relative path and used with (default) `commitMode: git-cli`
+2
View File
@@ -0,0 +1,2 @@
---
---
+1 -1
View File
@@ -33,7 +33,7 @@
"@actions/core": "^1.11.1", "@actions/core": "^1.11.1",
"@actions/exec": "^1.1.1", "@actions/exec": "^1.1.1",
"@actions/github": "^6.0.1", "@actions/github": "^6.0.1",
"@changesets/ghcommit": "1.4.0", "@changesets/ghcommit": "^2.0.0",
"@changesets/pre": "^1.0.9", "@changesets/pre": "^1.0.9",
"@changesets/read": "^0.5.3", "@changesets/read": "^0.5.3",
"@manypkg/get-packages": "^1.1.3", "@manypkg/get-packages": "^1.1.3",
+1 -1
View File
@@ -117,7 +117,7 @@ export class Git {
base: { base: {
commit: github.context.sha, commit: github.context.sha,
}, },
addFromDirectory, cwd: this.cwd,
force: true, force: true,
}); });
} }
+2 -6
View File
@@ -1,5 +1,6 @@
import * as core from "@actions/core"; import * as core from "@actions/core";
import fs from "node:fs/promises"; import fs from "node:fs/promises";
import path from "node:path";
import { Git } from "./git"; import { Git } from "./git";
import { setupOctokit } from "./octokit"; import { setupOctokit } from "./octokit";
import readChangesetState from "./readChangesetState"; import readChangesetState from "./readChangesetState";
@@ -16,12 +17,7 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
return; return;
} }
const inputCwd = getOptionalInput("cwd"); const cwd = path.resolve(getOptionalInput("cwd") ?? "");
if (inputCwd) {
core.info("changing directory to the one given as the input");
process.chdir(inputCwd);
}
const cwd = inputCwd || process.cwd();
const octokit = setupOctokit(githubToken); const octokit = setupOctokit(githubToken);
const commitMode = getOptionalInput("commitMode") ?? "git-cli"; const commitMode = getOptionalInput("commitMode") ?? "git-cli";
+4 -4
View File
@@ -219,10 +219,10 @@
resolved "https://registry.yarnpkg.com/@changesets/get-version-range-type/-/get-version-range-type-0.3.2.tgz#8131a99035edd11aa7a44c341cbb05e668618c67" resolved "https://registry.yarnpkg.com/@changesets/get-version-range-type/-/get-version-range-type-0.3.2.tgz#8131a99035edd11aa7a44c341cbb05e668618c67"
integrity sha512-SVqwYs5pULYjYT4op21F2pVbcrca4qA/bAA3FmFXKMN7Y+HcO8sbZUTx3TAy2VXulP2FACd1aC7f2nTuqSPbqg== integrity sha512-SVqwYs5pULYjYT4op21F2pVbcrca4qA/bAA3FmFXKMN7Y+HcO8sbZUTx3TAy2VXulP2FACd1aC7f2nTuqSPbqg==
"@changesets/ghcommit@1.4.0": "@changesets/ghcommit@^2.0.0":
version "1.4.0" version "2.0.0"
resolved "https://registry.yarnpkg.com/@changesets/ghcommit/-/ghcommit-1.4.0.tgz#61a8bcdad1e78140ad69b6c6980e9c82471c8993" resolved "https://registry.yarnpkg.com/@changesets/ghcommit/-/ghcommit-2.0.0.tgz#a3d8f733ad7ec9bb1f17c7dc0b64c3f62636305f"
integrity sha512-gG4QZsMwply4wFxqjfO7oI70lAb579zRbKB2EgjkVo+olWzXvmcQb52zkLpL3L9+QrAGD0QP8fNER9Wn3CmcHw== integrity sha512-UFS7mCjh3B8KfiDQi6JbZNDoANdTqLgBKHCwMASZ25A3yfxaFVKURGzwdMdlcYx5k6dHN1igDHzgXuwOyZ9xKg==
dependencies: dependencies:
isomorphic-git "^1.27.1" isomorphic-git "^1.27.1"