diff --git a/.cirrus.yml b/.cirrus.yml index 221fb5478..e25891f58 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -36,6 +36,8 @@ linux_task: - yarn run build:apm build_binary_script: - yarn dist || yarn dist + rename_binary_script: + - node script/rename.js "Linux" binary_artifacts: path: ./binaries/* test_script: @@ -91,6 +93,8 @@ arm_linux_task: - yarn run build:apm build_binary_script: - yarn dist || yarn dist + rename_binary_script: + - node script/rename.js "ARM.Linux" binary_artifacts: path: ./binaries/* test_script: @@ -134,6 +138,8 @@ silicon_mac_task: build_binary_script: - export PATH="/opt/homebrew/bin:/opt/homebrew/opt/node@16/bin:$PATH" - yarn dist || yarn dist + rename_binary_script: + - node script/rename.js "Silicon.Mac" binary_artifacts: path: ./binaries/* test_script: @@ -182,6 +188,8 @@ intel_mac_task: build_binary_script: - export PATH="/usr/local/opt/node@16/bin:/usr/local/bin:$PATH" - arch -x86_64 npx yarn dist || arch -x86_64 npx yarn dist + rename_binary_script: + - node script/rename.js "Intel.Mac" binary_artifacts: path: ./binaries/* test_script: @@ -223,6 +231,8 @@ windows_task: build_binary_script: - sed -i -e "s/[0-9]*-dev/`date -u +%Y%m%d%H`/g" package.json - npx yarn dist || npx yarn dist || npx yarn dist + rename_binary_script: + - node script\rename.js "Windows" binary_artifacts: path: .\binaries\* test_script: diff --git a/script/rename.js b/script/rename.js new file mode 100644 index 000000000..0034af364 --- /dev/null +++ b/script/rename.js @@ -0,0 +1,44 @@ +console.log("Starting the binary renaming script..."); + +const fs = require('fs'); + +const prefix = process.argv[2]; + +const pulsarVersion = require('../package.json').version + +if (pulsarVersion.endsWith('-dev')) { + console.log(`Based on the version string in package.json (${pulsarVersion}),`); + console.log('we are not preparing a Regular release, so not renaming any binaries.'); + console.log('Exiting the binary renaming script.'); +} else { + + // Warn about required prefix as first argument. + // If prefix was not provided, print warning and do nothing else, exiting "cleanly" with status 0. + if (typeof prefix !== "string" || prefix.length === 0) { + console.log("A prefix is required. Pass the desired prefix as the first argument to this script."); + console.log('Example usage: "node script/rename.js Windows"'); + console.log('or: "node script/rename.js ARM.Linux"'); + console.log("Exiting the binary renaming script."); + } else { + console.log(`Prefix is: ${prefix}`); + + // Rename files under ./binaries/* that haven't already been renamed + const fileNames = fs.readdirSync('./binaries'); + + fileNames.forEach((file) => { + console.log(`Existing filename is: ${file}`); + + // We use 'starting with "p" or "P"' as the heuristic + // for whether or not the file has already been renamed (and thus prefixed) before. + if (file.startsWith('p') || file.startsWith('P')) { + let dest = `${prefix}.${file}` + // Replace any spaces with periods in the resulting filenames + dest = dest.replace(/ /g,"."); + console.log(`Renaming file from "${file}" to "${dest}"`); + fs.renameSync(`./binaries/${file}`, `./binaries/${dest}`); + } else { + console.log('Filename does not start with "p" or "P". Skipping...'); + }; + }); + }; +};