Compare commits

...
6 Commits
Author SHA1 Message Date
github-actions[bot] e0538e6866 v1.5.2 2025-05-10 11:25:48 +00:00
github-actions[bot] 42d5417623 Version Packages (#476)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2025-05-10 13:25:20 +02:00
Sam LanningandMateusz Burzyński 3c24abeab2 Make git add work consistently with subdirectories (#473)
* Make git add work consistently with subdirectories

Currently, depending on your `commitMode`,
when running the action with `cwd` set to a subdirectory of a repo,
the action will either:

- `git-cli`: add the files changed in the subdirectory only
- `github-api`: add files changed anywhere in the repository

This commit brings github-api in line with git-cli,
so that it only adds files in the current working directory.

* Explicitly set `cwd` for all exec calls

* Avoid using `ExecOptions` from `@actions/exec`

* Rename type

* remove redundant `filter`

---------

Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
2025-05-10 12:34:27 +02:00
github-actions[bot] 7f0270e8f4 Version Packages (#468)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2025-05-08 15:25:41 +02:00
Herman JensenandMateusz Burzyński 15ab130606 Bump @changesets/ghcommit to v1.4.0 (#471)
* fix: bump @changesets/ghcommit to v1.4.0

* Update .changeset/dry-bugs-applaud.md

---------

Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
2025-05-08 15:22:42 +02:00
Vx-VandMateusz Burzyński 6e575506e6 Do not pre-start github API request (#467)
* Do not pre-start github API request

* Create quiet-jeans-poke.md

---------

Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
2025-05-06 23:07:15 +02:00
7 changed files with 162 additions and 51 deletions
+17
View File
@@ -1,5 +1,22 @@
# @changesets/action
## 1.5.2
### Patch Changes
- [#473](https://github.com/changesets/action/pull/473) [`3c24abe`](https://github.com/changesets/action/commit/3c24abeab26da6335c181222faa2ea485a092cf8) Thanks [@s0](https://github.com/s0)! - Make git add work consistently with subdirectories
Ensure that when running the action from a subdirectory of a repository,
only the files from that directory are added, regardless of `commitMode`.
## 1.5.1
### Patch Changes
- [#471](https://github.com/changesets/action/pull/471) [`15ab130`](https://github.com/changesets/action/commit/15ab1306067a396fa9ba7ad363e8a041d457782a) Thanks [@h3rmanj](https://github.com/h3rmanj)! - Bump `@changesets/ghcommit` to v1.4.0, which fixes an issue running this action in monorepos with `commitMode: github-api`
- [#467](https://github.com/changesets/action/pull/467) [`6e57550`](https://github.com/changesets/action/commit/6e575506e63f9e69e475d3eccfdd61b448efc8ae) Thanks [@Vx-V](https://github.com/Vx-V)! - Avoid searching for an existing pull request early.
## 1.5.0
### Minor Changes
+67
View File
File diff suppressed because one or more lines are too long
+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "@changesets/action",
"version": "1.5.0",
"version": "1.5.2",
"main": "dist/index.js",
"license": "MIT",
"devDependencies": {
@@ -37,7 +37,7 @@
"@actions/core": "^1.10.0",
"@actions/exec": "^1.1.1",
"@actions/github": "^5.1.1",
"@changesets/ghcommit": "1.3.0",
"@changesets/ghcommit": "1.4.0",
"@changesets/pre": "^1.0.9",
"@changesets/read": "^0.5.3",
"@manypkg/get-packages": "^1.1.3",
+57 -34
View File
@@ -4,60 +4,75 @@ import * as github from "@actions/github";
import { commitChangesFromRepo } from "@changesets/ghcommit/git";
import { Octokit } from "./octokit";
const push = async (branch: string, { force }: { force?: boolean } = {}) => {
await exec(
"git",
["push", "origin", `HEAD:${branch}`, force && "--force"].filter<string>(
Boolean as any
)
);
type GitOptions = {
cwd: string;
};
const switchToMaybeExistingBranch = async (branch: string) => {
const push = async (branch: string, options: GitOptions) => {
await exec("git", ["push", "origin", `HEAD:${branch}`, "--force"], options);
};
const switchToMaybeExistingBranch = async (
branch: string,
options: GitOptions
) => {
let { stderr } = await getExecOutput("git", ["checkout", branch], {
ignoreReturnCode: true,
...options,
});
let isCreatingBranch = !stderr
.toString()
.includes(`Switched to a new branch '${branch}'`);
if (isCreatingBranch) {
await exec("git", ["checkout", "-b", branch]);
await exec("git", ["checkout", "-b", branch], options);
}
};
const reset = async (
pathSpec: string,
mode: "hard" | "soft" | "mixed" = "hard"
) => {
await exec("git", ["reset", `--${mode}`, pathSpec]);
const reset = async (pathSpec: string, options: GitOptions) => {
await exec("git", ["reset", `--hard`, pathSpec], options);
};
const commitAll = async (message: string) => {
await exec("git", ["add", "."]);
await exec("git", ["commit", "-m", message]);
const commitAll = async (message: string, options: GitOptions) => {
await exec("git", ["add", "."], options);
await exec("git", ["commit", "-m", message], options);
};
const checkIfClean = async (): Promise<boolean> => {
const { stdout } = await getExecOutput("git", ["status", "--porcelain"]);
const checkIfClean = async (options: GitOptions): Promise<boolean> => {
const { stdout } = await getExecOutput(
"git",
["status", "--porcelain"],
options
);
return !stdout.length;
};
export class Git {
octokit;
constructor(octokit?: Octokit) {
this.octokit = octokit;
readonly octokit: Octokit | null;
readonly cwd: string;
constructor(args: { octokit?: Octokit; cwd: string }) {
this.octokit = args.octokit ?? null;
this.cwd = args.cwd;
}
async setupUser() {
if (this.octokit) {
return;
}
await exec("git", ["config", "user.name", `"github-actions[bot]"`]);
await exec("git", [
"config",
"user.email",
`"41898282+github-actions[bot]@users.noreply.github.com"`,
]);
await exec("git", ["config", "user.name", `"github-actions[bot]"`], {
cwd: this.cwd,
});
await exec(
"git",
[
"config",
"user.email",
`"41898282+github-actions[bot]@users.noreply.github.com"`,
],
{
cwd: this.cwd,
}
);
}
async pushTag(tag: string) {
@@ -73,7 +88,7 @@ export class Git {
core.warning(`Failed to create tag ${tag}: ${err.message}`);
});
}
await exec("git", ["push", "origin", tag]);
await exec("git", ["push", "origin", tag], { cwd: this.cwd });
}
async prepareBranch(branch: string) {
@@ -81,12 +96,19 @@ export class Git {
// Preparing a new local branch is not necessary when using the API
return;
}
await switchToMaybeExistingBranch(branch);
await reset(github.context.sha);
await switchToMaybeExistingBranch(branch, { cwd: this.cwd });
await reset(github.context.sha, { cwd: this.cwd });
}
async pushChanges({ branch, message }: { branch: string; message: string }) {
if (this.octokit) {
/**
* Only add files form the current working directory
*
* This will emulate the behavior of `git add .`,
* used in {@link commitAll}.
*/
const addFromDirectory = this.cwd;
return commitChangesFromRepo({
octokit: this.octokit,
...github.context.repo,
@@ -95,12 +117,13 @@ export class Git {
base: {
commit: github.context.sha,
},
addFromDirectory,
force: true,
});
}
if (!(await checkIfClean())) {
await commitAll(message);
if (!(await checkIfClean({ cwd: this.cwd }))) {
await commitAll(message, { cwd: this.cwd });
}
await push(branch, { force: true });
await push(branch, { cwd: this.cwd });
}
}
+7 -2
View File
@@ -15,11 +15,12 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
return;
}
const inputCwd = core.getInput("cwd");
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 octokit = setupOctokit(githubToken);
const commitMode = getOptionalInput("commitMode") ?? "git-cli";
@@ -27,7 +28,10 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
core.setFailed(`Invalid commit mode: ${commitMode}`);
return;
}
const git = new Git(commitMode === "github-api" ? octokit : undefined);
const git = new Git({
octokit: commitMode === "github-api" ? octokit : undefined,
cwd
});
let setupGitUser = core.getBooleanInput("setupGitUser");
@@ -100,6 +104,7 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
git,
octokit,
createGithubReleases: core.getBooleanInput("createGithubReleases"),
cwd,
});
if (result.published) {
+8 -9
View File
@@ -66,7 +66,7 @@ type PublishOptions = {
octokit: Octokit;
createGithubReleases: boolean;
git: Git;
cwd?: string;
cwd: string;
};
type PublishedPackage = { name: string; version: string };
@@ -85,7 +85,7 @@ export async function runPublish({
git,
octokit,
createGithubReleases,
cwd = process.cwd(),
cwd,
}: PublishOptions): Promise<PublishResult> {
let [publishCommand, ...publishArgs] = script.split(/\s+/);
@@ -300,12 +300,6 @@ export async function runVersion({
});
}
const existingPullRequestsPromise = octokit.rest.pulls.list({
...github.context.repo,
state: "open",
head: `${github.context.repo.owner}:${versionBranch}`,
base: branch,
});
let changedPackages = await getChangedPackages(cwd, versionsByDirectory);
let changedPackagesInfoPromises = Promise.all(
changedPackages.map(async (pkg) => {
@@ -331,7 +325,12 @@ export async function runVersion({
await git.pushChanges({ branch: versionBranch, message: finalCommitMessage });
let existingPullRequests = await existingPullRequestsPromise;
let existingPullRequests = await octokit.rest.pulls.list({
...github.context.repo,
state: "open",
head: `${github.context.repo.owner}:${versionBranch}`,
base: branch,
});
core.info(JSON.stringify(existingPullRequests.data, null, 2));
const changedPackagesInfo = (await changedPackagesInfoPromises)
+4 -4
View File
@@ -1139,10 +1139,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.3.0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@changesets/ghcommit/-/ghcommit-1.3.0.tgz#8978eac4d5c2d4dc63865eeac00bc5922db7c0f3"
integrity sha512-Bbg4NlEqVWnykX12XlHw8V1JV/xdAJvuai3eEd7pPMiHT9k4n9FQyPdKs6ww1zooM0Xrjy0CC2INGtD8vKkc1Q==
"@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==
dependencies:
isomorphic-git "^1.27.1"