mirror of
https://github.com/changesets/action
synced 2026-10-26 16:39:56 +08:00
Migrate to oxfmt (#618)
* Migrate to oxfmt * Enable import sorting * trailingComma always
This commit is contained in:
+3
-3
@@ -14,7 +14,7 @@ const push = async (branch: string, options: GitOptions) => {
|
||||
|
||||
const switchToMaybeExistingBranch = async (
|
||||
branch: string,
|
||||
options: GitOptions
|
||||
options: GitOptions,
|
||||
) => {
|
||||
let { stderr } = await getExecOutput("git", ["checkout", branch], {
|
||||
ignoreReturnCode: true,
|
||||
@@ -41,7 +41,7 @@ const checkIfClean = async (options: GitOptions): Promise<boolean> => {
|
||||
const { stdout } = await getExecOutput(
|
||||
"git",
|
||||
["status", "--porcelain"],
|
||||
options
|
||||
options,
|
||||
);
|
||||
return !stdout.length;
|
||||
};
|
||||
@@ -71,7 +71,7 @@ export class Git {
|
||||
],
|
||||
{
|
||||
cwd: this.cwd,
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+13
-13
@@ -1,6 +1,6 @@
|
||||
import * as core from "@actions/core";
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import * as core from "@actions/core";
|
||||
import { Git } from "./git.ts";
|
||||
import { setupOctokit } from "./octokit.ts";
|
||||
import readChangesetState from "./readChangesetState.ts";
|
||||
@@ -48,7 +48,7 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
|
||||
core.info("setting GitHub credentials");
|
||||
await fs.writeFile(
|
||||
`${process.env.HOME}/.netrc`,
|
||||
`machine github.com\nlogin github-actions[bot]\npassword ${githubToken}`
|
||||
`machine github.com\nlogin github-actions[bot]\npassword ${githubToken}`,
|
||||
);
|
||||
|
||||
let { changesets } = await readChangesetState(cwd);
|
||||
@@ -56,7 +56,7 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
|
||||
let publishScript = core.getInput("publish");
|
||||
let hasChangesets = changesets.length !== 0;
|
||||
const hasNonEmptyChangesets = changesets.some(
|
||||
(changeset) => changeset.releases.length > 0
|
||||
(changeset) => changeset.releases.length > 0,
|
||||
);
|
||||
let hasPublishScript = !!publishScript;
|
||||
|
||||
@@ -67,12 +67,12 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
|
||||
switch (true) {
|
||||
case !hasChangesets && !hasPublishScript:
|
||||
core.info(
|
||||
"No changesets present or were removed by merging release PR. Not publishing because no publish script found."
|
||||
"No changesets present or were removed by merging release PR. Not publishing because no publish script found.",
|
||||
);
|
||||
return;
|
||||
case !hasChangesets && hasPublishScript: {
|
||||
core.info(
|
||||
"No changesets found. Attempting to publish any unpublished packages to npm"
|
||||
"No changesets found. Attempting to publish any unpublished packages to npm",
|
||||
);
|
||||
|
||||
if (process.env.NPM_TOKEN) {
|
||||
@@ -87,24 +87,24 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
|
||||
});
|
||||
if (authLine) {
|
||||
core.info(
|
||||
"Found existing auth token for the npm registry in the user .npmrc file"
|
||||
"Found existing auth token for the npm registry in the user .npmrc file",
|
||||
);
|
||||
} else {
|
||||
core.info(
|
||||
"Didn't find existing auth token for the npm registry in the user .npmrc file, creating one"
|
||||
"Didn't find existing auth token for the npm registry in the user .npmrc file, creating one",
|
||||
);
|
||||
await fs.appendFile(
|
||||
userNpmrcPath,
|
||||
`\n//registry.npmjs.org/:_authToken=${process.env.NPM_TOKEN}\n`
|
||||
`\n//registry.npmjs.org/:_authToken=${process.env.NPM_TOKEN}\n`,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
core.info(
|
||||
"No user .npmrc file found, creating one with NPM_TOKEN used as auth token"
|
||||
"No user .npmrc file found, creating one with NPM_TOKEN used as auth token",
|
||||
);
|
||||
await fs.writeFile(
|
||||
userNpmrcPath,
|
||||
`//registry.npmjs.org/:_authToken=${process.env.NPM_TOKEN}\n`
|
||||
`//registry.npmjs.org/:_authToken=${process.env.NPM_TOKEN}\n`,
|
||||
);
|
||||
}
|
||||
} else if (
|
||||
@@ -112,11 +112,11 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
|
||||
process.env.ACTIONS_ID_TOKEN_REQUEST_URL
|
||||
) {
|
||||
core.info(
|
||||
"No NPM_TOKEN found, but OIDC is available - using npm trusted publishing"
|
||||
"No NPM_TOKEN found, but OIDC is available - using npm trusted publishing",
|
||||
);
|
||||
} else {
|
||||
core.info(
|
||||
"No NPM_TOKEN or OIDC available - assuming npm is already authenticated"
|
||||
"No NPM_TOKEN or OIDC available - assuming npm is already authenticated",
|
||||
);
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ const getOptionalInput = (name: string) => core.getInput(name) || undefined;
|
||||
core.setOutput("published", "true");
|
||||
core.setOutput(
|
||||
"publishedPackages",
|
||||
JSON.stringify(result.publishedPackages)
|
||||
JSON.stringify(result.publishedPackages),
|
||||
);
|
||||
}
|
||||
return;
|
||||
|
||||
+4
-4
@@ -9,7 +9,7 @@ export const setupOctokit = (githubToken: string) => {
|
||||
throttle: {
|
||||
onRateLimit: (retryAfter, options: any, octokit, retryCount) => {
|
||||
core.warning(
|
||||
`Request quota exhausted for request ${options.method} ${options.url}`
|
||||
`Request quota exhausted for request ${options.method} ${options.url}`,
|
||||
);
|
||||
|
||||
if (retryCount <= 2) {
|
||||
@@ -21,10 +21,10 @@ export const setupOctokit = (githubToken: string) => {
|
||||
retryAfter,
|
||||
options: any,
|
||||
octokit,
|
||||
retryCount
|
||||
retryCount,
|
||||
) => {
|
||||
core.warning(
|
||||
`SecondaryRateLimit detected for request ${options.method} ${options.url}`
|
||||
`SecondaryRateLimit detected for request ${options.method} ${options.url}`,
|
||||
);
|
||||
|
||||
if (retryCount <= 2) {
|
||||
@@ -34,7 +34,7 @@ export const setupOctokit = (githubToken: string) => {
|
||||
},
|
||||
},
|
||||
},
|
||||
throttling
|
||||
throttling,
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { PreState, NewChangeset } from "@changesets/types";
|
||||
import { readPreState } from "@changesets/pre";
|
||||
import readChangesets from "@changesets/read";
|
||||
import type { PreState, NewChangeset } from "@changesets/types";
|
||||
|
||||
export type ChangesetState = {
|
||||
preState: PreState | undefined;
|
||||
@@ -8,7 +8,7 @@ export type ChangesetState = {
|
||||
};
|
||||
|
||||
export default async function readChangesetState(
|
||||
cwd: string = process.cwd()
|
||||
cwd: string = process.cwd(),
|
||||
): Promise<ChangesetState> {
|
||||
let preState = await readPreState(cwd);
|
||||
let changesets = await readChangesets(cwd);
|
||||
|
||||
+13
-13
@@ -1,8 +1,8 @@
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import type { Changeset } from "@changesets/types";
|
||||
import writeChangeset from "@changesets/write";
|
||||
import fixturez from "fixturez";
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { Git } from "./git.ts";
|
||||
import { setupOctokit } from "./octokit.ts";
|
||||
@@ -41,7 +41,7 @@ let f = fixturez(import.meta.dirname);
|
||||
const linkNodeModules = async (cwd: string) => {
|
||||
await fs.symlink(
|
||||
path.join(import.meta.dirname, "..", "node_modules"),
|
||||
path.join(cwd, "node_modules")
|
||||
path.join(cwd, "node_modules"),
|
||||
);
|
||||
};
|
||||
const writeChangesets = (changesets: Changeset[], cwd: string) => {
|
||||
@@ -79,7 +79,7 @@ describe("version", () => {
|
||||
summary: "Awesome feature",
|
||||
},
|
||||
],
|
||||
cwd
|
||||
cwd,
|
||||
);
|
||||
|
||||
await runVersion({
|
||||
@@ -114,7 +114,7 @@ describe("version", () => {
|
||||
summary: "Awesome feature",
|
||||
},
|
||||
],
|
||||
cwd
|
||||
cwd,
|
||||
);
|
||||
|
||||
await runVersion({
|
||||
@@ -150,7 +150,7 @@ describe("version", () => {
|
||||
summary: "Awesome feature",
|
||||
},
|
||||
],
|
||||
cwd
|
||||
cwd,
|
||||
);
|
||||
|
||||
await runVersion({
|
||||
@@ -185,7 +185,7 @@ describe("version", () => {
|
||||
summary: "Awesome feature",
|
||||
},
|
||||
],
|
||||
cwd
|
||||
cwd,
|
||||
);
|
||||
|
||||
await runVersion({
|
||||
@@ -240,7 +240,7 @@ fluminis divesque vulnere aquis parce lapsis rabie si visa fulmineis.
|
||||
`,
|
||||
},
|
||||
],
|
||||
cwd
|
||||
cwd,
|
||||
);
|
||||
|
||||
await runVersion({
|
||||
@@ -253,7 +253,7 @@ fluminis divesque vulnere aquis parce lapsis rabie si visa fulmineis.
|
||||
|
||||
expect(mockedGithubMethods.pulls.create.mock.calls[0]).toMatchSnapshot();
|
||||
expect(mockedGithubMethods.pulls.create.mock.calls[0][0].body).toMatch(
|
||||
/The changelog information of each package has been omitted from this message/
|
||||
/The changelog information of each package has been omitted from this message/,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -299,7 +299,7 @@ fluminis divesque vulnere aquis parce lapsis rabie si visa fulmineis.
|
||||
`,
|
||||
},
|
||||
],
|
||||
cwd
|
||||
cwd,
|
||||
);
|
||||
|
||||
await runVersion({
|
||||
@@ -312,7 +312,7 @@ fluminis divesque vulnere aquis parce lapsis rabie si visa fulmineis.
|
||||
|
||||
expect(mockedGithubMethods.pulls.create.mock.calls[0]).toMatchSnapshot();
|
||||
expect(mockedGithubMethods.pulls.create.mock.calls[0][0].body).toMatch(
|
||||
/All release information have been omitted from this message, as the content exceeds the size limit/
|
||||
/All release information have been omitted from this message, as the content exceeds the size limit/,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -336,7 +336,7 @@ fluminis divesque vulnere aquis parce lapsis rabie si visa fulmineis.
|
||||
summary: "Awesome feature",
|
||||
},
|
||||
],
|
||||
cwd
|
||||
cwd,
|
||||
);
|
||||
|
||||
await runVersion({
|
||||
@@ -370,7 +370,7 @@ fluminis divesque vulnere aquis parce lapsis rabie si visa fulmineis.
|
||||
summary: "Awesome feature",
|
||||
},
|
||||
],
|
||||
cwd
|
||||
cwd,
|
||||
);
|
||||
|
||||
await runVersion({
|
||||
|
||||
+20
-18
@@ -1,11 +1,11 @@
|
||||
import fs from "node:fs/promises";
|
||||
import { createRequire } from "node:module";
|
||||
import path from "node:path";
|
||||
import * as core from "@actions/core";
|
||||
import { exec, getExecOutput } from "@actions/exec";
|
||||
import * as github from "@actions/github";
|
||||
import type { PreState } from "@changesets/types";
|
||||
import { type Package, getPackages } from "@manypkg/get-packages";
|
||||
import fs from "node:fs/promises";
|
||||
import { createRequire } from "node:module";
|
||||
import path from "node:path";
|
||||
import semverLt from "semver/functions/lt.js";
|
||||
import { Git } from "./git.ts";
|
||||
import type { Octokit } from "./octokit.ts";
|
||||
@@ -28,7 +28,7 @@ const MAX_CHARACTERS_PER_MESSAGE = 60000;
|
||||
|
||||
const createRelease = async (
|
||||
octokit: Octokit,
|
||||
{ pkg, tagName }: { pkg: Package; tagName: string }
|
||||
{ pkg, tagName }: { pkg: Package; tagName: string },
|
||||
) => {
|
||||
let changelog;
|
||||
try {
|
||||
@@ -45,7 +45,7 @@ const createRelease = async (
|
||||
// we can find a changelog but not the entry for this version
|
||||
// if this is true, something has probably gone wrong
|
||||
throw new Error(
|
||||
`Could not find changelog entry for ${pkg.packageJson.name}@${pkg.packageJson.version}`
|
||||
`Could not find changelog entry for ${pkg.packageJson.name}@${pkg.packageJson.version}`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ export async function runPublish({
|
||||
let changesetPublishOutput = await getExecOutput(
|
||||
publishCommand,
|
||||
publishArgs,
|
||||
{ cwd, env: { ...process.env, GITHUB_TOKEN: githubToken } }
|
||||
{ cwd, env: { ...process.env, GITHUB_TOKEN: githubToken } },
|
||||
);
|
||||
|
||||
let { packages, tool } = await getPackages(cwd);
|
||||
@@ -111,7 +111,7 @@ export async function runPublish({
|
||||
if (pkg === undefined) {
|
||||
throw new Error(
|
||||
`Package "${pkgName}" not found.` +
|
||||
"This is probably a bug in the action, please open an issue"
|
||||
"This is probably a bug in the action, please open an issue",
|
||||
);
|
||||
}
|
||||
releasedPackages.push(pkg);
|
||||
@@ -123,14 +123,14 @@ export async function runPublish({
|
||||
const tagName = `${pkg.packageJson.name}@${pkg.packageJson.version}`;
|
||||
await git.pushTag(tagName);
|
||||
await createRelease(octokit, { pkg, tagName });
|
||||
})
|
||||
}),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if (packages.length === 0) {
|
||||
throw new Error(
|
||||
`No package found.` +
|
||||
"This is probably a bug in the action, please open an issue"
|
||||
"This is probably a bug in the action, please open an issue",
|
||||
);
|
||||
}
|
||||
let pkg = packages[0];
|
||||
@@ -166,14 +166,16 @@ export async function runPublish({
|
||||
|
||||
const requireChangesetsCliPkgJson = (cwd: string) => {
|
||||
try {
|
||||
return require(require.resolve("@changesets/cli/package.json", {
|
||||
paths: [cwd],
|
||||
}));
|
||||
return require(
|
||||
require.resolve("@changesets/cli/package.json", {
|
||||
paths: [cwd],
|
||||
}),
|
||||
);
|
||||
} catch (err) {
|
||||
if (isErrorWithCode(err, "MODULE_NOT_FOUND")) {
|
||||
throw new Error(
|
||||
`Have you forgotten to install \`@changesets/cli\` in "${cwd}"?`,
|
||||
{ cause: err }
|
||||
{ cause: err },
|
||||
);
|
||||
}
|
||||
throw err;
|
||||
@@ -309,7 +311,7 @@ export async function runVersion({
|
||||
{
|
||||
cwd,
|
||||
env,
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -318,7 +320,7 @@ export async function runVersion({
|
||||
changedPackages.map(async (pkg) => {
|
||||
let changelogContents = await fs.readFile(
|
||||
path.join(pkg.dir, "CHANGELOG.md"),
|
||||
"utf8"
|
||||
"utf8",
|
||||
);
|
||||
|
||||
let entry = getChangelogEntry(changelogContents, pkg.packageJson.version);
|
||||
@@ -328,7 +330,7 @@ export async function runVersion({
|
||||
content: entry.content,
|
||||
header: `## ${pkg.packageJson.name}@${pkg.packageJson.version}`,
|
||||
};
|
||||
})
|
||||
}),
|
||||
);
|
||||
|
||||
const finalPrTitle = `${prTitle}${!!preState ? ` (${preState.tag})` : ""}`;
|
||||
@@ -353,8 +355,8 @@ export async function runVersion({
|
||||
`Existing pull requests: ${JSON.stringify(
|
||||
existingPullRequests.data,
|
||||
null,
|
||||
2
|
||||
)}`
|
||||
2,
|
||||
)}`,
|
||||
);
|
||||
|
||||
await git.pushChanges({ branch: versionBranch, message: finalCommitMessage });
|
||||
|
||||
+7
-7
@@ -1,11 +1,11 @@
|
||||
import unified from "unified";
|
||||
import remarkParse from "remark-parse";
|
||||
import remarkStringify from "remark-stringify";
|
||||
import fs from "node:fs/promises";
|
||||
import { getPackages, type Package } from "@manypkg/get-packages";
|
||||
import type { Root } from "mdast";
|
||||
// @ts-ignore
|
||||
import mdastToString from "mdast-util-to-string";
|
||||
import { getPackages, type Package } from "@manypkg/get-packages";
|
||||
import remarkParse from "remark-parse";
|
||||
import remarkStringify from "remark-stringify";
|
||||
import unified from "unified";
|
||||
|
||||
export const BumpLevels = {
|
||||
dep: 0,
|
||||
@@ -21,7 +21,7 @@ export async function getVersionsByDirectory(cwd: string) {
|
||||
|
||||
export async function getChangedPackages(
|
||||
cwd: string,
|
||||
previousVersions: Map<string, string>
|
||||
previousVersions: Map<string, string>,
|
||||
) {
|
||||
let { packages } = await getPackages(cwd);
|
||||
let changedPackages = new Set<Package>();
|
||||
@@ -87,7 +87,7 @@ export function getChangelogEntry(changelog: string, version: string) {
|
||||
|
||||
export function sortTheThings(
|
||||
a: { private: boolean; highestLevel: number },
|
||||
b: { private: boolean; highestLevel: number }
|
||||
b: { private: boolean; highestLevel: number },
|
||||
) {
|
||||
if (a.private === b.private) {
|
||||
return b.highestLevel - a.highestLevel;
|
||||
@@ -110,6 +110,6 @@ export function isErrorWithCode(err: unknown, code: string) {
|
||||
export function fileExists(filePath: string) {
|
||||
return fs.access(filePath, fs.constants.F_OK).then(
|
||||
() => true,
|
||||
() => false
|
||||
() => false,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user