Skip to content

Commit

Permalink
chore: filtering patches from docs deployment script (#3779)
Browse files Browse the repository at this point in the history
# 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.
  • Loading branch information
signorecello authored Dec 15, 2023
1 parent ea4d89d commit d617ea4
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 32 deletions.
1 change: 1 addition & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ yarn-debug.log*
yarn-error.log*

package-lock.json
versions.json
4 changes: 2 additions & 2 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
59 changes: 38 additions & 21 deletions docs/scripts/setStable.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,55 @@
/* 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: {},
};

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();
3 changes: 2 additions & 1 deletion docs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "@docusaurus/tsconfig",
"compilerOptions": {
"baseUrl": "."
"baseUrl": ".",
"downlevelIteration": true
},
}
4 changes: 0 additions & 4 deletions docs/versions.json

This file was deleted.

4 changes: 0 additions & 4 deletions versions.json

This file was deleted.

0 comments on commit d617ea4

Please sign in to comment.