From 1c35622c66309984cecddd6892fe2060ef21a447 Mon Sep 17 00:00:00 2001 From: André Oliveira <37463445+SpecialAro@users.noreply.github.com> Date: Sat, 23 Apr 2022 12:05:13 +0100 Subject: Update the build script for Windows (Powershell) and normalized with the unix equivalent [skip ci] Co-authored-by: Vijay A --- CONTRIBUTING.md | 53 ++++++++-------- scripts/build-unix.sh | 52 +++++++++++----- scripts/build-windows.ps1 | 155 ++++++++++++++++++++++++++++++++++------------ 3 files changed, 178 insertions(+), 82 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8f1b19685..a6b581112 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -6,32 +6,33 @@ -- [Table of contents](#table-of-contents) -- [Code of Conduct](#code-of-conduct) -- [What should I know before I get started?](#what-should-i-know-before-i-get-started) -- [How can I contribute?](#how-can-i-contribute) -- [Setting up your development machine](#setting-up-your-development-machine) - - [Install system-level dependencies](#install-system-level-dependencies) - - [Node.js, npm, pnpm](#nodejs-npm-pnpm) - - [Git](#git) - - [On Debian/Ubuntu](#on-debianubuntu) - - [On Fedora](#on-fedora) - - [On Windows](#on-windows) - - [Clone repository with submodule](#clone-repository-with-submodule) - - [Local caching of dependencies](#local-caching-of-dependencies) - - [Install dependencies](#install-dependencies) - - [Fix native modules to match current electron node version](#fix-native-modules-to-match-current-electron-node-version) - - [Package recipe repository](#package-recipe-repository) - - [Using Docker to build a linux-targetted packaged app](#using-docker-to-build-a-linux-targetted-packaged-app) - - [Code Signing on a mac](#code-signing-on-a-mac) - - [Start development app](#start-development-app) - - [Styleguide](#styleguide) - - [Git Commit Messages format](#git-commit-messages-format) - - [Javascript Coding style-checker](#javascript-coding-style-checker) -- [Packaging](#packaging) -- [Release](#release) - - [Nightly releases](#nightly-releases) - - [Updating the code after a hiatus](#updating-the-code-after-a-hiatus) +- [Contributing to Ferdium 6](#contributing-to-ferdium-6) + - [Table of contents](#table-of-contents) + - [Code of Conduct](#code-of-conduct) + - [What should I know before I get started?](#what-should-i-know-before-i-get-started) + - [How can I contribute?](#how-can-i-contribute) + - [Setting up your development machine](#setting-up-your-development-machine) + - [Install system-level dependencies](#install-system-level-dependencies) + - [Node.js, npm, pnpm](#nodejs-npm-pnpm) + - [Git](#git) + - [On Debian/Ubuntu](#on-debianubuntu) + - [On Fedora](#on-fedora) + - [On Windows](#on-windows) + - [Clone repository with submodule](#clone-repository-with-submodule) + - [Local caching of dependencies](#local-caching-of-dependencies) + - [Install dependencies](#install-dependencies) + - [Fix native modules to match current electron node version](#fix-native-modules-to-match-current-electron-node-version) + - [Package recipe repository](#package-recipe-repository) + - [Using Docker to build a linux-targetted packaged app](#using-docker-to-build-a-linux-targetted-packaged-app) + - [Code Signing on a mac](#code-signing-on-a-mac) + - [Start development app](#start-development-app) + - [Styleguide](#styleguide) + - [Git Commit Messages format](#git-commit-messages-format) + - [Javascript Coding style-checker](#javascript-coding-style-checker) + - [Packaging](#packaging) + - [Release](#release) + - [Nightly releases](#nightly-releases) + - [Updating the code after a hiatus](#updating-the-code-after-a-hiatus) diff --git a/scripts/build-unix.sh b/scripts/build-unix.sh index e80c38059..872219a8f 100755 --- a/scripts/build-unix.sh +++ b/scripts/build-unix.sh @@ -3,8 +3,8 @@ # INTRO: # This file is used to build ferdium on both x64 and arm-based for macos and linux (not tested on arm for linux). # It also handles any corrupted node modules with the 'CLEAN' env var (set it to 'true' for cleaning) -# It will install the system dependencies except for node (which is still verified) -# I sometimes symlink my 'recipes' folder so that any changes that I need to do in it can also be committed and pushed +# It will install the system dependencies except for node and python (which are still verified) +# I sometimes symlink my 'recipes' folder so that any changes that I need to do in it can also be committed and pushed independently # This file can live anywhere in your PATH set -e @@ -30,10 +30,12 @@ command_exists() { # ----------------------------------------------------------------------------- # Checking the developer environment -# checking for installed programmes +# Check for installed programmes command_exists node || fail_with_docs "Node is not installed" command_exists jq || fail_with_docs "jq is not installed" +command_exists python || fail_with_docs "python is not installed" +# Check node version EXPECTED_NODE_VERSION=$(cat .nvmrc) ACTUAL_NODE_VERSION=$(node -v) if [ "v$EXPECTED_NODE_VERSION" != "$ACTUAL_NODE_VERSION" ]; then @@ -73,23 +75,40 @@ else fi # ----------------------------------------------------------------------------- -printf "\n*************** Installing node dependencies ***************\n" +# Ensure that the system dependencies are at the correct version - fail if not +# Check python version +EXPECTED_PYTHON_VERSION="3.10.4" +ACTUAL_PYTHON_VERSION=$(python --version | sed -e "s/Python //") +if [[ "$ACTUAL_PYTHON_VERSION" != "$EXPECTED_PYTHON_VERSION" ]]; then + fail_with_docs "You are not running the expected version of Python! + expected: [$EXPECTED_PYTHON_VERSION] + actual : [$ACTUAL_PYTHON_VERSION]" +fi + +# ----------------------------------------------------------------------------- +# Ensure that the system dependencies are at the correct version - recover if not # If 'asdf' is installed, reshim for new nodejs if necessary command_exists asdf && asdf reshim nodejs # Ensure that the system dependencies are at the correct version -EXPECTED_NPM_VERSION=$(jq --raw-output .engines.npm <"package.json") -EXPECTED_PNPM_VERSION=$(jq --raw-output .engines.pnpm <"./recipes/package.json") -if [[ "$(npm --version)" != "$EXPECTED_NPM_VERSION" ]]; then - npm i -gf "npm@$EXPECTED_NPM_VERSION" +# Check npm version +EXPECTED_NPM_VERSION=$(jq --raw-output .engines.npm ./package.json) +ACTUAL_NPM_VERSION=$(npm --version) +if [[ "$ACTUAL_NPM_VERSION" != "$EXPECTED_NPM_VERSION" ]]; then + npm i -gf npm@$EXPECTED_NPM_VERSION fi -if [[ "$(pnpm --version)" != "$EXPECTED_PNPM_VERSION" ]]; then - npm i -gf "pnpm@$EXPECTED_PNPM_VERSION" + +# Check pnpm version +EXPECTED_PNPM_VERSION=$(jq --raw-output .engines.pnpm ./recipes/package.json) +ACTUAL_PNPM_VERSION=$(pnpm --version) +if [[ "$ACTUAL_PNPM_VERSION" != "$EXPECTED_PNPM_VERSION" ]]; then + npm i -gf pnpm@$EXPECTED_PNPM_VERSION fi # If 'asdf' is installed, reshim for new nodejs if necessary command_exists asdf && asdf reshim nodejs +# ----------------------------------------------------------------------------- # This is useful if we move from 'npm' to 'pnpm' for the main repo as well if [[ -s 'pnpm-lock.yaml' ]]; then BASE_CMD=pnpm @@ -123,13 +142,16 @@ else TARGET_OS="linux" fi -$BASE_CMD run build -- "--$TARGET_ARCH" --"$TARGET_OS" --dir +$BASE_CMD run build -- --$TARGET_ARCH --$TARGET_OS --dir printf "\n*************** App successfully built! ***************\n" + # Final check to ensure that the version built is the same as the latest commit -cat build/buildInfo.json -git --no-pager log -1 -if [[ $(git rev-parse --short HEAD) != $(jq --raw-output .gitHashShort <"build/buildInfo.json") ]]; then - echo "The built version is not on the latest commit" +VERSION_BUILT_HASH=$(jq --raw-output .gitHashShort ./build/buildInfo.json) +GIT_BUILT_HASH=$(git rev-parse --short HEAD) +if [[ $GIT_BUILT_HASH != $VERSION_BUILT_HASH ]]; then + echo "The built version is not on the latest commit + latest commit : [$GIT_BUILT_HASH] + actual build : [$VERSION_BUILT_HASH]" exit 1 fi diff --git a/scripts/build-windows.ps1 b/scripts/build-windows.ps1 index 9d4219ffb..3904c1bf9 100644 --- a/scripts/build-windows.ps1 +++ b/scripts/build-windows.ps1 @@ -1,45 +1,79 @@ # INTRO: # This file is used to build ferdium on windows. # It also handles any corrupted node modules with the 'CLEAN' env var (set it to 'true' for cleaning) -# It will install the system dependencies except for node (which is still verified) -# I sometimes symlink my 'recipes' folder so that any changes that I need to do in it can also be committed and pushed +# It will install the system dependencies except for node and python (which are still verified) +# I sometimes symlink my 'recipes' folder so that any changes that I need to do in it can also be committed and pushed independently # This file can live anywhere in your PATH -#CHECK PYTHON -#CHECK NODE.JS -#CHECK NPM -#CHECK MSVS_VERSION and MSVS Tools - $USERHOME = "${env:HOMEDRIVE}${env:HOMEPATH}" $env:ELECTRON_CACHE = $USERHOME + '/.cache/electron' $env:ELECTRON_BUILDER_CACHE = $USERHOME + '/.cache/electron-builder' $env:CSC_IDENTITY_AUTO_DISCOVERY = $false - $env:CI = $true -$EXPECTED_NODE_VERSION = (Get-Content .\.nvmrc) -$ACTUAL_NODE_VERSION = (node -v) +# ----------------------------------------------------------------------------- +# Utility functions -if ( "v$EXPECTED_NODE_VERSION" -ne $ACTUAL_NODE_VERSION) -{ - Write-Host "You are not running the expected version of node!" - Write-Host " expected: [v$EXPECTED_NODE_VERSION]" - Write-Host " actual : [$ACTUAL_NODE_VERSION]" +Function fail_with_docs {Param ($1) + Write-Host "*************** FAILING ***************" + Write-Host "$1" + Write-Host "" + Write-Host "Please read the developer documentation in CONTRIBUTING.md" exit 1 } -if ( $env:CLEAN -eq "true" ) +Function Test-CommandExists { Param ($command, $1) + $oldPreference = $ErrorActionPreference + $ErrorActionPreference = "stop" + + try { + if(Get-Command $command){RETURN} + } Catch { + fail_with_docs $1 + } + Finally {$ErrorActionPreference=$oldPreference} +} + +# ----------------------------------------------------------------------------- +# Checking the developer environment +# Check for installed programmes +Test-CommandExists node "Node is not installed" +Test-CommandExists npm "npm is not installed" +Test-CommandExists python "Python is not installed" +# NEEDS proper way to CHECK MSVS Tools + +# Check node version +$EXPECTED_NODE_VERSION = (cat .nvmrc) +$ACTUAL_NODE_VERSION = (node -v) +if ("v$EXPECTED_NODE_VERSION" -ne $ACTUAL_NODE_VERSION) { + fail_with_docs "You are not running the expected version of node! + expected: [v$EXPECTED_NODE_VERSION] + actual : [$ACTUAL_NODE_VERSION]" +} + +# Check if the 'recipes' folder is present either as a git submodule or a symbolic link +if (-not (Test-Path -Path "recipes/package.json" -PathType Leaf)) { + fail_with_docs "'recipes' folder is missing or submodule has not been checked out" +} + +# This log statement is only to remind me which 'recipes' folder I am using (symlink or git submodule) +# TODO: Implement this + +# ----------------------------------------------------------------------------- +# If you are moving to a new version of node or any other system dependency, then cleaning is recommended +# so that there's no irregular results due to cached modules +if ($env:CLEAN -eq "true") { $NPM_PATH = "$USERHOME\.npm" $NODE_GYP = "$USERHOME\.node-gyp" Write-Host "Cleaning!" npm cache clean --force - Remove-Item -Path $NPM_PATH -Recurse - Remove-Item -Path $NODE_GYP -Recurse + Remove-Item -Path $NPM_PATH -Recurse -ErrorAction SilentlyContinue + Remove-Item -Path $NODE_GYP -Recurse -ErrorAction SilentlyContinue - if ( Test-Path -Path ".\pnpm-lock.yaml" -and (Get-Command -ErrorAction Ignore -Type Application pnpm) ) + if ( (Test-Path -Path ".\pnpm-lock.yaml") -and (Get-Command -ErrorAction Ignore -Type Application pnpm) ) { $PNPM_STORE = "$USERHOME\.pnpm-store" $PNPM_STATE = "$USERHOME\.pnpm-state" @@ -50,16 +84,54 @@ if ( $env:CLEAN -eq "true" ) Remove-Item -Path $PNPM_STATE -Recurse } - git -C recipes clean -fxd - git clean -fxd # Note: This will blast away the 'recipes' folder if you have symlinked it + git -C recipes clean -fxd # Clean recipes folder/submodule + git clean -fxd # Note: This will blast away the 'recipes' folder if you have symlinked it } -# Ensure that the system dependencies are at the correct version -npm i -gf npm@8.7.0 -npm i -gf pnpm@6.32.8 +# ----------------------------------------------------------------------------- +# Ensure that the system dependencies are at the correct version - fail if not +# Check python version +$EXPECTED_PYTHON_VERSION = "3.10.4" +$ACTUAL_PYTHON_VERSION = (python --version).trim("Python ") +if ([System.Version]$ACTUAL_PYTHON_VERSION -le [System.Version]$EXPECTED_PYTHON_VERSION) { + fail_with_docs "You are not running the expected version of Python! + expected: [$EXPECTED_PYTHON_VERSION] + actual : [$ACTUAL_PYTHON_VERSION]" +} + +# TODO: Needs proper way to check MSVS Tools +# Check MSVS Tools through MSVS_VERSION +$EXPECTED_MSVST_VERSION = "2015" +$ACTUAL_MSVST_VERSION = (npm config get msvs_version) +if ([double]$ACTUAL_MSVST_VERSION -le [double]$EXPECTED_MSVST_VERSION) { + fail_with_docs "You are not running the expected version of MSVS Tools! + expected: [$EXPECTED_MSVST_VERSION] + actual : [$ACTUAL_MSVST_VERSION]" +} + +# ----------------------------------------------------------------------------- +# Ensure that the system dependencies are at the correct version - recover if not +# Check npm version +$EXPECTED_NPM_VERSION = (Get-Content package.json | ConvertFrom-Json).engines.npm +$ACTUAL_NPM_VERSION = (npm -v) +if ($EXPECTED_NPM_VERSION -ne $ACTUAL_NPM_VERSION) { + Write-Host "You are not running the expected version of npm! + expected: [$EXPECTED_NPM_VERSION] + actual : [$ACTUAL_NPM_VERSION]" + Write-Host "Changing version of npm to [$EXPECTED_NPM_VERSION]" + npm i -gf npm@$EXPECTED_NPM_VERSION +} +# Check pnpm version +$EXPECTED_PNPM_VERSION = (Get-Content recipes\package.json | ConvertFrom-Json).engines.pnpm +ACTUAL_PNPM_VERSION=$(pnpm --version) +if ($ACTUAL_PNPM_VERSION -ne $EXPECTED_PNPM_VERSION) { + npm i -gf pnpm@$EXPECTED_PNPM_VERSION +} + +# ----------------------------------------------------------------------------- # This is useful if we move from 'npm' to 'pnpm' for the main repo as well -if ( (Test-Path -Path ".\pnpm-lock.yaml") -and (Get-Command -ErrorAction Ignore -Type Application pnpm) ) +if ((Test-Path -Path ".\pnpm-lock.yaml") -and (Get-Command -ErrorAction Ignore -Type Application pnpm)) { $BASE_CMD="pnpm" $env:EXEC_CMD="pnpm dlx" @@ -74,27 +146,28 @@ else & $BASE_CMD i & $BASE_CMD run prepare-code -# Check if the 'recipes' folder is present either as a git submodule or a symbolic link -if (-not (Test-Path -Path ".\recipes\package.json")) -{ - try { - git submodule update --init --recursive --remote --rebase --force - } catch { - Write-Host "FAILING since 'recipes' folder/submodule has not been checked out" - exit 1 - } -} - +# ----------------------------------------------------------------------------- +Write-Host "\n*************** Building recipes ***************\n" # Note: 'recipes' is already using only pnpm - can switch to $BASE_CMD AFTER both repos are using pnpm -Set-Location recipes +Push-Location recipes pnpm i pnpm run package -Set-Location .. +Pop-Location +# ----------------------------------------------------------------------------- +Write-Host "\n*************** Building app ***************\n" $TARGET_ARCH="x64" & $BASE_CMD run build -- --$TARGET_ARCH --dir +Write-Host "*************** App successfully built! ***************" + # Final check to ensure that the version built is the same as the latest commit -# TODO: Need to make this an assertion similar to tthe unix-equivalent -Get-Content "build/buildInfo.json" | ConvertFrom-Json -git log -1 +$VERSION_BUILT_HASH = (Get-Content "build/buildInfo.json" | ConvertFrom-Json).gitHashShort +$GIT_BUILT_HASH = (git rev-parse --short HEAD) +if ($VERSION_BUILT_HASH -ne $GIT_BUILT_HASH) +{ + Write-Host "The built version is not on the latest commit!" + Write-Host " latest commit : [$GIT_BUILT_HASH]" + Write-Host " actual build : [$VERSION_BUILT_HASH]" + exit 1 +} -- cgit v1.2.3-54-g00ecf