mirror of
https://github.com/changesets/action
synced 2026-10-26 16:39:56 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
001cd79f0a |
@@ -1,14 +1,5 @@
|
||||
# @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
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@changesets/action",
|
||||
"version": "1.5.2",
|
||||
"version": "1.5.1",
|
||||
"main": "dist/index.js",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
|
||||
+34
-57
@@ -4,75 +4,60 @@ import * as github from "@actions/github";
|
||||
import { commitChangesFromRepo } from "@changesets/ghcommit/git";
|
||||
import { Octokit } from "./octokit";
|
||||
|
||||
type GitOptions = {
|
||||
cwd: string;
|
||||
const push = async (branch: string, { force }: { force?: boolean } = {}) => {
|
||||
await exec(
|
||||
"git",
|
||||
["push", "origin", `HEAD:${branch}`, force && "--force"].filter<string>(
|
||||
Boolean as any
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
const push = async (branch: string, options: GitOptions) => {
|
||||
await exec("git", ["push", "origin", `HEAD:${branch}`, "--force"], options);
|
||||
};
|
||||
|
||||
const switchToMaybeExistingBranch = async (
|
||||
branch: string,
|
||||
options: GitOptions
|
||||
) => {
|
||||
const switchToMaybeExistingBranch = async (branch: string) => {
|
||||
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], options);
|
||||
await exec("git", ["checkout", "-b", branch]);
|
||||
}
|
||||
};
|
||||
|
||||
const reset = async (pathSpec: string, options: GitOptions) => {
|
||||
await exec("git", ["reset", `--hard`, pathSpec], options);
|
||||
const reset = async (
|
||||
pathSpec: string,
|
||||
mode: "hard" | "soft" | "mixed" = "hard"
|
||||
) => {
|
||||
await exec("git", ["reset", `--${mode}`, pathSpec]);
|
||||
};
|
||||
|
||||
const commitAll = async (message: string, options: GitOptions) => {
|
||||
await exec("git", ["add", "."], options);
|
||||
await exec("git", ["commit", "-m", message], options);
|
||||
const commitAll = async (message: string) => {
|
||||
await exec("git", ["add", "."]);
|
||||
await exec("git", ["commit", "-m", message]);
|
||||
};
|
||||
|
||||
const checkIfClean = async (options: GitOptions): Promise<boolean> => {
|
||||
const { stdout } = await getExecOutput(
|
||||
"git",
|
||||
["status", "--porcelain"],
|
||||
options
|
||||
);
|
||||
const checkIfClean = async (): Promise<boolean> => {
|
||||
const { stdout } = await getExecOutput("git", ["status", "--porcelain"]);
|
||||
return !stdout.length;
|
||||
};
|
||||
|
||||
export class Git {
|
||||
readonly octokit: Octokit | null;
|
||||
readonly cwd: string;
|
||||
|
||||
constructor(args: { octokit?: Octokit; cwd: string }) {
|
||||
this.octokit = args.octokit ?? null;
|
||||
this.cwd = args.cwd;
|
||||
octokit;
|
||||
constructor(octokit?: Octokit) {
|
||||
this.octokit = octokit;
|
||||
}
|
||||
|
||||
async setupUser() {
|
||||
if (this.octokit) {
|
||||
return;
|
||||
}
|
||||
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,
|
||||
}
|
||||
);
|
||||
await exec("git", ["config", "user.name", `"github-actions[bot]"`]);
|
||||
await exec("git", [
|
||||
"config",
|
||||
"user.email",
|
||||
`"41898282+github-actions[bot]@users.noreply.github.com"`,
|
||||
]);
|
||||
}
|
||||
|
||||
async pushTag(tag: string) {
|
||||
@@ -88,7 +73,7 @@ export class Git {
|
||||
core.warning(`Failed to create tag ${tag}: ${err.message}`);
|
||||
});
|
||||
}
|
||||
await exec("git", ["push", "origin", tag], { cwd: this.cwd });
|
||||
await exec("git", ["push", "origin", tag]);
|
||||
}
|
||||
|
||||
async prepareBranch(branch: string) {
|
||||
@@ -96,19 +81,12 @@ export class Git {
|
||||
// Preparing a new local branch is not necessary when using the API
|
||||
return;
|
||||
}
|
||||
await switchToMaybeExistingBranch(branch, { cwd: this.cwd });
|
||||
await reset(github.context.sha, { cwd: this.cwd });
|
||||
await switchToMaybeExistingBranch(branch);
|
||||
await reset(github.context.sha);
|
||||
}
|
||||
|
||||
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,
|
||||
@@ -117,13 +95,12 @@ export class Git {
|
||||
base: {
|
||||
commit: github.context.sha,
|
||||
},
|
||||
addFromDirectory,
|
||||
force: true,
|
||||
});
|
||||
}
|
||||
if (!(await checkIfClean({ cwd: this.cwd }))) {
|
||||
await commitAll(message, { cwd: this.cwd });
|
||||
if (!(await checkIfClean())) {
|
||||
await commitAll(message);
|
||||
}
|
||||
await push(branch, { cwd: this.cwd });
|
||||
await push(branch, { force: true });
|
||||
}
|
||||
}
|
||||
|
||||
+2
-7
@@ -15,12 +15,11 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
|
||||
return;
|
||||
}
|
||||
|
||||
const inputCwd = getOptionalInput("cwd");
|
||||
const inputCwd = core.getInput("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";
|
||||
@@ -28,10 +27,7 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
|
||||
core.setFailed(`Invalid commit mode: ${commitMode}`);
|
||||
return;
|
||||
}
|
||||
const git = new Git({
|
||||
octokit: commitMode === "github-api" ? octokit : undefined,
|
||||
cwd
|
||||
});
|
||||
const git = new Git(commitMode === "github-api" ? octokit : undefined);
|
||||
|
||||
let setupGitUser = core.getBooleanInput("setupGitUser");
|
||||
|
||||
@@ -104,7 +100,6 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
|
||||
git,
|
||||
octokit,
|
||||
createGithubReleases: core.getBooleanInput("createGithubReleases"),
|
||||
cwd,
|
||||
});
|
||||
|
||||
if (result.published) {
|
||||
|
||||
+2
-2
@@ -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,
|
||||
cwd = process.cwd(),
|
||||
}: PublishOptions): Promise<PublishResult> {
|
||||
let [publishCommand, ...publishArgs] = script.split(/\s+/);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user