Skip to content

Commit

Permalink
docs: added an Antora extension that get versions from Makefile an in…
Browse files Browse the repository at this point in the history
…ject the result as AsciiDoc attributes

Signed-off-by: Fabrice Flore-Thébault <[email protected]>
  • Loading branch information
themr0c committed Sep 26, 2023
1 parent f69c337 commit 920aaa1
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
3 changes: 2 additions & 1 deletion antora-playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ urls:
redirect_facility: static
antora:
extensions:
- "@antora/lunr-extension"
# - "@antora/lunr-extension"
- ./docs/extensions/get-versions.js
asciidoc:
sourcemap: true
attributes:
Expand Down
52 changes: 52 additions & 0 deletions docs/extensions/get-versions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"use strict";
const fs = require("fs");
const child_process = require("child_process");
module.exports.register = function () {
this.on("playbookBuilt", function ({ playbook }) {
// Get versions from Makefile
// Use utf8 encoding to have a string rather than a buffer in the output
const ocp_ver_full = child_process.execSync(
"grep '^OPENSHIFT_VERSION' Makefile | cut -d' ' -f3 | tr -d '\n'",
{ encoding: "utf8" }
);
const ocp_ver = child_process.execSync(
"grep '^OPENSHIFT_VERSION' Makefile | cut -d' ' -f3 | cut -d'.' -f-2 | tr -d '\n'",
{ encoding: "utf8" }
);
const podman_ver = child_process.execSync(
"grep '^PODMAN_VERSION' Makefile | cut -d' ' -f3 | tr -d '\n'",
{ encoding: "utf8" }
);
const prod_ver_full = child_process.execSync(
"grep '^CRC_VERSION' Makefile | cut -d' ' -f3 | tr -d '\n'",
{ encoding: "utf8" }
);
const prod_ver = child_process.execSync(
"grep '^CRC_VERSION' Makefile | cut -d' ' -f3 | cut -d'.' -f-2 | tr -d '\n'",
{ encoding: "utf8" }
);
const ushift_ver = child_process.execSync(
"grep '^MICROSHIFT_VERSION' Makefile | cut -d' ' -f3 | tr -d '\n'",
{ encoding: "utf8" }
);

// Display versions
console.log("OpenShift patch version: " + ocp_ver_full);
console.log("OpenShift minor version: " + ocp_ver);
console.log("Podman version: " + podman_ver);
console.log("CRC patch version: " + prod_ver_full);
console.log("CRC minor version: " + prod_ver);
console.log("MicroShift version: " + ushift_ver);

// Set attributes values
Object.assign(playbook.asciidoc.attributes, {
"ocp-ver": ocp_ver,
"ocp-ver-full": ocp_ver_full,
"podman-ver": podman_ver,
"prod-ver": prod_ver,
"prod-ver-full": prod_ver_full,
"ushift-ver": ushift_ver,
});
this.updateVariables({ playbook });
});
};

0 comments on commit 920aaa1

Please sign in to comment.