Skip to content

Commit 77e14cc

Browse files
committed
Automate the release plan json
1 parent d396fb4 commit 77e14cc

File tree

3 files changed

+129
-5
lines changed

3 files changed

+129
-5
lines changed

packages/typescriptlang-org/scripts/getTypeScriptNPMVersions.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ const getTypeScriptNPMVersions = async () => {
126126
? siteReleaseNotesURL
127127
: releasePostURL
128128

129+
const next =
130+
semver.minor(stable) == 9
131+
? `${semver.major(stable) + 1}.${semver.minor(stable)}`
132+
: `${semver.major(stable)}.${semver.minor(stable) + 1}`
133+
129134
return {
130135
tags: {
131136
stableMajMin: `${semver.major(stable)}.${semver.minor(stable)}`,
@@ -134,6 +139,7 @@ const getTypeScriptNPMVersions = async () => {
134139
beta,
135140
rc,
136141
rcMajMin: `${semver.major(rc)}.${semver.minor(rc)}`,
142+
next,
137143
},
138144
isRC,
139145
isBeta,
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
// This script relies on getTypeScriptNPMVersions.js having been ran already
2+
// node packages/typescriptlang-org/scripts/getTypeScriptReleaseInfo.js
3+
4+
const Octokit = require("@octokit/rest")
5+
const versionMeta = require("../src/lib/release-info.json")
6+
const fetch = require("node-fetch")
7+
const { format } = require("prettier")
8+
const { writeFileSync, existsSync } = require("fs")
9+
const { join, dirname } = require("path")
10+
11+
const token = process.env.GITHUB_BOT_TOKEN || process.env.GITHUB_TOKEN
12+
if (!token) throw new Error("No GitHub Token at process.env.GITHUB_BOT_TOKEN")
13+
14+
const go = async () => {
15+
const octokit = new Octokit({
16+
auth: token,
17+
userAgent: "TS Website Issue Searcher",
18+
})
19+
20+
const issues = await octokit.search.issuesAndPullRequests({
21+
q: "iteration plan repo:microsoft/typescript state:open type:issues",
22+
})
23+
24+
const upcoming = issues.data.items.find(
25+
i =>
26+
i.title.toLowerCase().includes(versionMeta.tags.next) &&
27+
i.labels.find(l => l.name === "Planning")
28+
)
29+
30+
// Couldn't find the issue, bail,
31+
if (!upcoming) {
32+
return sendTeamsFail(
33+
`Could not find an iteration plan issue for ${versionMeta.tags.next} during the most recent site deploy - see https://github.com/microsoft/TypeScript-website/blob/v2/packages/typescriptlang-org/scripts/getTypeScriptReleaseInfo.js`
34+
)
35+
}
36+
37+
const lines = upcoming.body.toLowerCase().split("\n")
38+
const lastRelease = lines.find(
39+
l =>
40+
l.includes(`${versionMeta.tags.stableMajMin} release`) && l.includes("|")
41+
)
42+
const beta = lines.find(
43+
l => l.includes(`${versionMeta.tags.next} beta release`) && l.includes("|")
44+
)
45+
46+
const rc = lines.find(
47+
l => l.includes(`${versionMeta.tags.next} rc release`) && l.includes("|")
48+
)
49+
50+
const release = lines.find(
51+
l => l.includes(`${versionMeta.tags.next} final release`) && l.includes("|")
52+
)
53+
54+
// Making sure we got good data
55+
const dates = {
56+
lastRelease,
57+
beta,
58+
rc,
59+
release,
60+
}
61+
const missing = []
62+
Object.keys(dates).forEach(key => {
63+
if (!dates[key]) {
64+
missing.push(key)
65+
}
66+
})
67+
if (missing.length) {
68+
// prettier-ignore
69+
return sendTeamsFail(`Could not parse the md table for ${missing.join(",")} in https://github.com/microsoft/TypeScript/issues/${upcoming.number} - see https://github.com/microsoft/TypeScript-website/blob/v2/packages/typescriptlang-org/scripts/getTypeScriptReleaseInfo.js`)
70+
}
71+
72+
// "june 29th | **typescript 4.4 beta release**\r" -> Date
73+
const toDate = str => {
74+
const date = str.split("|")[0].trim()
75+
const components = date.split(" ")
76+
const month = components[0]
77+
const day = components[1].replace("th", "").replace("st", "")
78+
const thisYear = new Date().getFullYear()
79+
const year = parseInt(components[2]) || thisYear
80+
return new Date(`${month} ${day} ${year}`).toISOString()
81+
}
82+
83+
const results = {
84+
"_generated by":
85+
"node packages/typescriptlang-org/scripts/getTypeScriptReleaseInfo.js",
86+
upcoming_version: versionMeta.tags.next,
87+
iteration_plan_url: `https://github.com/microsoft/TypeScript/issues/${upcoming.number}`,
88+
last_release_date: toDate(lastRelease),
89+
upcoming_beta_date: toDate(beta),
90+
upcoming_rc_date: toDate(rc),
91+
upcoming_release_date: toDate(release),
92+
}
93+
const jsonPath = join(__dirname, "..", "src", "lib", "release-plan.json")
94+
95+
writeFileSync(
96+
jsonPath,
97+
format(JSON.stringify(results), { filepath: jsonPath })
98+
)
99+
}
100+
101+
go()
102+
103+
const sendTeamsFail = title => {
104+
const teamsURL = process.env.TEAMS_WEB_BOT_INCOMING_URL
105+
const message = {
106+
"@type": "MessageCard",
107+
"@context": "https://schema.org/extensions",
108+
summary: "Website issue",
109+
themeColor: "0078D7",
110+
title,
111+
}
112+
113+
fetch(teamsURL, {
114+
method: "post",
115+
body: JSON.stringify(message),
116+
headers: { "Content-Type": "application/json" },
117+
})
118+
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2-
"_format": "mm/dd/yyyy - these get put into new Date()",
2+
"_generated by": "node packages/typescriptlang-org/scripts/getTypeScriptReleaseInfo.js",
33
"upcoming_version": "4.4",
44
"iteration_plan_url": "https://github.com/microsoft/TypeScript/issues/44237",
5-
"last_release_date": "05/25/2021",
6-
"upcoming_beta_date": "06/25/2021",
7-
"upcoming_rc_date": "07/06/2021",
8-
"upcoming_release_date": "07/24/2021"
5+
"last_release_date": "2021-05-24T23:00:00.000Z",
6+
"upcoming_beta_date": "2021-06-28T23:00:00.000Z",
7+
"upcoming_rc_date": "2021-08-09T23:00:00.000Z",
8+
"upcoming_release_date": "2021-08-23T23:00:00.000Z"
99
}

0 commit comments

Comments
 (0)