From d617ea4266f188328af33dac17913115e16b52cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Pedro=20Sousa?= Date: Fri, 15 Dec 2023 00:07:51 +0000 Subject: [PATCH] chore: filtering patches from docs deployment script (#3779) # Description This change makes the script that runs before `yarn build` filter down the patches to the latest patch of every major. ## Problem\* This script used to remove: - Prereleases - Nightlies (which are prereleases) - "Aztec" versions However, this would mean that every patch, as long as it was stable, would have its own docs deployed. This would lead to docs having three patch versions, which shouldn't even differ (they're patches, no breaking changes), like 0.19.1, 0.19.2, etc ## Summary\* This change simplifies the script by removing some computation that was there just for debugging reasons. It also stops assuming all "aztec" versions are prereleases. And finally, it filters down only for the latest patch version. ## Additional Context Another way of doing it (which is how we're doing it now) is to just make all non-latest patch as prereleases, which is kinda annoying. With this change, it shouldn't matter. --- docs/.gitignore | 1 + docs/package.json | 4 +-- docs/scripts/setStable.ts | 59 +++++++++++++++++++++++++-------------- docs/tsconfig.json | 3 +- docs/versions.json | 4 --- versions.json | 4 --- 6 files changed, 43 insertions(+), 32 deletions(-) delete mode 100644 docs/versions.json delete mode 100644 versions.json diff --git a/docs/.gitignore b/docs/.gitignore index e4abc8785c7..4f6eee8284e 100644 --- a/docs/.gitignore +++ b/docs/.gitignore @@ -22,3 +22,4 @@ yarn-debug.log* yarn-error.log* package-lock.json +versions.json diff --git a/docs/package.json b/docs/package.json index 86f15b0a311..1fa4ab79b85 100644 --- a/docs/package.json +++ b/docs/package.json @@ -3,9 +3,9 @@ "version": "0.0.0", "private": true, "scripts": { - "start": "docusaurus start", + "start": "yarn version::stables && docusaurus start", "build": "yarn version::stables && docusaurus build", - "version::stables": "node --loader ts-node/esm ./scripts/setStable.ts", + "version::stables": "ts-node ./scripts/setStable.ts", "serve": "serve build" }, "dependencies": { diff --git a/docs/scripts/setStable.ts b/docs/scripts/setStable.ts index e23d990763a..0f86c4afd59 100644 --- a/docs/scripts/setStable.ts +++ b/docs/scripts/setStable.ts @@ -1,13 +1,13 @@ +/* eslint-disable @typescript-eslint/no-var-requires */ const fs = require('fs'); const path = require('path'); const axios = require('axios'); +const GITHUB_PAGES = 3; const IGNORE_VERSIONS = ['0.16.0']; -const NUMBER_OF_VERSIONS_TO_SHOW = 4; +const NUMBER_OF_VERSIONS_TO_SHOW = 2; async function main() { - const versionsFile = path.resolve('../versions.json'); - const axiosOpts = { params: { per_page: 100 }, headers: {}, @@ -15,24 +15,41 @@ async function main() { if (process.env.GITHUB_TOKEN) axiosOpts.headers = { Authorization: `token ${process.env.GITHUB_TOKEN}` }; - const { data } = await axios.get('https://api.github.com/repos/noir-lang/noir/releases', axiosOpts); - - const all = data.map((release) => release.tag_name); - console.log('All versions: ', all); - const aztecs = data.filter((release) => release.tag_name.includes('aztec')).map((release) => release.tag_name); - console.log('Removing aztecs: ', aztecs); - const prereleases = data.filter((release) => !release.prerelease).map((release) => release.tag_name); - console.log('Removing prereleases: ', prereleases); - - const stables = data - .filter((release) => !release.prerelease && !release.tag_name.includes('aztec')) - .filter((release) => !IGNORE_VERSIONS.includes(release.tag_name.replace('v', ''))) - .map((release) => release.tag_name) - .slice(0, NUMBER_OF_VERSIONS_TO_SHOW); - - console.log('Stables: ', stables); - - fs.writeFileSync(versionsFile, JSON.stringify(stables, null, 2)); + let stables = []; + console.log('Retrieved versions:'); + + for (let i = 0; i < GITHUB_PAGES; i++) { + const { data } = await axios.get(`https://api.github.com/repos/noir-lang/noir/releases?page=${i + 1}`, axiosOpts); + + console.log(data.map((release) => release.tag_name)); + stables.push( + ...data + .filter( + (release) => + !release.prerelease && !release.tag_name.includes('aztec') && !release.tag_name.includes('aztec'), + ) + .filter((release) => !IGNORE_VERSIONS.includes(release.tag_name.replace('v', ''))) + .map((release) => release.tag_name), + ); + } + + stables = stables.slice(0, NUMBER_OF_VERSIONS_TO_SHOW); + + console.log('Filtered down to stables: ', stables); + + const onlyLatestPatches = []; + const minorsSet = new Set(stables.map((el) => el.split('.')[1])); + for (const minor of minorsSet) { + const minorVersions = stables.filter((el) => el.split('.')[1] === minor); + const max = minorVersions.reduce((prev, current) => { + return prev > current ? prev : current; + }); + onlyLatestPatches.push(max); + } + + console.log('Only latest patches: ', onlyLatestPatches); + + fs.writeFileSync(path.resolve(__dirname, '../versions.json'), JSON.stringify(onlyLatestPatches, null, 2)); } main(); diff --git a/docs/tsconfig.json b/docs/tsconfig.json index 01b56ec5988..241fcf4b5e3 100644 --- a/docs/tsconfig.json +++ b/docs/tsconfig.json @@ -1,6 +1,7 @@ { "extends": "@docusaurus/tsconfig", "compilerOptions": { - "baseUrl": "." + "baseUrl": ".", + "downlevelIteration": true }, } diff --git a/docs/versions.json b/docs/versions.json deleted file mode 100644 index 7e140c94b73..00000000000 --- a/docs/versions.json +++ /dev/null @@ -1,4 +0,0 @@ -[ - "v0.19.4", - "v0.17.0" -] diff --git a/versions.json b/versions.json deleted file mode 100644 index a1c826264f4..00000000000 --- a/versions.json +++ /dev/null @@ -1,4 +0,0 @@ -[ - "v0.19.4", - "v0.17.0" -] \ No newline at end of file