|
| 1 | +"use strict"; |
| 2 | +const fs = require("fs"); |
| 3 | +const child_process = require("child_process"); |
| 4 | +module.exports.register = function () { |
| 5 | + this.on("playbookBuilt", function ({ playbook }) { |
| 6 | + // Get versions from Makefile |
| 7 | + // Use utf8 encoding to have a string rather than a buffer in the output |
| 8 | + const ocp_ver_full = child_process.execSync( |
| 9 | + "grep '^OPENSHIFT_VERSION' Makefile | cut -d' ' -f3 | tr -d '\n'", |
| 10 | + { encoding: "utf8" } |
| 11 | + ); |
| 12 | + const ocp_ver = child_process.execSync( |
| 13 | + "grep '^OPENSHIFT_VERSION' Makefile | cut -d' ' -f3 | cut -d'.' -f-2 | tr -d '\n'", |
| 14 | + { encoding: "utf8" } |
| 15 | + ); |
| 16 | + const podman_ver = child_process.execSync( |
| 17 | + "grep '^PODMAN_VERSION' Makefile | cut -d' ' -f3 | tr -d '\n'", |
| 18 | + { encoding: "utf8" } |
| 19 | + ); |
| 20 | + const prod_ver_full = child_process.execSync( |
| 21 | + "grep '^CRC_VERSION' Makefile | cut -d' ' -f3 | tr -d '\n'", |
| 22 | + { encoding: "utf8" } |
| 23 | + ); |
| 24 | + const prod_ver = child_process.execSync( |
| 25 | + "grep '^CRC_VERSION' Makefile | cut -d' ' -f3 | cut -d'.' -f-2 | tr -d '\n'", |
| 26 | + { encoding: "utf8" } |
| 27 | + ); |
| 28 | + const ushift_ver = child_process.execSync( |
| 29 | + "grep '^MICROSHIFT_VERSION' Makefile | cut -d' ' -f3 | tr -d '\n'", |
| 30 | + { encoding: "utf8" } |
| 31 | + ); |
| 32 | + |
| 33 | + // Display versions |
| 34 | + console.log("OpenShift patch version: " + ocp_ver_full); |
| 35 | + console.log("OpenShift minor version: " + ocp_ver); |
| 36 | + console.log("Podman version: " + podman_ver); |
| 37 | + console.log("CRC patch version: " + prod_ver_full); |
| 38 | + console.log("CRC minor version: " + prod_ver); |
| 39 | + console.log("MicroShift version: " + ushift_ver); |
| 40 | + |
| 41 | + // Set attributes values |
| 42 | + Object.assign(playbook.asciidoc.attributes, { |
| 43 | + "ocp-ver": ocp_ver, |
| 44 | + "ocp-ver-full": ocp_ver_full, |
| 45 | + "podman-ver": podman_ver, |
| 46 | + "prod-ver": prod_ver, |
| 47 | + "prod-ver-full": prod_ver_full, |
| 48 | + "ushift-ver": ushift_ver, |
| 49 | + }); |
| 50 | + this.updateVariables({ playbook }); |
| 51 | + }); |
| 52 | +}; |
0 commit comments