Skip to content

Commit

Permalink
Merge pull request #1897 from microsoft/44
Browse files Browse the repository at this point in the history
Automate the release plan
  • Loading branch information
Orta Therox authored Jun 22, 2021
2 parents 0a00d04 + 37d374a commit 0c8d98a
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 9 deletions.
20 changes: 16 additions & 4 deletions .github/workflows/deploy-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,30 @@ jobs:

- uses: microsoft/playwright-github-action@v1

# Build v2
- name: Build website v2
# Builds the modules, and boostraps the other modules
- name: Build website
run: |
yarn install
yarn docs-sync pull microsoft/TypeScript-Website-localizations#main 1
yarn bootstrap
yarn build
yarn build-site
cp -r packages/typescriptlang-org/public site
env:
YARN_CHECKSUM_BEHAVIOR: ignore

# Update the site plan, scoped out on its own because it gets access to secrets
- run: node packages/typescriptlang-org/scripts/getTypeScriptReleasePlan.js
env:
GITHUB_BOT_TOKEN: ${{ secrets.GITHUB_BOT_TOKEN }}
TEAMS_WEB_BOT_INCOMING_URL: ${{ secrets.TEAMS_WEB_BOT_INCOMING_URL }}

# Builds the site
- name: Makes the site
run: |
yarn build-site
cp -r packages/typescriptlang-org/public site
env:
YARN_CHECKSUM_BEHAVIOR: ignore

# Deploy to the prod appservice
- name: Deploy + Publish to AppService
uses: peaceiris/actions-gh-pages@v1.1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ const getTypeScriptNPMVersions = async () => {
? siteReleaseNotesURL
: releasePostURL

const next =
semver.minor(stable) == 9
? `${semver.major(stable) + 1}.${semver.minor(stable)}`
: `${semver.major(stable)}.${semver.minor(stable) + 1}`

return {
tags: {
stableMajMin: `${semver.major(stable)}.${semver.minor(stable)}`,
Expand All @@ -134,6 +139,7 @@ const getTypeScriptNPMVersions = async () => {
beta,
rc,
rcMajMin: `${semver.major(rc)}.${semver.minor(rc)}`,
next,
},
isRC,
isBeta,
Expand Down
121 changes: 121 additions & 0 deletions packages/typescriptlang-org/scripts/getTypeScriptReleasePlan.js
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" },
})
}
10 changes: 5 additions & 5 deletions packages/typescriptlang-org/src/lib/release-plan.json
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"
}

0 comments on commit 0c8d98a

Please sign in to comment.