Skip to content

Commit

Permalink
use tags parsing for basis of deployed docs versions
Browse files Browse the repository at this point in the history
  • Loading branch information
sh-rp committed Aug 29, 2024
1 parent 726ceab commit 52ab6ea
Showing 1 changed file with 41 additions and 9 deletions.
50 changes: 41 additions & 9 deletions docs/website/tools/update_versions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const proc = require('child_process')
const fs = require('fs');
const semver = require('semver')


// const
REPO_DIR = ".dlt-repo"
Expand All @@ -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 })
Expand All @@ -35,19 +67,19 @@ 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:`)
proc.execSync(`cd ${REPO_DIR} && git checkout ${version}`)
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
Expand Down

0 comments on commit 52ab6ea

Please sign in to comment.