diff --git a/.github/workflows/deploy-prod.yml b/.github/workflows/deploy-prod.yml index c70265c7753f..b71406902069 100644 --- a/.github/workflows/deploy-prod.yml +++ b/.github/workflows/deploy-prod.yml @@ -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 diff --git a/packages/typescriptlang-org/scripts/getTypeScriptNPMVersions.js b/packages/typescriptlang-org/scripts/getTypeScriptNPMVersions.js index 366ee89a0c72..a97fe354d50f 100644 --- a/packages/typescriptlang-org/scripts/getTypeScriptNPMVersions.js +++ b/packages/typescriptlang-org/scripts/getTypeScriptNPMVersions.js @@ -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)}`, @@ -134,6 +139,7 @@ const getTypeScriptNPMVersions = async () => { beta, rc, rcMajMin: `${semver.major(rc)}.${semver.minor(rc)}`, + next, }, isRC, isBeta, diff --git a/packages/typescriptlang-org/scripts/getTypeScriptReleasePlan.js b/packages/typescriptlang-org/scripts/getTypeScriptReleasePlan.js new file mode 100644 index 000000000000..f95a163c6520 --- /dev/null +++ b/packages/typescriptlang-org/scripts/getTypeScriptReleasePlan.js @@ -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" }, + }) +} diff --git a/packages/typescriptlang-org/src/lib/release-plan.json b/packages/typescriptlang-org/src/lib/release-plan.json index b4c408bb8494..fff3abb95116 100644 --- a/packages/typescriptlang-org/src/lib/release-plan.json +++ b/packages/typescriptlang-org/src/lib/release-plan.json @@ -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" }