Skip to content

Commit 83c2b65

Browse files
committed
build(dev-utils): release script will now automatically create github release
1 parent db1aa30 commit 83c2b65

8 files changed

Lines changed: 171 additions & 16 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ packages/*/*.tsbuildinfo
1616
/packages/material-icons/temp
1717
!/packages/documentation/types
1818

19+
# for creating github releases
20+
/.env.local
21+
1922
# Testing
2023
coverage
2124

packages/dev-utils/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
},
1717
"dependencies": {
1818
"@babel/core": "^7.12.13",
19+
"@octokit/core": "^3.2.5",
1920
"chokidar": "^3.5.0",
2021
"commander": "^7.0.0",
2122
"cpx": "^1.5.0",
2223
"cssnano": "^4.1.10",
24+
"dotenv": "^8.2.0",
2325
"filesize": "^6.1.0",
2426
"fs-extra": "^9.1.0",
2527
"glob": "^7.1.6",

packages/dev-utils/src/cli.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,16 @@ createCommand("libsize")
165165
themes = true,
166166
forceThemes = false,
167167
stageChanges = false,
168-
}) => libsize({ umd, forceUmd, themes, forceThemes, stageChanges })
168+
}) =>
169+
libsize({
170+
umd,
171+
forceUmd,
172+
themes,
173+
forceThemes,
174+
stageChanges,
175+
}).then(() => {
176+
// .action only allows Promise<void> or void
177+
})
169178
);
170179

171180
createCommand("themes")

packages/dev-utils/src/libsize.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,11 @@ function getSizes(message: string): readonly Size[] {
126126
});
127127
}
128128

129-
function logPercentChanged(message: string, umd: boolean, css: boolean): void {
129+
function getPercentChanged(
130+
message: string,
131+
umd: boolean,
132+
css: boolean
133+
): string {
130134
const previous = getSizes(getPreviousLibsize(ROOT_README_PATH));
131135
const current = getSizes(message);
132136
const start = umd ? 0 : 3;
@@ -161,7 +165,7 @@ function logPercentChanged(message: string, umd: boolean, css: boolean): void {
161165
})
162166
.join("\n");
163167

164-
log.info(updated);
168+
return updated;
165169
}
166170

167171
function updateLibsize(filePath: string, message: string): void {
@@ -233,7 +237,7 @@ export async function libsize({
233237
themes = true,
234238
forceThemes = false,
235239
stageChanges = false,
236-
}: Options): Promise<void> {
240+
}: Options): Promise<string> {
237241
umd = umd || forceUmd;
238242
themes = themes || forceThemes;
239243
if (!umd && !themes) {
@@ -267,7 +271,12 @@ ${list(css)}
267271
`;
268272
}
269273

270-
logPercentChanged(message, !!umds.length, !!css.length);
274+
const percentChanged = getPercentChanged(
275+
message,
276+
!!umds.length,
277+
!!css.length
278+
);
279+
log.info(percentChanged);
271280

272281
if (stageChanges && umds.length && css.length) {
273282
log.info("Updating documentation files with libsize...");
@@ -280,4 +289,6 @@ ${list(css)}
280289
git("add -u");
281290
}
282291
}
292+
293+
return percentChanged;
283294
}

packages/dev-utils/src/release.ts

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1+
import { Octokit } from "@octokit/core";
2+
import dotenv from "dotenv";
13
import log from "loglevel";
4+
import { join } from "path";
25
import prompts from "prompts";
36

7+
import { changelogData } from "./changelogData";
48
import { clean } from "./clean";
9+
import { projectRoot } from "./constants";
510
import { libsize } from "./libsize";
6-
import { changelogData } from "./changelogData";
711
import { getLernaVersion, git, replaceTag, run } from "./utils";
8-
import { variables } from "./variables";
912
import { initBlog } from "./utils/initBlog";
13+
import { variables } from "./variables";
1014

1115
export type ReleaseType =
1216
| "major"
@@ -74,6 +78,21 @@ export async function release({
7478
clean: enableClean,
7579
type,
7680
}: Options): Promise<void> {
81+
const localDotEnv = join(projectRoot, ".env.local");
82+
dotenv.config({ path: localDotEnv });
83+
const { GITHUB_TOKEN } = process.env;
84+
if (!GITHUB_TOKEN) {
85+
log.error(
86+
`Missing a \`GITHUB_TOKEN\` environment variable. This should be located at:
87+
- ${localDotEnv}
88+
89+
A token can be created at:
90+
- https://github.com/settings/tokens/new?scopes=repo
91+
`
92+
);
93+
94+
process.exit(1);
95+
}
7796
const yes = autoYes ? " --yes" : "";
7897

7998
if (enableClean) {
@@ -91,9 +110,9 @@ export async function release({
91110

92111
await changelogData();
93112
run(`npx lerna version ${type} --no-push${yes}`);
94-
await initBlog();
113+
const changelog = await initBlog();
95114

96-
await libsize({
115+
const percentChanged = await libsize({
97116
umd: true,
98117
themes: true,
99118
// have to force the themes to be updated since they are always stored in
@@ -122,4 +141,26 @@ export async function release({
122141

123142
git("push origin main");
124143
git("push --tags");
144+
145+
log.info("Creating github release");
146+
const body = `${changelog}
147+
148+
### Library Size Changes
149+
150+
${percentChanged}
151+
`;
152+
const version = await getLernaVersion();
153+
const octokit = new Octokit({ auth: GITHUB_TOKEN });
154+
const response = await octokit.request(
155+
"POST /repos/{owner}/{repo}/releases",
156+
{
157+
owner: "mlaursen",
158+
repo: "react-md",
159+
tag_name: `v${version}`,
160+
body,
161+
prerelease: type.startsWith("pre"),
162+
}
163+
);
164+
165+
log.info(`Created release: ${response.data.html_url}`);
125166
}

packages/dev-utils/src/utils/initBlog.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ import { format } from "./format";
77

88
const NEW_ENTRY = /^#{1,2}\s+\[\d/;
99

10-
export async function initBlog(): Promise<void> {
10+
/**
11+
*
12+
* @return the current release markdown that can be used to generate a github
13+
* release for the current tag.
14+
*/
15+
export async function initBlog(): Promise<string> {
1116
const blogPath = join(documentationRoot, src, "blogs", "index.md");
1217
const version = (await getPackageJson("react-md")).version;
1318
const changelog = await readFile(join(projectRoot, "CHANGELOG.md"), "utf8");
@@ -31,9 +36,8 @@ export async function initBlog(): Promise<void> {
3136
process.exit(1);
3237
}
3338

34-
const currentRelease = lines
35-
.slice(lastEntryStart, nextEntryStart)
36-
.join("\n")
39+
const currentRelease = lines.slice(lastEntryStart, nextEntryStart).join("\n");
40+
const blogMarkdown = currentRelease
3741
// create smaller headings and remove margin
3842
.replace(/^(###)\s+(.+)$/gm, "##### $2<!-- no-margin -->")
3943
// replace issue/pr references with super-shorthand syntax. they can
@@ -52,12 +56,14 @@ Date: ${new Date().toLocaleDateString("en-US", {
5256
5357
Summary:
5458
55-
${currentRelease}
59+
${blogMarkdown}
5660
5761
---
5862
5963
${blog}
6064
`;
6165

6266
await writeFile(blogPath, format(contents, "markdown"));
67+
68+
return currentRelease;
6369
}

packages/dev-utils/src/utils/packages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export async function getAllVersions(): Promise<typeof VERSIONS> {
8383
/**
8484
* Gets the current root lerna version.
8585
*/
86-
export async function getLernaVersion(): Promise<string | null> {
86+
export async function getLernaVersion(): Promise<string> {
8787
const lernaJsonPath = join(projectRoot, "lerna.json");
8888
if (VERSIONS.has(lernaJsonPath)) {
8989
const value = VERSIONS.get(lernaJsonPath);

yarn.lock

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1511,6 +1511,25 @@
15111511
dependencies:
15121512
"@octokit/types" "^2.0.0"
15131513

1514+
"@octokit/auth-token@^2.4.4":
1515+
version "2.4.5"
1516+
resolved "https://registry.yarnpkg.com/@octokit/auth-token/-/auth-token-2.4.5.tgz#568ccfb8cb46f36441fac094ce34f7a875b197f3"
1517+
integrity sha512-BpGYsPgJt05M7/L/5FoE1PiAbdxXFZkX/3kDYcsvd1v6UhlnE5e96dTDr0ezX/EFwciQxf3cNV0loipsURU+WA==
1518+
dependencies:
1519+
"@octokit/types" "^6.0.3"
1520+
1521+
"@octokit/core@^3.2.5":
1522+
version "3.2.5"
1523+
resolved "https://registry.yarnpkg.com/@octokit/core/-/core-3.2.5.tgz#57becbd5fd789b0592b915840855f3a5f233d554"
1524+
integrity sha512-+DCtPykGnvXKWWQI0E1XD+CCeWSBhB6kwItXqfFmNBlIlhczuDPbg+P6BtLnVBaRJDAjv+1mrUJuRsFSjktopg==
1525+
dependencies:
1526+
"@octokit/auth-token" "^2.4.4"
1527+
"@octokit/graphql" "^4.5.8"
1528+
"@octokit/request" "^5.4.12"
1529+
"@octokit/types" "^6.0.3"
1530+
before-after-hook "^2.1.0"
1531+
universal-user-agent "^6.0.0"
1532+
15141533
"@octokit/endpoint@^6.0.0":
15151534
version "6.0.0"
15161535
resolved "https://registry.yarnpkg.com/@octokit/endpoint/-/endpoint-6.0.0.tgz#4c7acd79ab72df78732a7d63b09be53ec5a2230b"
@@ -1520,6 +1539,29 @@
15201539
is-plain-object "^3.0.0"
15211540
universal-user-agent "^5.0.0"
15221541

1542+
"@octokit/endpoint@^6.0.1":
1543+
version "6.0.11"
1544+
resolved "https://registry.yarnpkg.com/@octokit/endpoint/-/endpoint-6.0.11.tgz#082adc2aebca6dcefa1fb383f5efb3ed081949d1"
1545+
integrity sha512-fUIPpx+pZyoLW4GCs3yMnlj2LfoXTWDUVPTC4V3MUEKZm48W+XYpeWSZCv+vYF1ZABUm2CqnDVf1sFtIYrj7KQ==
1546+
dependencies:
1547+
"@octokit/types" "^6.0.3"
1548+
is-plain-object "^5.0.0"
1549+
universal-user-agent "^6.0.0"
1550+
1551+
"@octokit/graphql@^4.5.8":
1552+
version "4.6.0"
1553+
resolved "https://registry.yarnpkg.com/@octokit/graphql/-/graphql-4.6.0.tgz#f9abca55f82183964a33439d5264674c701c3327"
1554+
integrity sha512-CJ6n7izLFXLvPZaWzCQDjU/RP+vHiZmWdOunaCS87v+2jxMsW9FB5ktfIxybRBxZjxuJGRnxk7xJecWTVxFUYQ==
1555+
dependencies:
1556+
"@octokit/request" "^5.3.0"
1557+
"@octokit/types" "^6.0.3"
1558+
universal-user-agent "^6.0.0"
1559+
1560+
"@octokit/openapi-types@^5.0.0":
1561+
version "5.0.0"
1562+
resolved "https://registry.yarnpkg.com/@octokit/openapi-types/-/openapi-types-5.0.0.tgz#420853cc6d97a12521fa1d105ecc277112b32935"
1563+
integrity sha512-QXpwbGjidE+XhgCEeXpffQk/XGiexgne8czTebwU359Eoko8FJzAED4aizrQlL9t4n6tMx/1Ka1vwZbP6rayFA==
1564+
15231565
"@octokit/plugin-enterprise-rest@^6.0.1":
15241566
version "6.0.1"
15251567
resolved "https://registry.yarnpkg.com/@octokit/plugin-enterprise-rest/-/plugin-enterprise-rest-6.0.1.tgz#e07896739618dab8da7d4077c658003775f95437"
@@ -1577,6 +1619,20 @@
15771619
once "^1.4.0"
15781620
universal-user-agent "^5.0.0"
15791621

1622+
"@octokit/request@^5.3.0", "@octokit/request@^5.4.12":
1623+
version "5.4.14"
1624+
resolved "https://registry.yarnpkg.com/@octokit/request/-/request-5.4.14.tgz#ec5f96f78333bb2af390afa5ff66f114b063bc96"
1625+
integrity sha512-VkmtacOIQp9daSnBmDI92xNIeLuSRDOIuplp/CJomkvzt7M18NXgG044Cx/LFKLgjKt9T2tZR6AtJayba9GTSA==
1626+
dependencies:
1627+
"@octokit/endpoint" "^6.0.1"
1628+
"@octokit/request-error" "^2.0.0"
1629+
"@octokit/types" "^6.7.1"
1630+
deprecation "^2.0.0"
1631+
is-plain-object "^5.0.0"
1632+
node-fetch "^2.6.1"
1633+
once "^1.4.0"
1634+
universal-user-agent "^6.0.0"
1635+
15801636
"@octokit/rest@^16.28.4":
15811637
version "16.43.1"
15821638
resolved "https://registry.yarnpkg.com/@octokit/rest/-/rest-16.43.1.tgz#3b11e7d1b1ac2bbeeb23b08a17df0b20947eda6b"
@@ -1606,6 +1662,13 @@
16061662
dependencies:
16071663
"@types/node" ">= 8"
16081664

1665+
"@octokit/types@^6.0.3", "@octokit/types@^6.7.1":
1666+
version "6.9.0"
1667+
resolved "https://registry.yarnpkg.com/@octokit/types/-/types-6.9.0.tgz#08505bf87385772032e7d3b08487944f87ee6c52"
1668+
integrity sha512-j4ms2ukvWciu8hSuIWtWK/LyOWMZ0ZsRcvPIVLBYyAkTKBKrMJyiyv2wawJnyphKyEOhRgIyu5Nmf4yPxp0tcg==
1669+
dependencies:
1670+
"@octokit/openapi-types" "^5.0.0"
1671+
16091672
"@opentelemetry/api@0.14.0":
16101673
version "0.14.0"
16111674
resolved "https://registry.yarnpkg.com/@opentelemetry/api/-/api-0.14.0.tgz#4e17d8d2f1da72b19374efa7b6526aa001267cae"
@@ -3473,6 +3536,11 @@ before-after-hook@^2.0.0:
34733536
resolved "https://registry.yarnpkg.com/before-after-hook/-/before-after-hook-2.1.0.tgz#b6c03487f44e24200dd30ca5e6a1979c5d2fb635"
34743537
integrity sha512-IWIbu7pMqyw3EAJHzzHbWa85b6oud/yfKYg5rqB5hNE8CeMi3nX+2C2sj0HswfblST86hpVEOAb9x34NZd6P7A==
34753538

3539+
before-after-hook@^2.1.0:
3540+
version "2.1.1"
3541+
resolved "https://registry.yarnpkg.com/before-after-hook/-/before-after-hook-2.1.1.tgz#99ae36992b5cfab4a83f6bee74ab27835f28f405"
3542+
integrity sha512-5ekuQOvO04MDj7kYZJaMab2S8SPjGJbotVNyv7QYFCOAwrGZs/YnoDNlh1U+m5hl7H2D/+n0taaAV/tfyd3KMA==
3543+
34763544
big.js@^5.2.2:
34773545
version "5.2.2"
34783546
resolved "https://registry.yarnpkg.com/big.js/-/big.js-5.2.2.tgz#65f0af382f578bcdc742bd9c281e9cb2d7768328"
@@ -5826,6 +5894,11 @@ dot-prop@^5.2.0:
58265894
dependencies:
58275895
is-obj "^2.0.0"
58285896

5897+
dotenv@^8.2.0:
5898+
version "8.2.0"
5899+
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-8.2.0.tgz#97e619259ada750eea3e4ea3e26bceea5424b16a"
5900+
integrity sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw==
5901+
58295902
download@^8.0.0:
58305903
version "8.0.0"
58315904
resolved "https://registry.yarnpkg.com/download/-/download-8.0.0.tgz#afc0b309730811731aae9f5371c9f46be73e51b1"
@@ -8756,6 +8829,11 @@ is-plain-object@^3.0.0:
87568829
dependencies:
87578830
isobject "^4.0.0"
87588831

8832+
is-plain-object@^5.0.0:
8833+
version "5.0.0"
8834+
resolved "https://registry.yarnpkg.com/is-plain-object/-/is-plain-object-5.0.0.tgz#4427f50ab3429e9025ea7d52e9043a9ef4159344"
8835+
integrity sha512-VRSzKkbMm5jMDoKLbltAkFQ5Qr7VDiTFGXxYFXXowVj387GeGNOCsOH6Msy00SGZ3Fp84b1Naa1psqgcCIEP5Q==
8836+
87598837
is-posix-bracket@^0.1.0:
87608838
version "0.1.1"
87618839
resolved "https://registry.yarnpkg.com/is-posix-bracket/-/is-posix-bracket-0.1.1.tgz#3334dc79774368e92f016e6fbc0a88f5cd6e6bc4"
@@ -10981,7 +11059,7 @@ node-fetch-npm@^2.0.2:
1098111059
json-parse-better-errors "^1.0.0"
1098211060
safe-buffer "^5.1.1"
1098311061

10984-
node-fetch@2.6.1, node-fetch@^2.3.0, node-fetch@^2.5.0:
11062+
node-fetch@2.6.1, node-fetch@^2.3.0, node-fetch@^2.5.0, node-fetch@^2.6.1:
1098511063
version "2.6.1"
1098611064
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052"
1098711065
integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==
@@ -15869,6 +15947,11 @@ universal-user-agent@^5.0.0:
1586915947
dependencies:
1587015948
os-name "^3.1.0"
1587115949

15950+
universal-user-agent@^6.0.0:
15951+
version "6.0.0"
15952+
resolved "https://registry.yarnpkg.com/universal-user-agent/-/universal-user-agent-6.0.0.tgz#3381f8503b251c0d9cd21bc1de939ec9df5480ee"
15953+
integrity sha512-isyNax3wXoKaulPDZWHQqbmIx1k2tb9fb3GGDBRxCscfYV2Ch7WxPArBsFEG8s/safwXTT7H4QGhaIkTp9447w==
15954+
1587215955
universalify@^0.1.0:
1587315956
version "0.1.2"
1587415957
resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.2.tgz#b646f69be3942dabcecc9d6639c80dc105efaa66"

0 commit comments

Comments
 (0)