diff --git a/.changeset/silent-schools-bathe.md b/.changeset/silent-schools-bathe.md new file mode 100644 index 0000000..d6525be --- /dev/null +++ b/.changeset/silent-schools-bathe.md @@ -0,0 +1,5 @@ +--- +"@changesets/action": minor +--- + +Add a `cwd` input to the root action, `/select-mode`, `/version`, `/pack`, and `/publish` sub-actions to set the current working directory to execute Changesets in. This input existed in v1 but was incorrectly removed. diff --git a/README.md b/README.md index 4b724e7..18784fb 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,7 @@ If using [trusted publishing](https://docs.npmjs.com/trusted-publishers), it's r | `create-github-releases` | Whether to create Github releases after publish | | `push-git-tags` | Whether to create git tags after publish. If `create-github-releases` is set to `true`, this option will also always be `true`. | | `push-with-git-cli` | Whether to use the Git CLI instead of the GitHub API to push release commits and tags. Defaults to `false`. When using the GitHub API, commits and tags are signed using GitHub's GPG key and attributed to the user or app that owns the `github-token`. | +| `cwd` | The working directory to execute Changesets in. Defaults to the root of the repository. | | Outputs | Description | | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ | diff --git a/action.yml b/action.yml index e19c373..e358500 100644 --- a/action.yml +++ b/action.yml @@ -47,6 +47,9 @@ inputs: GitHub's GPG key and attributed to the user or app that owns the `github-token`. required: false default: false + cwd: + description: "The working directory to execute Changesets in. Defaults to the root of the repository." + required: false outputs: published: description: A "true" or "false" string value to indicate whether a publishing is happened or not diff --git a/pack/README.md b/pack/README.md index ee7709d..178ac36 100644 --- a/pack/README.md +++ b/pack/README.md @@ -17,9 +17,10 @@ This action packs publishable packages into tarballs, complements [changesets/ac -| Inputs | Description | -| -------------------------- | --------------------------------------------------------------------- | -| `publish-plan-artifact-id` | Artifact id for a publish plan generated by the select-mode subaction | +| Inputs | Description | +| -------------------------- | --------------------------------------------------------------------------------------- | +| `publish-plan-artifact-id` | Artifact id for a publish plan generated by the select-mode subaction | +| `cwd` | The working directory to execute Changesets in. Defaults to the root of the repository. | | Outputs | Description | | ---------------------- | ------------------------------------------- | diff --git a/pack/action.yml b/pack/action.yml index eceb353..ad5b733 100644 --- a/pack/action.yml +++ b/pack/action.yml @@ -7,6 +7,9 @@ inputs: publish-plan-artifact-id: description: "Artifact id for a publish plan generated by the select-mode subaction" required: false + cwd: + description: "The working directory to execute Changesets in. Defaults to the root of the repository." + required: false outputs: pack-dir-artifact-id: description: "Artifact id for the packed output directory" diff --git a/publish/README.md b/publish/README.md index a8148f2..e0cacc3 100644 --- a/publish/README.md +++ b/publish/README.md @@ -25,6 +25,7 @@ This action publishes packages to npm. | `pack-dir-artifact-id` | Artifact id for packed publish output generated by the pack subaction | | `create-github-releases` | Whether to create Github releases after publish | | `push-git-tags` | Whether to create git tags after publish. If `create-github-releases` is set to `true`, this option will also always be `true`. | +| `cwd` | The working directory to execute Changesets in. Defaults to the root of the repository. | | Outputs | Description | | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ | diff --git a/publish/action.yml b/publish/action.yml index 511fb7a..580d9dd 100644 --- a/publish/action.yml +++ b/publish/action.yml @@ -26,6 +26,9 @@ inputs: this option will also always be `true`. required: false default: true + cwd: + description: "The working directory to execute Changesets in. Defaults to the root of the repository." + required: false outputs: published: description: A "true" or "false" string value to indicate whether a publishing has happened or not diff --git a/select-mode/README.md b/select-mode/README.md index 3b7abc4..668b33c 100644 --- a/select-mode/README.md +++ b/select-mode/README.md @@ -20,7 +20,9 @@ This action selects the mode to run a Changesets workflow: -Inputs: _none_ +| Inputs | Description | +| ------ | --------------------------------------------------------------------------------------- | +| `cwd` | The working directory to execute Changesets in. Defaults to the root of the repository. | | Outputs | Description | | -------------------------- | ---------------------------------------------------------------------------- | diff --git a/select-mode/action.yml b/select-mode/action.yml index c03d8a2..7dccb5b 100644 --- a/select-mode/action.yml +++ b/select-mode/action.yml @@ -3,7 +3,10 @@ description: Whether to version or publish in the current repo state runs: using: node24 main: ../dist/select-mode.js -inputs: {} +inputs: + cwd: + description: "The working directory to execute Changesets in. Defaults to the root of the repository." + required: false outputs: mode: description: "The mode to use for the current repo state: 'version', 'publish', or 'none'." diff --git a/src/index.ts b/src/index.ts index 14420bf..556506a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -11,8 +11,7 @@ import { } from "./utils.ts"; (async () => { - // If the user needs to change the cwd, set `working-directory` in the step instead - const cwd = process.cwd(); + const cwd = getOptionalInput("cwd") || process.cwd(); await validateChangesetsCliVersion(cwd); throwOnRenamedInputs({ diff --git a/src/pack/index.ts b/src/pack/index.ts index ae4ed1b..5ab50d8 100644 --- a/src/pack/index.ts +++ b/src/pack/index.ts @@ -17,8 +17,7 @@ try { } async function main() { - // If the user needs to change the cwd, set `working-directory` in the step instead - const cwd = process.cwd(); + const cwd = getOptionalInput("cwd") || process.cwd(); await validateChangesetsCliVersion(cwd); const publishPlanArtifactId = getOptionalInput("publish-plan-artifact-id"); diff --git a/src/publish/index.ts b/src/publish/index.ts index 308c93c..5fc60c3 100644 --- a/src/publish/index.ts +++ b/src/publish/index.ts @@ -17,8 +17,7 @@ try { } async function main() { - // If the user needs to change the cwd, set `working-directory` in the step instead - const cwd = process.cwd(); + const cwd = getOptionalInput("cwd") || process.cwd(); await validateChangesetsCliVersion(cwd); const githubToken = getRequiredInput("github-token"); diff --git a/src/select-mode/index.ts b/src/select-mode/index.ts index 396aa2e..61514fc 100644 --- a/src/select-mode/index.ts +++ b/src/select-mode/index.ts @@ -4,7 +4,11 @@ import path from "node:path"; import artifact from "@actions/artifact"; import * as core from "@actions/core"; import readChangesetState from "../readChangesetState.ts"; -import { execChangesetsCli, validateChangesetsCliVersion } from "../utils.ts"; +import { + execChangesetsCli, + getOptionalInput, + validateChangesetsCliVersion, +} from "../utils.ts"; type ModeResult = | { @@ -27,7 +31,7 @@ try { } async function main() { - const cwd = process.cwd(); + const cwd = getOptionalInput("cwd") || process.cwd(); await validateChangesetsCliVersion(cwd); const result = await getMode(cwd); diff --git a/src/version/index.ts b/src/version/index.ts index bf7d3b7..699f390 100644 --- a/src/version/index.ts +++ b/src/version/index.ts @@ -15,8 +15,7 @@ try { } async function main() { - // If the user needs to change the cwd, set `working-directory` in the step instead - const cwd = process.cwd(); + const cwd = getOptionalInput("cwd") || process.cwd(); await validateChangesetsCliVersion(cwd); throwOnRemovedCommitModeInput(); diff --git a/version/README.md b/version/README.md index 16ea99e..ff2f0a2 100644 --- a/version/README.md +++ b/version/README.md @@ -31,6 +31,7 @@ This action versions packages and creates or updates a pull request with the cha | `pr-draft` | 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. | | `pr-base-branch` | Sets the base branch of the PR. Defaults to `github.ref_name`. | | `push-with-git-cli` | Whether to use the Git CLI instead of the GitHub API to push release commits. Defaults to `false`. When using the GitHub API, commits are signed using GitHub's GPG key and attributed to the user or app that owns the `github-token`. | +| `cwd` | The working directory to execute Changesets in. Defaults to the root of the repository. | | Outputs | Description | | ----------- | --------------------------------------------------- | diff --git a/version/action.yml b/version/action.yml index e3dda8a..c98e070 100644 --- a/version/action.yml +++ b/version/action.yml @@ -34,6 +34,9 @@ inputs: GPG key and attributed to the user or app that owns the `github-token`. required: false default: false + cwd: + description: "The working directory to execute Changesets in. Defaults to the root of the repository." + required: false outputs: pr-number: description: The pull request number that was created or updated