Skip to content

Commit

Permalink
ci: add package name to releases
Browse files Browse the repository at this point in the history
  • Loading branch information
Wroud committed Sep 9, 2024
1 parent 5484e32 commit 95b99ba
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
4 changes: 3 additions & 1 deletion packages/ci-github-release/src/github-release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Options<
/**
* Create a GitHub release for the latest version in the repository.
*
* @param packageName - The name of the package.
* @param auth - The authentication options for the GitHub API.
* @param changelogOpts - Options for the changelog generation.
* @param context - The context object with owner and repository.
Expand All @@ -38,6 +39,7 @@ export async function githubRelease<
TCommit extends Commit = Commit,
TContext extends WriterContext = Context,
>(
packageName: string,
auth: IAuthOptions,
changelogOpts: Options<TCommit, TContext> = {},
context: Partial<TContext> = {},
Expand Down Expand Up @@ -105,7 +107,7 @@ export async function githubRelease<
owner,
repo: repository,
tag_name: chunk.keyCommit["tag"],
name: version,
name: `${packageName}@${version}`,
body: chunk.log,
draft: false,
prerelease: (semver.parse(version)?.prerelease || []).length > 0,
Expand Down
5 changes: 5 additions & 0 deletions packages/ci/src/gulp/IPackageJson.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface IPackageJson {
name: string;
version?: string;
description?: string;
}
23 changes: 15 additions & 8 deletions packages/ci/src/gulp/prepublish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { combineStreams } from "./combineStreams.js";
import { createReadStream, createWriteStream, existsSync } from "fs";
import { githubRelease } from "@wroud/ci-github-release";
import { releaseCommitRegex } from "./releaseCommitRegex.js";
import type { IPackageJson } from "./IPackageJson.js";

const tagPrefix = "di-v";
const commitPath = ".";
Expand All @@ -20,6 +21,12 @@ const changeLogFile = "CHANGELOG.md";
const stdio = "inherit";
const commitsConfig = { path: commitPath /*, ignore: releaseCommitRegex*/ };

async function readPackageJson(): Promise<IPackageJson> {
return await readFile("package.json", "utf8").then((data) =>
JSON.parse(data),
);
}

async function bumpVersion(preset: Preset): Promise<string | null> {
const bumper = new RestrictEmptyCommits(process.cwd())
.loadPreset(preset)
Expand All @@ -38,9 +45,7 @@ async function bumpVersion(preset: Preset): Promise<string | null> {
stdio,
});

return await readFile("package.json", "utf8")
.then((data) => JSON.parse(data))
.then((content) => content.version);
return await readPackageJson().then((content) => content.version || null);
}

async function changelog(preset: Preset, version: string) {
Expand Down Expand Up @@ -70,8 +75,8 @@ async function changelog(preset: Preset, version: string) {
return version;
}

async function commitTagPush(version: string) {
const commitMsg = `chore: release ${version}`;
async function commitTagPush(version: string, packageName: string) {
const commitMsg = `chore: release ${packageName}@${version}`;
await execa("git", ["add", "package.json", "CHANGELOG.md"], { stdio });
await execa("git", ["commit", "--message", commitMsg], { stdio });
await execa("git", ["tag", "-a", `${tagPrefix}${version}`, "-m", commitMsg], {
Expand All @@ -80,7 +85,7 @@ async function commitTagPush(version: string) {
await execa("git", ["push", "--follow-tags"], { stdio });
}

async function publishGithubRelease(preset: Preset) {
async function publishGithubRelease(preset: Preset, packageName: string) {
const token = process.env["GITHUB_TOKEN"];
const [owner, repository] =
process.env["GITHUB_REPOSITORY"]?.split("/") || [];
Expand All @@ -90,6 +95,7 @@ async function publishGithubRelease(preset: Preset) {
}

await githubRelease(
packageName,
{ type: "oauth", token },
{ config: preset, tagPrefix },
{ owner, repository },
Expand All @@ -98,6 +104,7 @@ async function publishGithubRelease(preset: Preset) {
}

task("ci:prepublish", async () => {
const packageJson = await readPackageJson();
const preset = await createPreset();
const version = await bumpVersion(preset);

Expand All @@ -107,6 +114,6 @@ task("ci:prepublish", async () => {
}

await changelog(preset, version);
await commitTagPush(version);
await publishGithubRelease(preset);
await commitTagPush(version, packageJson.name);
await publishGithubRelease(preset, packageJson.name);
});
2 changes: 1 addition & 1 deletion packages/di/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![ESM-only package][package]][package-url]
[![NPM version][npm]][npm-url]

<!-- [![Install size][size]][size-url] -->
<!-- [![Install size][size]][size-url] test -->

[package]: https://img.shields.io/badge/package-ESM--only-ffe536.svg
[package-url]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
Expand Down

0 comments on commit 95b99ba

Please sign in to comment.