Verified Commit cf2b9433 authored by Aral Balkan's avatar Aral Balkan
Browse files

Add sourceVersion (git hash) and update version terminology

parent 32cb908d
......@@ -36,7 +36,7 @@ if (cpuArchitecture !== 'x64' && cpuArchitecture !== 'arm') {
// If this is a deployment build, ensure that the working directory is not dirty
// before proceeding. Deployment builds are tied to Git revisions and tags.
if (childProcess.execSync('git status').toString().match('working tree clean') === null) {
if (commandLineOptions.deploy && childProcess.execSync('git status').toString().match('working tree clean') === null) {
console.log('❌ Error: Cannot deploy when working copy is dirty. Please commit or stash changes before retrying.\n')
process.exit(1)
}
......@@ -63,7 +63,7 @@ function presentBinaryVersion (binaryVersion) {
const binaryVersion = moment(new Date()).format('YYYYMMDDHHmmss')
const packageVersion = package.version
const sourceVersion = childProcess.execSync('git log -1 --oneline | cut -c1-8')
const sourceVersion = (childProcess.execSync('git log -1 --oneline | cut -c1-7')).toString().trim()
const binaryName = 'site'
const windowsBinaryName = `${binaryName}.exe`
......@@ -72,7 +72,7 @@ console.log(`\n ⚙️ Site.js build started on ${presentBinaryVersion(binaryVer
Release channel: ${releaseChannel}
Binary version : ${binaryVersion}
Package version: ${packageVersion}
Source version : ${packageVersion}
Source version : ${sourceVersion}
Node version : ${nodeVersion}\n`)
// Write out the manifest file. This will be included in the build so that the binary knows what type of release it is.
......@@ -499,6 +499,10 @@ async function build () {
const binaryVersionVariable = `${binaryVersionVariableName}=${binaryVersion}`
const binaryVersionRegExp = new RegExp(`${binaryVersionVariableName}=\\d{14}`)
const sourceVersionVariableName = `${releaseChannel}sourceVersion`
const sourceVersionVariable = `${packageVersionVariableName}=${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+`)
......@@ -506,6 +510,7 @@ async function build () {
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
......
......@@ -26,19 +26,19 @@ async function update () {
const cpuArchitecture = os.arch()
const isLinux = platform === 'linux'
const releaseType = Site.releaseType
const releaseChannel = Site.releaseChannel
ensure.root('update')
Site.logAppNameAndVersion(/* compact = */ true)
console.log(` 🧐 Checking for ${releaseType} updates…\n`)
console.log(` 🧐 Checking for ${releaseChannel} updates…\n`)
let response
try {
response = await secureGet(`https://sitejs.org/version/${releaseType}`)
response = await secureGet(`https://sitejs.org/version/${releaseChannel}`)
} catch (error) {
console.log(` 🤯 Error: Could not check for ${releaseType} updates.\n`)
console.log(` 🤯 Error: Could not check for ${releaseChannel} updates.\n`)
console.log(error)
exitGracefully(1)
return
......@@ -53,31 +53,15 @@ async function update () {
if (currentVersion !== latestVersion) {
// Are we running a newer version than the latest release version?
if (currentVersion > latestVersion) {
console.log(` 🤓 You are running a newer ${releaseType} version (released on ${humanReadableCurrentVersion}) than the latest ${releaseType} version (released on ${humanReadableLatestVersion}).\n`)
console.log(` 🤓 You are running a newer ${releaseChannel} version (released on ${humanReadableCurrentVersion}) than the latest version released on ${humanReadableLatestVersion}.\n`)
exitGracefully()
return
}
// Get the source version also.
try {
response = await secureGet(`https://sitejs.org/version/`)
} catch (error) {
console.log(` 🤯 Error: Could not check for ${releaseType} source version.\n`)
console.log(error)
exitGracefully(1)
return
}
const latestSourceVersion = response.body
const currentSourceVersion = Site.sourceVersion
const currentFullVersion = `${currentBinaryVersion}/${currentSourceVersion}`
const latestFullVersion = `${latestBinaryVersion}/${latestSourceVersion}`
// The current version is not newer than the latest version and we know
// that it isn’t equal to the release version so it must be older. Let’s
// update!
console.log(` 🎁 There is a new ${releaseType} version of Site.js available (${latestFullVersion} released on ${humanReadableLatestVersion}). You currently have ${releaseType} version ${currentFullVersion} released on ${humanReadableCurrentVersion}\n`)
console.log(` 🎁 There is a new version of Site.js available in the ${releaseChannel} channel: (${latestVersion} released on ${humanReadableLatestVersion}). You currently have version ${currentVersion} released on ${humanReadableCurrentVersion}.\n`)
//
// Compose the right binary URL for the platform and architecture.
......@@ -93,9 +77,9 @@ async function update () {
platformPath = `${platformPath}-arm`
}
let binaryUrl = `https://sitejs.org/binaries/${releaseType}/${platformPath}/${latestVersion}.tar.gz`
let binaryUrl = `https://sitejs.org/binaries/${releaseChannel}/${platformPath}/${latestVersion}.tar.gz`
console.log(` 📡 Downloading Site.js ${releaseType} version ${latestFullVersion}…`)
console.log(` 📡 Downloading Site.js ${releaseChannel} version ${latestVersion}…`)
let latestReleaseResponse
try {
......@@ -140,7 +124,7 @@ async function update () {
if (ensure.commandExists('systemctl')) {
const { isActive } = status()
if (isActive) {
console.log(` 😈 Daemon is running on old version. Restarting it using Site.js ${releaseType} version ${latestFullVersion}…`)
console.log(` 😈 Daemon is running on old version. Restarting it using Site.js ${releaseChannel} version ${latestVersion}…`)
try {
restart()
......
......@@ -53,10 +53,14 @@ class Site {
return `${clr('🅷', 'magenta')} ${clr('🆄', 'blue')} ${clr('🅶', 'green')} ${clr('🅾', 'yellow')} `
}
//
// Manifest helpers. The manifest file is created by the build script and includes metadata such as the
// binary version (in calendar version format YYYYMMDDHHmmss), the source version (in semantic version format), and
// the release type (alpha, beta, or release).
static RELEASE_TYPE = {
// binary version (in calendar version format YYYYMMDDHHmmss), the package version (in semantic version format),
// the source version (the git hash of the commit that corresponds to the source code the binary was built from), and
// the release channel (alpha, beta, or release).
//
static RELEASE_CHANNEL = {
alpha : 'alpha',
beta : 'beta',
release: 'release'
......@@ -66,11 +70,11 @@ class Site {
this.#manifest = JSON.parse(fs.readFileSync(path.join(__dirname, './manifest.json'), 'utf-8'))
}
static get releaseType () {
static get releaseChannel () {
if (this.#manifest === null) {
this.readAndCacheManifest()
}
return this.#manifest.releaseType
return this.#manifest.releaseChannel
}
static get binaryVersion () {
......@@ -80,6 +84,13 @@ class Site {
return this.#manifest.binaryVersion
}
static get packageVersion () {
if (this.#manifest === null) {
this.readAndCacheManifest()
}
return this.#manifest.packageVersion
}
static get sourceVersion () {
if (this.#manifest === null) {
this.readAndCacheManifest()
......@@ -99,11 +110,11 @@ class Site {
return this.binaryVersionToHumanReadableDateString(this.#manifest.binaryVersion)
}
static get releaseTypeFormattedForConsole () {
static get releaseChannelFormattedForConsole () {
if (this.#manifest === null) {
this.readAndCacheManifest()
}
switch(this.#manifest.releaseType) {
switch(this.#manifest.releaseChannel) {
// Spells ALPHA in large red block letters.
case 'alpha': return clr(`\n
█████  ██  ██████  ██  ██  █████ 
......@@ -147,10 +158,10 @@ class Site {
this.readAndCacheManifest()
let message = [
`\n${prefix1}Site.js ${this.releaseTypeFormattedForConsole}\n\n`,
`${prefix2}Build : ${clr(this.humanReadableBinaryVersion, 'green')}\n`,
`${prefix2}Engine: ${clr(`Node.js ${process.version}`, 'green')}\n`,
`${prefix2}Source: ${clr(`https://source.small-tech.org/site.js/app/tags/${this.sourceVersion}`, 'cyan')}\n\n`,
`\n${prefix1}Site.js ${this.releaseChannelFormattedForConsole}\n\n`,
`${prefix2}Version: ${clr(this.humanReadableBinaryVersion, 'green')}\n`,
`${prefix2}Engine : ${clr(`Node.js ${process.version}`, 'green')}\n`,
`${prefix2}Source : ${clr(`https://source.small-tech.org/site.js/app/-/tree/${this.sourceVersion}`, 'cyan')}\n\n`,
`${prefix2}╔═══════════════════════════════════════════╗\n`,
`${prefix2}║ Like this? Fund us! ║\n`,
`${prefix2}║ ║\n`,
......
......@@ -30,39 +30,44 @@ function cleanUp {
rm -rf /tmp/sitejs.org
}
releaseType=$1
releaseChannel=$1
# Release is the default release type (others are alpha and beta).
if [[ "$releaseType" == "" ]]; then
releaseType='release'
if [[ "$releaseChannel" == "" ]]; then
releaseChannel='release'
fi
alphaBinaryVersion=00000000000000
alphaSourceVersion=00.00.00
alphaPackageVersion=00.00.00
alphaSourceVersion=bedface
betaBinaryVersion=00000000000000
betaSourceVersion=00.00.00
betaPackageVersion=00.00.00
betaSourceVersion=acecafe
releaseBinaryVersion=00000000000000
releaseSourceVersion=00.00.00
releasePackageVersion=00.00.00
releaseSourceVersion=decafAF
binaryVersionVariableName="${releaseType}BinaryVersion"
sourceVersionVariableName="${releaseType}SourceVersion"
binaryVersionVariableName="${releaseChannel}BinaryVersion"
packageVersionVariableName="${releaseChannel}PackageVersion"
sourceVersionVariableName="${releaseChannel}SourceVersion"
binaryVersion=${!binaryVersionVariableName}
packageVersion=${!packageVersionVariableName}
sourceVersion=${!sourceVersionVariableName}
if [[ "$binaryVersion" == "00000000000000" ]]; then
echo " ❌ Sorry, no Site.js ${releaseType} binaries have been released yet."
echo " ❌ Sorry, no Site.js ${releaseChannel} binaries have been released yet."
cleanUp
exit 1
fi
echo
echo " 📡 Downloading Site.js version ${binaryVersion}/${sourceVersion}…"
echo " 📡 Downloading Site.js version ${binaryVersion} (${packageversion}/${sourceVersion})…"
# Mark alpha and beta releases prominently.
if [[ "$releaseType" == "alpha" ]]; then
if [[ "$releaseChannel" == "alpha" ]]; then
# Writes ALPHA in large red block letters.
echo -e '\033[31m'
......@@ -73,7 +78,7 @@ if [[ "$releaseType" == "alpha" ]]; then
echo ' ██  ██ ███████ ██  ██  ██ ██  ██'
echo -e '\033[0m'
elif [[ "$releaseType" == "beta" ]]; then
elif [[ "$releaseChannel" == "beta" ]]; then
# Writes BETA in large yellow block letters.
echo -e '\033[33m'
......@@ -96,10 +101,10 @@ if [[ "$OSTYPE" == "linux-gnu" || "$OSTYPE" == "linux-gnueabihf" ]]; then
cpuArchitecture=`uname -m`
if [[ "$cpuArchitecture" == "x86_64" ]]; then
# Linux on x64.
wget -q "https://sitejs.org/binaries/${releaseType}/linux/${binaryVersion}.tar.gz"
wget -q "https://sitejs.org/binaries/${releaseChannel}/linux/${binaryVersion}.tar.gz"
elif [[ "$cpuArchitecture" == "armv7l" || "$cpuArchitecture" == "armv6l" ]]; then
# Linux on ARM. Tested on Raspberry Pi Zero W (armv6l), 3B+ and 4B (both reporting armv7l).
wget -q "https://sitejs.org/binaries/${releaseType}/linux-arm/${binaryVersion}.tar.gz"
wget -q "https://sitejs.org/binaries/${releaseChannel}/linux-arm/${binaryVersion}.tar.gz"
else
# Error: unsupported architecture.
echo
......@@ -110,7 +115,7 @@ if [[ "$OSTYPE" == "linux-gnu" || "$OSTYPE" == "linux-gnueabihf" ]]; then
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
# macOS
curl -Os "https://sitejs.org/binaries/${releaseType}/macos/${binaryVersion}.tar.gz"
curl -Os "https://sitejs.org/binaries/${releaseChannel}/macos/${binaryVersion}.tar.gz"
else
# Error: Unsupported operating system.
echo
......
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