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
|
# @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
|
## 1.5.1
|
||||||
|
|
||||||
### Patch Changes
|
### 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",
|
"name": "@changesets/action",
|
||||||
"version": "1.5.2",
|
"version": "1.5.1",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
+31
-54
@@ -4,75 +4,60 @@ import * as github from "@actions/github";
|
|||||||
import { commitChangesFromRepo } from "@changesets/ghcommit/git";
|
import { commitChangesFromRepo } from "@changesets/ghcommit/git";
|
||||||
import { Octokit } from "./octokit";
|
import { Octokit } from "./octokit";
|
||||||
|
|
||||||
type GitOptions = {
|
const push = async (branch: string, { force }: { force?: boolean } = {}) => {
|
||||||
cwd: string;
|
await exec(
|
||||||
|
"git",
|
||||||
|
["push", "origin", `HEAD:${branch}`, force && "--force"].filter<string>(
|
||||||
|
Boolean as any
|
||||||
|
)
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const push = async (branch: string, options: GitOptions) => {
|
const switchToMaybeExistingBranch = async (branch: string) => {
|
||||||
await exec("git", ["push", "origin", `HEAD:${branch}`, "--force"], options);
|
|
||||||
};
|
|
||||||
|
|
||||||
const switchToMaybeExistingBranch = async (
|
|
||||||
branch: string,
|
|
||||||
options: GitOptions
|
|
||||||
) => {
|
|
||||||
let { stderr } = await getExecOutput("git", ["checkout", branch], {
|
let { stderr } = await getExecOutput("git", ["checkout", branch], {
|
||||||
ignoreReturnCode: true,
|
ignoreReturnCode: true,
|
||||||
...options,
|
|
||||||
});
|
});
|
||||||
let isCreatingBranch = !stderr
|
let isCreatingBranch = !stderr
|
||||||
.toString()
|
.toString()
|
||||||
.includes(`Switched to a new branch '${branch}'`);
|
.includes(`Switched to a new branch '${branch}'`);
|
||||||
if (isCreatingBranch) {
|
if (isCreatingBranch) {
|
||||||
await exec("git", ["checkout", "-b", branch], options);
|
await exec("git", ["checkout", "-b", branch]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const reset = async (pathSpec: string, options: GitOptions) => {
|
const reset = async (
|
||||||
await exec("git", ["reset", `--hard`, pathSpec], options);
|
pathSpec: string,
|
||||||
|
mode: "hard" | "soft" | "mixed" = "hard"
|
||||||
|
) => {
|
||||||
|
await exec("git", ["reset", `--${mode}`, pathSpec]);
|
||||||
};
|
};
|
||||||
|
|
||||||
const commitAll = async (message: string, options: GitOptions) => {
|
const commitAll = async (message: string) => {
|
||||||
await exec("git", ["add", "."], options);
|
await exec("git", ["add", "."]);
|
||||||
await exec("git", ["commit", "-m", message], options);
|
await exec("git", ["commit", "-m", message]);
|
||||||
};
|
};
|
||||||
|
|
||||||
const checkIfClean = async (options: GitOptions): Promise<boolean> => {
|
const checkIfClean = async (): Promise<boolean> => {
|
||||||
const { stdout } = await getExecOutput(
|
const { stdout } = await getExecOutput("git", ["status", "--porcelain"]);
|
||||||
"git",
|
|
||||||
["status", "--porcelain"],
|
|
||||||
options
|
|
||||||
);
|
|
||||||
return !stdout.length;
|
return !stdout.length;
|
||||||
};
|
};
|
||||||
|
|
||||||
export class Git {
|
export class Git {
|
||||||
readonly octokit: Octokit | null;
|
octokit;
|
||||||
readonly cwd: string;
|
constructor(octokit?: Octokit) {
|
||||||
|
this.octokit = octokit;
|
||||||
constructor(args: { octokit?: Octokit; cwd: string }) {
|
|
||||||
this.octokit = args.octokit ?? null;
|
|
||||||
this.cwd = args.cwd;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async setupUser() {
|
async setupUser() {
|
||||||
if (this.octokit) {
|
if (this.octokit) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await exec("git", ["config", "user.name", `"github-actions[bot]"`], {
|
await exec("git", ["config", "user.name", `"github-actions[bot]"`]);
|
||||||
cwd: this.cwd,
|
await exec("git", [
|
||||||
});
|
|
||||||
await exec(
|
|
||||||
"git",
|
|
||||||
[
|
|
||||||
"config",
|
"config",
|
||||||
"user.email",
|
"user.email",
|
||||||
`"41898282+github-actions[bot]@users.noreply.github.com"`,
|
`"41898282+github-actions[bot]@users.noreply.github.com"`,
|
||||||
],
|
]);
|
||||||
{
|
|
||||||
cwd: this.cwd,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async pushTag(tag: string) {
|
async pushTag(tag: string) {
|
||||||
@@ -88,7 +73,7 @@ export class Git {
|
|||||||
core.warning(`Failed to create tag ${tag}: ${err.message}`);
|
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) {
|
async prepareBranch(branch: string) {
|
||||||
@@ -96,19 +81,12 @@ export class Git {
|
|||||||
// Preparing a new local branch is not necessary when using the API
|
// Preparing a new local branch is not necessary when using the API
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await switchToMaybeExistingBranch(branch, { cwd: this.cwd });
|
await switchToMaybeExistingBranch(branch);
|
||||||
await reset(github.context.sha, { cwd: this.cwd });
|
await reset(github.context.sha);
|
||||||
}
|
}
|
||||||
|
|
||||||
async pushChanges({ branch, message }: { branch: string; message: string }) {
|
async pushChanges({ branch, message }: { branch: string; message: string }) {
|
||||||
if (this.octokit) {
|
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({
|
return commitChangesFromRepo({
|
||||||
octokit: this.octokit,
|
octokit: this.octokit,
|
||||||
...github.context.repo,
|
...github.context.repo,
|
||||||
@@ -117,13 +95,12 @@ export class Git {
|
|||||||
base: {
|
base: {
|
||||||
commit: github.context.sha,
|
commit: github.context.sha,
|
||||||
},
|
},
|
||||||
addFromDirectory,
|
|
||||||
force: true,
|
force: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (!(await checkIfClean({ cwd: this.cwd }))) {
|
if (!(await checkIfClean())) {
|
||||||
await commitAll(message, { cwd: this.cwd });
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const inputCwd = getOptionalInput("cwd");
|
const inputCwd = core.getInput("cwd");
|
||||||
if (inputCwd) {
|
if (inputCwd) {
|
||||||
core.info("changing directory to the one given as the input");
|
core.info("changing directory to the one given as the input");
|
||||||
process.chdir(inputCwd);
|
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";
|
||||||
@@ -28,10 +27,7 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
|
|||||||
core.setFailed(`Invalid commit mode: ${commitMode}`);
|
core.setFailed(`Invalid commit mode: ${commitMode}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const git = new Git({
|
const git = new Git(commitMode === "github-api" ? octokit : undefined);
|
||||||
octokit: commitMode === "github-api" ? octokit : undefined,
|
|
||||||
cwd
|
|
||||||
});
|
|
||||||
|
|
||||||
let setupGitUser = core.getBooleanInput("setupGitUser");
|
let setupGitUser = core.getBooleanInput("setupGitUser");
|
||||||
|
|
||||||
@@ -104,7 +100,6 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
|
|||||||
git,
|
git,
|
||||||
octokit,
|
octokit,
|
||||||
createGithubReleases: core.getBooleanInput("createGithubReleases"),
|
createGithubReleases: core.getBooleanInput("createGithubReleases"),
|
||||||
cwd,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (result.published) {
|
if (result.published) {
|
||||||
|
|||||||
+2
-2
@@ -66,7 +66,7 @@ type PublishOptions = {
|
|||||||
octokit: Octokit;
|
octokit: Octokit;
|
||||||
createGithubReleases: boolean;
|
createGithubReleases: boolean;
|
||||||
git: Git;
|
git: Git;
|
||||||
cwd: string;
|
cwd?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
type PublishedPackage = { name: string; version: string };
|
type PublishedPackage = { name: string; version: string };
|
||||||
@@ -85,7 +85,7 @@ export async function runPublish({
|
|||||||
git,
|
git,
|
||||||
octokit,
|
octokit,
|
||||||
createGithubReleases,
|
createGithubReleases,
|
||||||
cwd,
|
cwd = process.cwd(),
|
||||||
}: PublishOptions): Promise<PublishResult> {
|
}: PublishOptions): Promise<PublishResult> {
|
||||||
let [publishCommand, ...publishArgs] = script.split(/\s+/);
|
let [publishCommand, ...publishArgs] = script.split(/\s+/);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user