Verified Commit 2dcd3431 authored by Aral Balkan's avatar Aral Balkan
Browse files

Update build script

  - Rebuild node_modules before deployment builds.
  - Change order to operations to leave zipping and copying to end.
parent 84e48e09
......@@ -233,6 +233,16 @@ async function buildBinary () {
// are not all included in the various builds.
const nodeModulesPath = path.resolve(__dirname, '..', 'node_modules')
if (commandLineOptions.deploy) {
//
// Rebuild node_modules to ensure that all dependencies are as we expect them.
//
console.log(' • Rebuilding node modules before creating deployment builds…')
fs.removeSync(nodeModulesPath)
childProcess.execSync('npm i', {env: process.env, cwd: mainSourceDirectory})
}
const mkcertBinaryDirectoryPath = path.join(nodeModulesPath, '@small-tech', 'auto-encrypt-localhost', 'mkcert-bin')
const hugoBinaryDirectoryPath = path.join(nodeModulesPath, '@small-tech', 'node-hugo', 'hugo-bin')
......@@ -504,16 +514,87 @@ async function buildBinary () {
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Only zip and copy files to the local working copy of the Site.js web site if explicitly asked to.
if (commandLineOptions.deploy) {
const mainSourceDirectory = path.join(__dirname, '..')
// Check that a local working copy of the Site.js web site exists at the relative location
// that we expect it to. If it doesn’t skip this step.
if (commandLineOptions.deploy && fs.existsSync(websitePath)) {
const mainSourceDirectory = path.join(__dirname, '..')
// Update the install file and deploy them to the Site.js web site.
console.log(' • Updating the installation scripts and copying them to local Site.js web site working copy.')
const installationScriptTemplatesFolder = path.join(mainSourceDirectory, 'installation-script-templates')
//
// Rebuild node_modules to ensure that all dependencies are as we expect them.
// Linux and macOS.
//
console.log(' • Rebuilding node modules…')
fs.removeSync(path.join(mainSourceDirectory, 'node_modules'))
childProcess.execSync('npm i', {env: process.env, cwd: mainSourceDirectory})
const linuxAndMacOSInstallScriptFile = path.join(installationScriptTemplatesFolder, 'install')
const binaryVersionVariableName = `${releaseChannel}BinaryVersion`
const binaryVersionVariable = `${binaryVersionVariableName}=${binaryVersion}`
const binaryVersionRegExp = new RegExp(`${binaryVersionVariableName}=\\d{14}`)
const sourceVersionVariableName = `${releaseChannel}SourceVersion`
const sourceVersionVariable = `${sourceVersionVariableName}=${sourceVersion}`
const sourceVersionRegExp = new RegExp(`${sourceVersionVariableName}=[0-9a-fA-F]{7}`)
const packageVersionVariableName = `${releaseChannel}PackageVersion`
const packageVersionVariable = `${packageVersionVariableName}=${packageVersion}`
const packageVersionRegExp = new RegExp(`${packageVersionVariableName}=\\d+\\.\\d+\\.\\d+`)
let linuxAndMacOSInstallScript
linuxAndMacOSInstallScript = fs.readFileSync(linuxAndMacOSInstallScriptFile, 'utf-8')
linuxAndMacOSInstallScript = linuxAndMacOSInstallScript.replace(binaryVersionRegExp, binaryVersionVariable)
linuxAndMacOSInstallScript = linuxAndMacOSInstallScript.replace(sourceVersionRegExp, sourceVersionVariable)
linuxAndMacOSInstallScript = linuxAndMacOSInstallScript.replace(packageVersionRegExp, packageVersionVariable)
// As we have three different release types, each with a different version, we need to persist
// the template with the other values. Changes should be checked into the repository.
fs.writeFileSync(linuxAndMacOSInstallScriptFile, linuxAndMacOSInstallScript)
console.log('DEBUG EARLY EXIT')
process.exit()
fs.copyFileSync(linuxAndMacOSInstallScriptFile, websitePathForLinuxAndMacInstallScript)
//
// Windows.
//
// (Note: Windows script does not support alpha and beta builds.)
//
if (releaseChannel === 'release') {
const windowsInstallScriptFile = path.join(installationScriptTemplatesFolder, 'windows')
let windowsInstallScript
windowsInstallScript = fs.readFileSync(windowsInstallScriptFile, 'utf-8')
windowsInstallScript = windowsInstallScript.replace(/\d{14}/g, binaryVersion)
windowsInstallScript = windowsInstallScript.replace(/\/[0-9a-fA-F]{7}\)/g, `/${sourceVersion})`)
windowsInstallScript = windowsInstallScript.replace(/\d+\.\d+\.\d+/g, packageVersion)
fs.writeFileSync(websitePathForWindowsInstallScript, windowsInstallScript)
} else {
console.log(` • This is a ${releaseChannel} build, not updating the Windows install script as ${releaseChannel} builds are not supported on Windows.`)
}
//
// Commit the installation script changes.
//
console.log(' • Committing and pushing latest generated installation script…')
childProcess.execSync('git add installation-script-templates/install')
childProcess.execSync(`git commit -m "Update installation script for ${manifest.releaseChannel} version ${manifest.packageVersion}"`)
childProcess.execSync('git push')
//
// Tag the release and push tags.
//
console.log(' • Tagging the release and pushing tags…')
const capitaliseFirstLetter = word => `${word.slice(0,1).toUpperCase()}${word.slice(1)}`
childProcess.execSync(`git tag -s ${binaryVersion} -m '${capitaliseFirstLetter(manifest.releaseChannel)} (package version: ${manifest.packageVersion}, source version: ${manifest.sourceVersion})'`)
childProcess.execSync('git push --tags')
//
// Zip.
......@@ -565,7 +646,6 @@ async function buildBinary () {
//
const INDEX = 'index.js'
const websitePath = path.resolve(path.join(__dirname, '..', '..', 'site'))
const websitePathForIndex = path.resolve(path.join(websitePath, 'index.html'))
const websitePathForBinaries = path.resolve(path.join(websitePath, 'binaries', releaseChannel))
const websitePathForVersionRoutesFolder = path.join(websitePath, '.dynamic', 'version')
const websitePathForBinaryVersionRouteFolder = path.join(websitePathForVersionRoutesFolder, releaseChannel)
......@@ -578,117 +658,41 @@ async function buildBinary () {
fs.ensureDirSync(websitePathForVersionRoutesFolder)
fs.ensureDirSync(websitePathForBinaryVersionRouteFolder)
// Check that a local working copy of the Site.js web site exists at the relative location
// that we expect it to. If it doesn’t skip this step.
if (fs.existsSync(websitePath)) {
console.log(' • Copying release binaries to the Site.js web site…')
const linuxX64VersionZipFilePath = path.join(linuxX64WorkingDirectory, zipFileName)
const linuxArmVersionZipFilePath = path.join(linuxArmWorkingDirectory, zipFileName)
const linuxArm64VersionZipFilePath = path.join(linuxArm64WorkingDirectory, zipFileName)
const macOsVersionZipFilePath = path.join(macOsWorkingDirectory, zipFileName)
const windowsVersionZipFilePath = path.join(windowsWorkingDirectory, zipFileName)
const websitePathForLinuxX64Version = path.join(websitePathForBinaries, 'linux' )
const websitePathForLinuxArmVersion = path.join(websitePathForBinaries, 'linux-arm' )
const websitePathForLinuxArm64Version = path.join(websitePathForBinaries, 'linux-arm64')
const websitePathForMacVersion = path.join(websitePathForBinaries, 'macos' )
const websitePathForWindowsVersion = path.join(websitePathForBinaries, 'windows' )
fs.ensureDirSync(websitePathForBinaries, {recursive: true})
fs.ensureDirSync(websitePathForLinuxX64Version )
fs.ensureDirSync(websitePathForLinuxArmVersion )
fs.ensureDirSync(websitePathForLinuxArm64Version)
fs.ensureDirSync(websitePathForMacVersion )
fs.ensureDirSync(websitePathForWindowsVersion )
fs.copyFileSync(linuxX64VersionZipFilePath, path.join(websitePathForLinuxX64Version, zipFileName))
fs.copyFileSync(linuxArmVersionZipFilePath, path.join(websitePathForLinuxArmVersion, zipFileName))
fs.copyFileSync(linuxArm64VersionZipFilePath, path.join(websitePathForLinuxArm64Version, zipFileName))
fs.copyFileSync(macOsVersionZipFilePath, path.join(websitePathForMacVersion, zipFileName))
fs.copyFileSync(windowsVersionZipFilePath, path.join(websitePathForWindowsVersion, zipFileName))
// Write out a dynamic route on the SiteJS.org web site to return the binary version. This endpoint is used by
// the auto-update feature to decide whether the binary should be updated.
console.log(` • Adding dynamic binary version endpoint for ${releaseChannel} version to Site.js web site.`)
const binaryVersionRoute = `module.exports = (request, response) => { response.end('${binaryVersion}') }\n`
fs.writeFileSync(websitePathForBinaryVersionRouteFile, binaryVersionRoute, {encoding: 'utf-8'})
// Update the install file and deploy them to the Site.js web site.
console.log(' • Updating the installation scripts and copying them to local Site.js web site working copy.')
const installationScriptTemplatesFolder = path.join(mainSourceDirectory, 'installation-script-templates')
//
// Linux and macOS.
//
const linuxAndMacOSInstallScriptFile = path.join(installationScriptTemplatesFolder, 'install')
const binaryVersionVariableName = `${releaseChannel}BinaryVersion`
const binaryVersionVariable = `${binaryVersionVariableName}=${binaryVersion}`
const binaryVersionRegExp = new RegExp(`${binaryVersionVariableName}=\\d{14}`)
const sourceVersionVariableName = `${releaseChannel}SourceVersion`
const sourceVersionVariable = `${sourceVersionVariableName}=${sourceVersion}`
const sourceVersionRegExp = new RegExp(`${sourceVersionVariableName}=[0-9a-fA-F]{7}`)
const packageVersionVariableName = `${releaseChannel}PackageVersion`
const packageVersionVariable = `${packageVersionVariableName}=${packageVersion}`
const packageVersionRegExp = new RegExp(`${packageVersionVariableName}=\\d+\\.\\d+\\.\\d+`)
let linuxAndMacOSInstallScript
linuxAndMacOSInstallScript = fs.readFileSync(linuxAndMacOSInstallScriptFile, 'utf-8')
linuxAndMacOSInstallScript = linuxAndMacOSInstallScript.replace(binaryVersionRegExp, binaryVersionVariable)
linuxAndMacOSInstallScript = linuxAndMacOSInstallScript.replace(sourceVersionRegExp, sourceVersionVariable)
linuxAndMacOSInstallScript = linuxAndMacOSInstallScript.replace(packageVersionRegExp, packageVersionVariable)
// As we have three different release types, each with a different version, we need to persist
// the template with the other values. Changes should be checked into the repository.
fs.writeFileSync(linuxAndMacOSInstallScriptFile, linuxAndMacOSInstallScript)
fs.copyFileSync(linuxAndMacOSInstallScriptFile, websitePathForLinuxAndMacInstallScript)
//
// Windows.
//
// (Note: Windows script does not support alpha and beta builds.)
//
if (releaseChannel === 'release') {
const windowsInstallScriptFile = path.join(installationScriptTemplatesFolder, 'windows')
let windowsInstallScript
windowsInstallScript = fs.readFileSync(windowsInstallScriptFile, 'utf-8')
windowsInstallScript = windowsInstallScript.replace(/\d{14}/g, binaryVersion)
windowsInstallScript = windowsInstallScript.replace(/\/[0-9a-fA-F]{7}\)/g, `/${sourceVersion})`)
windowsInstallScript = windowsInstallScript.replace(/\d+\.\d+\.\d+/g, packageVersion)
fs.writeFileSync(websitePathForWindowsInstallScript, windowsInstallScript)
} else {
console.log(` • This is a ${releaseChannel} build, not updating the Windows install script as ${releaseChannel} builds are not supported on Windows.`)
}
//
// Commit the installation script changes.
//
console.log(' • Committing and pushing latest generated installation script…')
childProcess.execSync('git add installation-script-templates/install')
childProcess.execSync(`git commit -m "Update installation script for ${manifest.releaseChannel} version ${manifest.packageVersion}"`)
childProcess.execSync('git push')
//
// Tag the release and push tags.
//
console.log(' • Tagging the release and pushing tags…')
const capitaliseFirstLetter = word => `${word.slice(0,1).toUpperCase()}${word.slice(1)}`
childProcess.execSync(`git tag -s ${binaryVersion} -m '${capitaliseFirstLetter(manifest.releaseChannel)} (package version: ${manifest.packageVersion}, source version: ${manifest.sourceVersion})'`)
childProcess.execSync('git push --tags')
} else {
console.log(` • No local working copy of Site.js web site found. Skipped copy of release binaries. Please clone https://small-tech.org/site.js/site to ${websitePath} and ensure you have commit permissions on the repository before attempting to deploy.`)
}
console.log(' • Copying release binaries to the Site.js web site…')
const linuxX64VersionZipFilePath = path.join(linuxX64WorkingDirectory, zipFileName)
const linuxArmVersionZipFilePath = path.join(linuxArmWorkingDirectory, zipFileName)
const linuxArm64VersionZipFilePath = path.join(linuxArm64WorkingDirectory, zipFileName)
const macOsVersionZipFilePath = path.join(macOsWorkingDirectory, zipFileName)
const windowsVersionZipFilePath = path.join(windowsWorkingDirectory, zipFileName)
const websitePathForLinuxX64Version = path.join(websitePathForBinaries, 'linux' )
const websitePathForLinuxArmVersion = path.join(websitePathForBinaries, 'linux-arm' )
const websitePathForLinuxArm64Version = path.join(websitePathForBinaries, 'linux-arm64')
const websitePathForMacVersion = path.join(websitePathForBinaries, 'macos' )
const websitePathForWindowsVersion = path.join(websitePathForBinaries, 'windows' )
fs.ensureDirSync(websitePathForBinaries, {recursive: true})
fs.ensureDirSync(websitePathForLinuxX64Version )
fs.ensureDirSync(websitePathForLinuxArmVersion )
fs.ensureDirSync(websitePathForLinuxArm64Version)
fs.ensureDirSync(websitePathForMacVersion )
fs.ensureDirSync(websitePathForWindowsVersion )
fs.copyFileSync(linuxX64VersionZipFilePath, path.join(websitePathForLinuxX64Version, zipFileName))
fs.copyFileSync(linuxArmVersionZipFilePath, path.join(websitePathForLinuxArmVersion, zipFileName))
fs.copyFileSync(linuxArm64VersionZipFilePath, path.join(websitePathForLinuxArm64Version, zipFileName))
fs.copyFileSync(macOsVersionZipFilePath, path.join(websitePathForMacVersion, zipFileName))
fs.copyFileSync(windowsVersionZipFilePath, path.join(websitePathForWindowsVersion, zipFileName))
// Write out a dynamic route on the SiteJS.org web site to return the binary version. This endpoint is used by
// the auto-update feature to decide whether the binary should be updated.
console.log(` • Adding dynamic binary version endpoint for ${releaseChannel} version to Site.js web site.`)
const binaryVersionRoute = `module.exports = (request, response) => { response.end('${binaryVersion}') }\n`
fs.writeFileSync(websitePathForBinaryVersionRouteFile, binaryVersionRoute, {encoding: 'utf-8'})
} else {
console.log(` • No local working copy of Site.js web site found. Skipped deploy. Please clone https://small-tech.org/site.js/site to ${websitePath} and ensure you have commit permissions on the repository before attempting to deploy.`)
}
console.log('\n 😁👍 Done!\n')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment