mirror of
https://github.com/changesets/action
synced 2026-10-26 16:39:56 +08:00
Add support for the simplified tag for single-package repositories (#35)
This commit is contained in:
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -14,6 +14,38 @@ import * as semver from "semver";
|
|||||||
import { readPreState } from "@changesets/pre";
|
import { readPreState } from "@changesets/pre";
|
||||||
import readChangesets from "@changesets/read";
|
import readChangesets from "@changesets/read";
|
||||||
|
|
||||||
|
const createRelease = async (
|
||||||
|
octokit: github.GitHub,
|
||||||
|
{ pkg, tagName }: { pkg: Package; tagName: string }
|
||||||
|
) => {
|
||||||
|
try {
|
||||||
|
let changelogFileName = path.join(pkg.dir, "CHANGELOG.md");
|
||||||
|
|
||||||
|
let changelog = await fs.readFile(changelogFileName, "utf8");
|
||||||
|
|
||||||
|
let changelogEntry = getChangelogEntry(changelog, pkg.packageJson.version);
|
||||||
|
if (!changelogEntry) {
|
||||||
|
// we can find a changelog but not the entry for this version
|
||||||
|
// if this is true, something has probably gone wrong
|
||||||
|
return core.setFailed(
|
||||||
|
`Could not find changelog entry for ${pkg.packageJson.name}@${pkg.packageJson.version}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
await octokit.repos.createRelease({
|
||||||
|
tag_name: tagName,
|
||||||
|
body: changelogEntry.content,
|
||||||
|
prerelease: pkg.packageJson.version.includes("-"),
|
||||||
|
...github.context.repo
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
// if we can't find a changelog, the user has probably disabled changelogs
|
||||||
|
if (err.code !== "ENOENT") {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
let githubToken = process.env.GITHUB_TOKEN;
|
let githubToken = process.env.GITHUB_TOKEN;
|
||||||
|
|
||||||
@@ -75,9 +107,6 @@ import readChangesets from "@changesets/read";
|
|||||||
console.log(
|
console.log(
|
||||||
"No changesets found, attempting to publish any unpublished packages to npm"
|
"No changesets found, attempting to publish any unpublished packages to npm"
|
||||||
);
|
);
|
||||||
let { packages } = await getPackages(process.cwd());
|
|
||||||
let packagesByName = new Map(packages.map(x => [x.packageJson.name, x]));
|
|
||||||
|
|
||||||
let npmrcPath = `${process.env.HOME}/.npmrc`;
|
let npmrcPath = `${process.env.HOME}/.npmrc`;
|
||||||
if (fs.existsSync(npmrcPath)) {
|
if (fs.existsSync(npmrcPath)) {
|
||||||
console.log("Found existing .npmrc file");
|
console.log("Found existing .npmrc file");
|
||||||
@@ -100,60 +129,52 @@ import readChangesets from "@changesets/read";
|
|||||||
|
|
||||||
await exec("git", ["push", "origin", `HEAD:${branch}`, "--tags"]);
|
await exec("git", ["push", "origin", `HEAD:${branch}`, "--tags"]);
|
||||||
|
|
||||||
let newTagRegex = /New tag:\s+(@[^/]+\/[^@]+|[^/]+)@([^\s]+)/;
|
let { packages, tool } = await getPackages(process.cwd());
|
||||||
|
|
||||||
let releasedPackages: Package[] = [];
|
let releasedPackages: Package[] = [];
|
||||||
|
|
||||||
for (let line of changesetPublishOutput.stdout.split("\n")) {
|
if (tool !== "root") {
|
||||||
let match = line.match(newTagRegex);
|
let newTagRegex = /New tag:\s+(@[^/]+\/[^@]+|[^/]+)@([^\s]+)/;
|
||||||
if (match === null) {
|
let packagesByName = new Map(packages.map(x => [x.packageJson.name, x]));
|
||||||
continue;
|
|
||||||
|
for (let line of changesetPublishOutput.stdout.split("\n")) {
|
||||||
|
let match = line.match(newTagRegex);
|
||||||
|
if (match === null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let pkgName = match[1];
|
||||||
|
let pkg = packagesByName.get(pkgName);
|
||||||
|
if (pkg === undefined) {
|
||||||
|
return core.setFailed(
|
||||||
|
`Package "${pkgName}" not found.` +
|
||||||
|
"This is probably a bug in the action, please open an issue"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
releasedPackages.push(pkg);
|
||||||
}
|
}
|
||||||
let pkgName = match[1];
|
|
||||||
let pkg = packagesByName.get(pkgName);
|
await Promise.all(
|
||||||
if (pkg === undefined) {
|
releasedPackages.map(pkg =>
|
||||||
|
createRelease(octokit, {
|
||||||
|
pkg,
|
||||||
|
tagName: `${pkg.packageJson.name}@${pkg.packageJson.version}`
|
||||||
|
})
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
if (packages.length === 0) {
|
||||||
return core.setFailed(
|
return core.setFailed(
|
||||||
`Package "${pkgName}" not found.` +
|
`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"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
const pkg = packages[0];
|
||||||
releasedPackages.push(pkg);
|
releasedPackages.push(pkg);
|
||||||
|
await createRelease(octokit, {
|
||||||
|
pkg,
|
||||||
|
tagName: `v${pkg.packageJson.version}`
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
await Promise.all(
|
|
||||||
releasedPackages.map(async pkg => {
|
|
||||||
try {
|
|
||||||
let changelogFileName = path.join(pkg.dir, "CHANGELOG.md");
|
|
||||||
|
|
||||||
let changelog = await fs.readFile(changelogFileName, "utf8");
|
|
||||||
|
|
||||||
let changelogEntry = getChangelogEntry(
|
|
||||||
changelog,
|
|
||||||
pkg.packageJson.version
|
|
||||||
);
|
|
||||||
if (!changelogEntry) {
|
|
||||||
// we can find a changelog but not the entry for this version
|
|
||||||
// if this is true, something has probably gone wrong
|
|
||||||
return core.setFailed(
|
|
||||||
`Could not find changelog entry for ${pkg.packageJson.name}@${pkg.packageJson.version}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
await octokit.repos.createRelease({
|
|
||||||
tag_name: `${pkg.packageJson.name}@${pkg.packageJson.version}`,
|
|
||||||
body: changelogEntry.content,
|
|
||||||
prerelease: pkg.packageJson.version.includes("-"),
|
|
||||||
...github.context.repo
|
|
||||||
});
|
|
||||||
} catch (err) {
|
|
||||||
// if we can't find a changelog, the user has probably disabled changelogs
|
|
||||||
if (err.code !== "ENOENT") {
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
if (releasedPackages.length) {
|
if (releasedPackages.length) {
|
||||||
core.setOutput("published", "true");
|
core.setOutput("published", "true");
|
||||||
core.setOutput(
|
core.setOutput(
|
||||||
|
|||||||
Reference in New Issue
Block a user