diff --git a/.gitignore b/.gitignore index 77d1f7cec0545a216b17f4e1a22820c3f2a27832..fac5f4f55c78b4901a29f5303c3b4932a6b2e9e9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ /.cache/ /.idea/ /.nyc_output/ +/build/ /node_modules/ /packages/*/node_modules/ /reports/ diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index fed906bbcb2691d0d02461a2f938584632e4e5fe..864f70ebd7069bd2c5c0aee95c9db1049b7fe419 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -9,6 +9,7 @@ For a detailed view of what's changed, refer to the {url-repo}/commits[commit hi === Changed * upgrade isomorphic-git and make use of new force flag on branch function +* automatically set release AsciiDoc attributes in docs descriptor during release (#6) === Fixed diff --git a/docs/antora.yml b/docs/antora.yml index bd412138db39963a41b8c35ac108ee46c2861836..2b8ba5e7ce94dc21f0f8f41cff4ef4284b3469de 100644 --- a/docs/antora.yml +++ b/docs/antora.yml @@ -4,8 +4,12 @@ version: '1.0' prerelease: '.0-alpha.2' asciidoc: attributes: - antora-minimum-version: '3.1' - node-version: '16.17.0' + version-antora-min: '3.1' + version-node-min: '16' + version-node: '18.12.0' + release-version: '1.0.0-alpha.2' + release-dist-tag: latest + release-date: '2022-09-02' url-repo: https://gitlab.com/antora/antora-collector-extension url-chat: https://chat.antora.org nav: diff --git a/docs/modules/ROOT/pages/install.adoc b/docs/modules/ROOT/pages/install.adoc index fd8f8f5c0c2c4848e2c35630c7881c6fecc5dfec..07f4d902b52010e114a28ffe5d47633da4c0428e 100644 --- a/docs/modules/ROOT/pages/install.adoc +++ b/docs/modules/ROOT/pages/install.adoc @@ -1,7 +1,7 @@ = Install the Collector Extension :navtitle: Install -The Antora Collector extension requires Node.js 16 or greater and Antora {antora-minimum-version} or greater. +The Antora Collector extension requires Node.js {version-node-min} or greater and Antora {version-antora-min} or greater. == Prerequisites @@ -14,7 +14,7 @@ If you install the prerequisites and Collector extension globally, conflicts wit === Node.js -This software requires Node.js 16 or greater. +This software requires Node.js {version-node-min} or greater. To see if you have Node.js installed, and which version, type: $ node -v @@ -23,7 +23,7 @@ You should see a version string, such as: [subs=attributes+] $ node -v - v{node-version} + v{version-node} If no version number is displayed in your terminal, you need to install Node.js. Follow one of these guides to learn how to install nvm and Node.js on your platform. @@ -34,13 +34,13 @@ Follow one of these guides to learn how to install nvm and Node.js on your platf === Antora -The Collector extension requires Antora {antora-minimum-version} or greater. -To confirm you have Antora {antora-minimum-version} or greater installed in your playbook directory, run: +The Collector extension requires Antora {version-antora-min} or greater. +To confirm you have a suitable version of Antora installed, run: $ npx antora -v The command should report the version of the Antora CLI and site generator you have installed. -If you're not yet using Antora {antora-minimum-version} or greater, you need to xref:antora:install:upgrade-antora.adoc[upgrade] to use the Collector extension. +If you're not yet using Antora {version-antora-min} or greater, you need to xref:antora:install:upgrade-antora.adoc[upgrade] to use the Collector extension. Once you've satisfied the prerequisites, you're ready to install the Collector extension in your playbook project. diff --git a/npm/postrelease.js b/npm/postrelease.js new file mode 100644 index 0000000000000000000000000000000000000000..36887a06b5b73a2d8b5272b205846ee4b7eac666 --- /dev/null +++ b/npm/postrelease.js @@ -0,0 +1,29 @@ +'use strict' + +const { promises: fsp } = require('fs') +const ospath = require('path') + +const PROJECT_ROOT_DIR = ospath.join(__dirname, '..') +const DOCS_CONFIG_FILE = ospath.join(PROJECT_ROOT_DIR, 'docs/antora.yml') +const VERSION = process.env.npm_package_version + +function updateDocsConfig () { + const hyphenIdx = VERSION.indexOf('-') + const main = ~hyphenIdx ? VERSION.substr(0, hyphenIdx) : VERSION + const prerelease = ~hyphenIdx ? VERSION.substr(hyphenIdx + 1) : undefined + const [major, minor, patch] = main.split('.') + return fsp.readFile(DOCS_CONFIG_FILE, 'utf8').then((docsConfig) => { + docsConfig = docsConfig + .replace(/^version: \S+$/m, `version: ${q(major + '.' + minor)}`) + .replace(/^prerelease: \S+$/m, `prerelease: ${prerelease ? q('.' + patch + '-' + prerelease) : 'false'}`) + return fsp.writeFile(DOCS_CONFIG_FILE, docsConfig, 'utf8') + }) +} + +function q (str) { + return `'${str}'` +} + +;(async () => { + await updateDocsConfig() +})() diff --git a/npm/release.sh b/npm/release.sh index 5bdc423c1fce623c99839d65c265716120253380..7f5a07e1fe15c2805ab32316742591a68a7c7160 100755 --- a/npm/release.sh +++ b/npm/release.sh @@ -70,10 +70,12 @@ echo -e "//registry.npmjs.org/:_authToken=$RELEASE_NPM_TOKEN" > $HOME/.npmrc if case $RELEASE_VERSION in 1.0.0-*) ;; *) false;; esac; then RELEASE_NPM_TAG=latest fi - git commit -a -m "release $RELEASE_VERSION [skip ci]" + git commit -a -m "release $RELEASE_VERSION" git tag -m "version $RELEASE_VERSION" v$RELEASE_VERSION git push origin $(git describe --tags --exact-match) npm publish --access public --tag $RELEASE_NPM_TAG $(node npm/publish-workspace-args.js) + npm run postrelease + git commit -a -m "prepare branch for development [skip ci]" git push origin $RELEASE_BRANCH ) exit_code=$? diff --git a/npm/version.js b/npm/version.js index 44fc8b56f02a0a40cfc22062ec95bedf5dc1d791..cd6d22bef9b6c71c30d34f5d66788fdde9a4db4f 100644 --- a/npm/version.js +++ b/npm/version.js @@ -1,8 +1,10 @@ 'use strict' const { promises: fsp } = require('fs') +const https = require('https') const ospath = require('path') +const NODEJS_RELEASES_URL = 'https://nodejs.org/dist/index.json' const PROJECT_ROOT_DIR = ospath.join(__dirname, '..') const CHANGELOG_FILE = ospath.join(PROJECT_ROOT_DIR, 'CHANGELOG.adoc') const DOCS_CONFIG_FILE = ospath.join(PROJECT_ROOT_DIR, 'docs/antora.yml') @@ -10,27 +12,63 @@ const PACKAGE_LOCK_FILE = ospath.join(PROJECT_ROOT_DIR, 'package-lock.json') const PACKAGES_DIR = ospath.join(PROJECT_ROOT_DIR, 'packages') const VERSION = process.env.npm_package_version -function getCurrentDate () { - const now = new Date() +function compareSemVer (a, b) { + const componentsA = a.split('.') + const componentsB = b.split('.') + for (let i = 0; i < 3; i++) { + const numA = Number(componentsA[i]) + const numB = Number(componentsB[i]) + if (numA > numB) return 1 + if (numB > numA) return -1 + } + return 0 +} + +function getCurrentDate (now = new Date()) { return new Date(now.getTime() - now.getTimezoneOffset() * 60000) } -function updateDocsConfig () { - const hyphenIdx = VERSION.indexOf('-') - const base = ~hyphenIdx ? VERSION.substr(0, hyphenIdx) : VERSION - const [major, minor, patch] = base.split('.') - const prerelease = ~hyphenIdx ? VERSION.substr(hyphenIdx + 1) : undefined - return fsp - .readFile(DOCS_CONFIG_FILE, 'utf8') - .then((docsConfig) => - fsp.writeFile( - DOCS_CONFIG_FILE, - docsConfig - .replace(/^version: \S+$/m, `version: ${q(major + '.' + minor)}`) - .replace(/^prerelease: \S+$/m, `prerelease: ${prerelease ? q('.' + patch + '-' + prerelease) : 'false'}`), - 'utf8' - ) - ) +function getToolVersions (major) { + return readFromURL(NODEJS_RELEASES_URL) + .then(JSON.parse) + .then((data) => { + data.forEach((it) => { + if (it.version.charAt() === 'v') it.version = it.version.substr(1) + }) + data.sort(({ version: a }, { version: b }) => compareSemVer(b, a)) + const { version, npm } = data.find(major ? ({ version }) => version.startsWith(major + '.') : ({ lts }) => lts) + return { nodeVersion: version, npmVersion: npm } + }) +} + +function readFromURL (url) { + return new Promise((resolve, reject) => { + const buffer = [] + https + .get(url, (response) => { + response.on('data', (chunk) => buffer.push(chunk.toString())) + response.on('end', () => resolve(buffer.join('').trimRight())) + }) + .on('error', reject) + }) +} + +function updateDocsConfig (releaseDate) { + return getToolVersions().then(({ nodeVersion }) => + fsp.readFile(DOCS_CONFIG_FILE, 'utf8').then((contents) => { + const prerelease = ~VERSION.indexOf('-') + const distTag = prerelease && !VERSION.startsWith('1.0.0-') ? 'testing' : 'latest' + contents = contents + .replace(/^(version:) \S+$/m, `$1 ${q(VERSION)}`) + .replace(/^(prerelease:) \S+$/m, `$1 ${prerelease ? 'true' : 'false'}`) + .replace(/^( {4}release-version:) \S+$/m, `$1 ${q(VERSION)}`) + .replace(/^( {4}release-dist-tag:) \S+$/m, `$1 ${distTag}`) + .replace(/^( {4}release-date:) \S+$/m, `$1 ${q(releaseDate)}`) + .replace(/^( {4}version-node-major:) \S+$/m, `$1 ${q(nodeVersion.split('.')[0])}`) + .replace(/^( {4}version-node:) \S+$/m, `$1 ${q(nodeVersion)}`) + return fsp.writeFile(DOCS_CONFIG_FILE, contents, 'utf8') + }) + ) } function updateChangelog (releaseDate) { @@ -89,7 +127,7 @@ function q (str) { ;(async () => { const releaseDate = getCurrentDate().toISOString().split('T')[0] - await updateDocsConfig() + await updateDocsConfig(releaseDate) await updateChangelog(releaseDate) await updatePackageLock() })() diff --git a/package.json b/package.json index 946dc217657973b399766a7e2d9b6ba2f395e09c..0d004da70929078235285c279fe81efd25171d00 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "coverage": "nyc _mocha", "format": "node npm/format.js packages/${npm_config_package},npm", "lint": "eslint \"{docs,npm}/**/*.js\" \"packages/${npm_config_package:-*}/{lib,test}/**/*.js\"", + "postrelease": "node npm/postrelease.js", "test": "_mocha", "version": "node npm/version.js" },