diff --git a/docs/website/tools/update_versions.js b/docs/website/tools/update_versions.js index b41f592612..c9eb256124 100644 --- a/docs/website/tools/update_versions.js +++ b/docs/website/tools/update_versions.js @@ -1,5 +1,7 @@ const proc = require('child_process') const fs = require('fs'); +const semver = require('semver') + // const REPO_DIR = ".dlt-repo" @@ -8,11 +10,41 @@ REPO_URL = "https://github.com/dlt-hub/dlt.git" VERSIONED_DOCS_FOLDER = "versioned_docs" VERSIONED_SIDEBARS_FOLDER = "versioned_sidebars" -// TODO: get tags automatically, put newest version on top -const VERSIONS = [ - "0.5.4", - "0.4.12", -] +// no doc versions below this version will be deployed +MINIMUM_SEMVER_VERSION = "0.4.0" + +// find tags +console.log("Discovering versions") +const tags = proc.execSync(`git tag`).toString().trim().split("\n"); +console.log(`Found ${tags.length} tags`) + +// parse and filter invalid tags +let versions = tags.map(v => semver.valid(v)).filter(v => v != null) + +// remove all tags below the min version and sort +min_version = semver.valid(MINIMUM_SEMVER_VERSION) +versions = semver.rsort(versions.filter(v => semver.gt(v, min_version))) + +// remove prelease versions +versions.filter(v => semver.prerelease(v) == null) + +console.log(`Found ${versions.length} elligible versions`) +if (versions.length < 5) { + console.error("Sanity check failed, not enough elligble version tags found") + process.exit(1) +} + +// go through the versions and find all newest versions of minor versions +const selectedVersions = [versions[0]]; +let lastVersion = versions[0]; +for (let ver of versions) { + if (semver.minor(ver) != semver.minor(lastVersion) || semver.major(ver) != semver.major(lastVersion)) { + selectedVersions.push(ver) + } + lastVersion = ver; +} + +console.log(`Will create docs versions for ${selectedVersions}`) // create folders fs.rmSync(VERSIONED_DOCS_FOLDER, { recursive: true, force: true }) @@ -35,11 +67,11 @@ const branch = proc.execSync(`cd ${REPO_DIR} && git rev-parse --abbrev-ref HEAD` if (branch != "devel") { console.error("Could not check out devel branch") - process.exit() + process.exit(1) } -VERSIONS.reverse() -for (const version of VERSIONS) { +selectedVersions.reverse() +for (const version of selectedVersions) { // checkout verison and verify we have the right tag console.log(`Generating version ${version}, switching to tag:`) @@ -47,7 +79,7 @@ for (const version of VERSIONS) { const tag = proc.execSync(`cd ${REPO_DIR} && git describe --exact-match --tags`).toString().trim() if (tag != version) { console.error(`Could not checkout version ${version}`) - process.exit() + process.exit(1) } // build doc version, we also run preprocessing and markdown gen for each doc version