-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1897 from microsoft/44
Automate the release plan
- Loading branch information
Showing
4 changed files
with
148 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
packages/typescriptlang-org/scripts/getTypeScriptReleasePlan.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
// This script relies on getTypeScriptNPMVersions.js having been ran already | ||
// it will grab the latest TypeScript issue with info about the iteration plan | ||
// and turn that into structured data. | ||
|
||
// node packages/typescriptlang-org/scripts/getTypeScriptReleasePlan.js | ||
|
||
const Octokit = require("@octokit/rest") | ||
const versionMeta = require("../src/lib/release-info.json") | ||
const fetch = require("node-fetch") | ||
const { format } = require("prettier") | ||
const { writeFileSync } = require("fs") | ||
const { join } = require("path") | ||
|
||
const token = process.env.GITHUB_BOT_TOKEN || process.env.GITHUB_TOKEN | ||
if (!token) throw new Error("No GitHub Token at process.env.GITHUB_BOT_TOKEN") | ||
|
||
const go = async () => { | ||
const octokit = new Octokit({ | ||
auth: token, | ||
userAgent: "TS Website Issue Searcher", | ||
}) | ||
|
||
const issues = await octokit.search.issuesAndPullRequests({ | ||
q: "iteration plan repo:microsoft/typescript state:open type:issues", | ||
}) | ||
|
||
const upcoming = issues.data.items.find( | ||
i => | ||
i.title.toLowerCase().includes(versionMeta.tags.next) && | ||
i.labels.find(l => l.name === "Planning") | ||
) | ||
|
||
// Couldn't find the issue, bail, | ||
if (!upcoming) { | ||
return sendTeamsFail( | ||
`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` | ||
) | ||
} | ||
|
||
const lines = upcoming.body.toLowerCase().split("\n") | ||
const lastRelease = lines.find( | ||
l => | ||
l.includes(`${versionMeta.tags.stableMajMin} release`) && l.includes("|") | ||
) | ||
const beta = lines.find( | ||
l => l.includes(`${versionMeta.tags.next} beta release`) && l.includes("|") | ||
) | ||
|
||
const rc = lines.find( | ||
l => l.includes(`${versionMeta.tags.next} rc release`) && l.includes("|") | ||
) | ||
|
||
const release = lines.find( | ||
l => l.includes(`${versionMeta.tags.next} final release`) && l.includes("|") | ||
) | ||
|
||
// Making sure we got good data | ||
const dates = { | ||
lastRelease, | ||
beta, | ||
rc, | ||
release, | ||
} | ||
const missing = [] | ||
Object.keys(dates).forEach(key => { | ||
if (!dates[key]) { | ||
missing.push(key) | ||
} | ||
}) | ||
if (missing.length) { | ||
// prettier-ignore | ||
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`) | ||
} | ||
|
||
// "june 29th | **typescript 4.4 beta release**\r" -> Date | ||
const toDate = str => { | ||
const date = str.split("|")[0].trim() | ||
const components = date.split(" ") | ||
const month = components[0] | ||
const day = components[1].replace("th", "").replace("st", "") | ||
const thisYear = new Date().getFullYear() | ||
const year = parseInt(components[2]) || thisYear | ||
return new Date(`${month} ${day} ${year}`).toISOString() | ||
} | ||
|
||
const results = { | ||
"_generated by": | ||
"node packages/typescriptlang-org/scripts/getTypeScriptReleasePlan.js", | ||
upcoming_version: versionMeta.tags.next, | ||
iteration_plan_url: `https://github.com/microsoft/TypeScript/issues/${upcoming.number}`, | ||
last_release_date: toDate(lastRelease), | ||
upcoming_beta_date: toDate(beta), | ||
upcoming_rc_date: toDate(rc), | ||
upcoming_release_date: toDate(release), | ||
} | ||
const jsonPath = join(__dirname, "..", "src", "lib", "release-plan.json") | ||
|
||
writeFileSync( | ||
jsonPath, | ||
format(JSON.stringify(results), { filepath: jsonPath }) | ||
) | ||
} | ||
|
||
go() | ||
|
||
const sendTeamsFail = title => { | ||
const teamsURL = process.env.TEAMS_WEB_BOT_INCOMING_URL | ||
const message = { | ||
"@type": "MessageCard", | ||
"@context": "https://schema.org/extensions", | ||
summary: "Website issue", | ||
themeColor: "0078D7", | ||
title, | ||
} | ||
|
||
fetch(teamsURL, { | ||
method: "post", | ||
body: JSON.stringify(message), | ||
headers: { "Content-Type": "application/json" }, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
{ | ||
"_format": "mm/dd/yyyy - these get put into new Date()", | ||
"_generated by": "node packages/typescriptlang-org/scripts/getTypeScriptReleaseInfo.js", | ||
"upcoming_version": "4.4", | ||
"iteration_plan_url": "https://github.com/microsoft/TypeScript/issues/44237", | ||
"last_release_date": "05/25/2021", | ||
"upcoming_beta_date": "06/25/2021", | ||
"upcoming_rc_date": "07/06/2021", | ||
"upcoming_release_date": "07/24/2021" | ||
"last_release_date": "2021-05-24T23:00:00.000Z", | ||
"upcoming_beta_date": "2021-06-28T23:00:00.000Z", | ||
"upcoming_rc_date": "2021-08-09T23:00:00.000Z", | ||
"upcoming_release_date": "2021-08-23T23:00:00.000Z" | ||
} |