aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorLibravatar André Oliveira <37463445+SpecialAro@users.noreply.github.com>2022-04-23 12:05:13 +0100
committerLibravatar GitHub <noreply@github.com>2022-04-23 11:05:13 +0000
commit1c35622c66309984cecddd6892fe2060ef21a447 (patch)
tree27651692f01cbdd4e2b2b6be8a057524035e5a97 /scripts
parent6.0.0-nightly.9 [skip ci] (diff)
downloadferdium-app-1c35622c66309984cecddd6892fe2060ef21a447.tar.gz
ferdium-app-1c35622c66309984cecddd6892fe2060ef21a447.tar.zst
ferdium-app-1c35622c66309984cecddd6892fe2060ef21a447.zip
Update the build script for Windows (Powershell) and normalized with the unix equivalent [skip ci]
Co-authored-by: Vijay A <vraravam@users.noreply.github.com>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/build-unix.sh52
-rw-r--r--scripts/build-windows.ps1155
2 files changed, 151 insertions, 56 deletions
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 @@
3# INTRO: 3# INTRO:
4# This file is used to build ferdium on both x64 and arm-based for macos and linux (not tested on arm for linux). 4# This file is used to build ferdium on both x64 and arm-based for macos and linux (not tested on arm for linux).
5# It also handles any corrupted node modules with the 'CLEAN' env var (set it to 'true' for cleaning) 5# It also handles any corrupted node modules with the 'CLEAN' env var (set it to 'true' for cleaning)
6# It will install the system dependencies except for node (which is still verified) 6# It will install the system dependencies except for node and python (which are still verified)
7# I sometimes symlink my 'recipes' folder so that any changes that I need to do in it can also be committed and pushed 7# I sometimes symlink my 'recipes' folder so that any changes that I need to do in it can also be committed and pushed independently
8# This file can live anywhere in your PATH 8# This file can live anywhere in your PATH
9 9
10set -e 10set -e
@@ -30,10 +30,12 @@ command_exists() {
30 30
31# ----------------------------------------------------------------------------- 31# -----------------------------------------------------------------------------
32# Checking the developer environment 32# Checking the developer environment
33# checking for installed programmes 33# Check for installed programmes
34command_exists node || fail_with_docs "Node is not installed" 34command_exists node || fail_with_docs "Node is not installed"
35command_exists jq || fail_with_docs "jq is not installed" 35command_exists jq || fail_with_docs "jq is not installed"
36command_exists python || fail_with_docs "python is not installed"
36 37
38# Check node version
37EXPECTED_NODE_VERSION=$(cat .nvmrc) 39EXPECTED_NODE_VERSION=$(cat .nvmrc)
38ACTUAL_NODE_VERSION=$(node -v) 40ACTUAL_NODE_VERSION=$(node -v)
39if [ "v$EXPECTED_NODE_VERSION" != "$ACTUAL_NODE_VERSION" ]; then 41if [ "v$EXPECTED_NODE_VERSION" != "$ACTUAL_NODE_VERSION" ]; then
@@ -73,23 +75,40 @@ else
73fi 75fi
74 76
75# ----------------------------------------------------------------------------- 77# -----------------------------------------------------------------------------
76printf "\n*************** Installing node dependencies ***************\n" 78# Ensure that the system dependencies are at the correct version - fail if not
79# Check python version
80EXPECTED_PYTHON_VERSION="3.10.4"
81ACTUAL_PYTHON_VERSION=$(python --version | sed -e "s/Python //")
82if [[ "$ACTUAL_PYTHON_VERSION" != "$EXPECTED_PYTHON_VERSION" ]]; then
83 fail_with_docs "You are not running the expected version of Python!
84 expected: [$EXPECTED_PYTHON_VERSION]
85 actual : [$ACTUAL_PYTHON_VERSION]"
86fi
87
88# -----------------------------------------------------------------------------
89# Ensure that the system dependencies are at the correct version - recover if not
77# If 'asdf' is installed, reshim for new nodejs if necessary 90# If 'asdf' is installed, reshim for new nodejs if necessary
78command_exists asdf && asdf reshim nodejs 91command_exists asdf && asdf reshim nodejs
79 92
80# Ensure that the system dependencies are at the correct version 93# Ensure that the system dependencies are at the correct version
81EXPECTED_NPM_VERSION=$(jq --raw-output .engines.npm <"package.json") 94# Check npm version
82EXPECTED_PNPM_VERSION=$(jq --raw-output .engines.pnpm <"./recipes/package.json") 95EXPECTED_NPM_VERSION=$(jq --raw-output .engines.npm ./package.json)
83if [[ "$(npm --version)" != "$EXPECTED_NPM_VERSION" ]]; then 96ACTUAL_NPM_VERSION=$(npm --version)
84 npm i -gf "npm@$EXPECTED_NPM_VERSION" 97if [[ "$ACTUAL_NPM_VERSION" != "$EXPECTED_NPM_VERSION" ]]; then
98 npm i -gf npm@$EXPECTED_NPM_VERSION
85fi 99fi
86if [[ "$(pnpm --version)" != "$EXPECTED_PNPM_VERSION" ]]; then 100
87 npm i -gf "pnpm@$EXPECTED_PNPM_VERSION" 101# Check pnpm version
102EXPECTED_PNPM_VERSION=$(jq --raw-output .engines.pnpm ./recipes/package.json)
103ACTUAL_PNPM_VERSION=$(pnpm --version)
104if [[ "$ACTUAL_PNPM_VERSION" != "$EXPECTED_PNPM_VERSION" ]]; then
105 npm i -gf pnpm@$EXPECTED_PNPM_VERSION
88fi 106fi
89 107
90# If 'asdf' is installed, reshim for new nodejs if necessary 108# If 'asdf' is installed, reshim for new nodejs if necessary
91command_exists asdf && asdf reshim nodejs 109command_exists asdf && asdf reshim nodejs
92 110
111# -----------------------------------------------------------------------------
93# This is useful if we move from 'npm' to 'pnpm' for the main repo as well 112# This is useful if we move from 'npm' to 'pnpm' for the main repo as well
94if [[ -s 'pnpm-lock.yaml' ]]; then 113if [[ -s 'pnpm-lock.yaml' ]]; then
95 BASE_CMD=pnpm 114 BASE_CMD=pnpm
@@ -123,13 +142,16 @@ else
123 TARGET_OS="linux" 142 TARGET_OS="linux"
124fi 143fi
125 144
126$BASE_CMD run build -- "--$TARGET_ARCH" --"$TARGET_OS" --dir 145$BASE_CMD run build -- --$TARGET_ARCH --$TARGET_OS --dir
127 146
128printf "\n*************** App successfully built! ***************\n" 147printf "\n*************** App successfully built! ***************\n"
148
129# Final check to ensure that the version built is the same as the latest commit 149# Final check to ensure that the version built is the same as the latest commit
130cat build/buildInfo.json 150VERSION_BUILT_HASH=$(jq --raw-output .gitHashShort ./build/buildInfo.json)
131git --no-pager log -1 151GIT_BUILT_HASH=$(git rev-parse --short HEAD)
132if [[ $(git rev-parse --short HEAD) != $(jq --raw-output .gitHashShort <"build/buildInfo.json") ]]; then 152if [[ $GIT_BUILT_HASH != $VERSION_BUILT_HASH ]]; then
133 echo "The built version is not on the latest commit" 153 echo "The built version is not on the latest commit
154 latest commit : [$GIT_BUILT_HASH]
155 actual build : [$VERSION_BUILT_HASH]"
134 exit 1 156 exit 1
135fi 157fi
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 @@
1# INTRO: 1# INTRO:
2# This file is used to build ferdium on windows. 2# This file is used to build ferdium on windows.
3# It also handles any corrupted node modules with the 'CLEAN' env var (set it to 'true' for cleaning) 3# It also handles any corrupted node modules with the 'CLEAN' env var (set it to 'true' for cleaning)
4# It will install the system dependencies except for node (which is still verified) 4# It will install the system dependencies except for node and python (which are still verified)
5# I sometimes symlink my 'recipes' folder so that any changes that I need to do in it can also be committed and pushed 5# I sometimes symlink my 'recipes' folder so that any changes that I need to do in it can also be committed and pushed independently
6# This file can live anywhere in your PATH 6# This file can live anywhere in your PATH
7 7
8#CHECK PYTHON
9#CHECK NODE.JS
10#CHECK NPM
11#CHECK MSVS_VERSION and MSVS Tools
12
13$USERHOME = "${env:HOMEDRIVE}${env:HOMEPATH}" 8$USERHOME = "${env:HOMEDRIVE}${env:HOMEPATH}"
14 9
15$env:ELECTRON_CACHE = $USERHOME + '/.cache/electron' 10$env:ELECTRON_CACHE = $USERHOME + '/.cache/electron'
16$env:ELECTRON_BUILDER_CACHE = $USERHOME + '/.cache/electron-builder' 11$env:ELECTRON_BUILDER_CACHE = $USERHOME + '/.cache/electron-builder'
17$env:CSC_IDENTITY_AUTO_DISCOVERY = $false 12$env:CSC_IDENTITY_AUTO_DISCOVERY = $false
18
19$env:CI = $true 13$env:CI = $true
20 14
21$EXPECTED_NODE_VERSION = (Get-Content .\.nvmrc) 15# -----------------------------------------------------------------------------
22$ACTUAL_NODE_VERSION = (node -v) 16# Utility functions
23 17
24if ( "v$EXPECTED_NODE_VERSION" -ne $ACTUAL_NODE_VERSION) 18Function fail_with_docs {Param ($1)
25{ 19 Write-Host "*************** FAILING ***************"
26 Write-Host "You are not running the expected version of node!" 20 Write-Host "$1"
27 Write-Host " expected: [v$EXPECTED_NODE_VERSION]" 21 Write-Host ""
28 Write-Host " actual : [$ACTUAL_NODE_VERSION]" 22 Write-Host "Please read the developer documentation in CONTRIBUTING.md"
29 exit 1 23 exit 1
30} 24}
31 25
32if ( $env:CLEAN -eq "true" ) 26Function Test-CommandExists { Param ($command, $1)
27 $oldPreference = $ErrorActionPreference
28 $ErrorActionPreference = "stop"
29
30 try {
31 if(Get-Command $command){RETURN}
32 } Catch {
33 fail_with_docs $1
34 }
35 Finally {$ErrorActionPreference=$oldPreference}
36}
37
38# -----------------------------------------------------------------------------
39# Checking the developer environment
40# Check for installed programmes
41Test-CommandExists node "Node is not installed"
42Test-CommandExists npm "npm is not installed"
43Test-CommandExists python "Python is not installed"
44# NEEDS proper way to CHECK MSVS Tools
45
46# Check node version
47$EXPECTED_NODE_VERSION = (cat .nvmrc)
48$ACTUAL_NODE_VERSION = (node -v)
49if ("v$EXPECTED_NODE_VERSION" -ne $ACTUAL_NODE_VERSION) {
50 fail_with_docs "You are not running the expected version of node!
51 expected: [v$EXPECTED_NODE_VERSION]
52 actual : [$ACTUAL_NODE_VERSION]"
53}
54
55# Check if the 'recipes' folder is present either as a git submodule or a symbolic link
56if (-not (Test-Path -Path "recipes/package.json" -PathType Leaf)) {
57 fail_with_docs "'recipes' folder is missing or submodule has not been checked out"
58}
59
60# This log statement is only to remind me which 'recipes' folder I am using (symlink or git submodule)
61# TODO: Implement this
62
63# -----------------------------------------------------------------------------
64# If you are moving to a new version of node or any other system dependency, then cleaning is recommended
65# so that there's no irregular results due to cached modules
66if ($env:CLEAN -eq "true")
33{ 67{
34 $NPM_PATH = "$USERHOME\.npm" 68 $NPM_PATH = "$USERHOME\.npm"
35 $NODE_GYP = "$USERHOME\.node-gyp" 69 $NODE_GYP = "$USERHOME\.node-gyp"
36 70
37 Write-Host "Cleaning!" 71 Write-Host "Cleaning!"
38 npm cache clean --force 72 npm cache clean --force
39 Remove-Item -Path $NPM_PATH -Recurse 73 Remove-Item -Path $NPM_PATH -Recurse -ErrorAction SilentlyContinue
40 Remove-Item -Path $NODE_GYP -Recurse 74 Remove-Item -Path $NODE_GYP -Recurse -ErrorAction SilentlyContinue
41 75
42 if ( Test-Path -Path ".\pnpm-lock.yaml" -and (Get-Command -ErrorAction Ignore -Type Application pnpm) ) 76 if ( (Test-Path -Path ".\pnpm-lock.yaml") -and (Get-Command -ErrorAction Ignore -Type Application pnpm) )
43 { 77 {
44 $PNPM_STORE = "$USERHOME\.pnpm-store" 78 $PNPM_STORE = "$USERHOME\.pnpm-store"
45 $PNPM_STATE = "$USERHOME\.pnpm-state" 79 $PNPM_STATE = "$USERHOME\.pnpm-state"
@@ -50,16 +84,54 @@ if ( $env:CLEAN -eq "true" )
50 Remove-Item -Path $PNPM_STATE -Recurse 84 Remove-Item -Path $PNPM_STATE -Recurse
51 } 85 }
52 86
53 git -C recipes clean -fxd 87 git -C recipes clean -fxd # Clean recipes folder/submodule
54 git clean -fxd # Note: This will blast away the 'recipes' folder if you have symlinked it 88 git clean -fxd # Note: This will blast away the 'recipes' folder if you have symlinked it
55} 89}
56 90
57# Ensure that the system dependencies are at the correct version 91# -----------------------------------------------------------------------------
58npm i -gf npm@8.7.0 92# Ensure that the system dependencies are at the correct version - fail if not
59npm i -gf pnpm@6.32.8 93# Check python version
94$EXPECTED_PYTHON_VERSION = "3.10.4"
95$ACTUAL_PYTHON_VERSION = (python --version).trim("Python ")
96if ([System.Version]$ACTUAL_PYTHON_VERSION -le [System.Version]$EXPECTED_PYTHON_VERSION) {
97 fail_with_docs "You are not running the expected version of Python!
98 expected: [$EXPECTED_PYTHON_VERSION]
99 actual : [$ACTUAL_PYTHON_VERSION]"
100}
101
102# TODO: Needs proper way to check MSVS Tools
103# Check MSVS Tools through MSVS_VERSION
104$EXPECTED_MSVST_VERSION = "2015"
105$ACTUAL_MSVST_VERSION = (npm config get msvs_version)
106if ([double]$ACTUAL_MSVST_VERSION -le [double]$EXPECTED_MSVST_VERSION) {
107 fail_with_docs "You are not running the expected version of MSVS Tools!
108 expected: [$EXPECTED_MSVST_VERSION]
109 actual : [$ACTUAL_MSVST_VERSION]"
110}
111
112# -----------------------------------------------------------------------------
113# Ensure that the system dependencies are at the correct version - recover if not
114# Check npm version
115$EXPECTED_NPM_VERSION = (Get-Content package.json | ConvertFrom-Json).engines.npm
116$ACTUAL_NPM_VERSION = (npm -v)
117if ($EXPECTED_NPM_VERSION -ne $ACTUAL_NPM_VERSION) {
118 Write-Host "You are not running the expected version of npm!
119 expected: [$EXPECTED_NPM_VERSION]
120 actual : [$ACTUAL_NPM_VERSION]"
121 Write-Host "Changing version of npm to [$EXPECTED_NPM_VERSION]"
122 npm i -gf npm@$EXPECTED_NPM_VERSION
123}
60 124
125# Check pnpm version
126$EXPECTED_PNPM_VERSION = (Get-Content recipes\package.json | ConvertFrom-Json).engines.pnpm
127ACTUAL_PNPM_VERSION=$(pnpm --version)
128if ($ACTUAL_PNPM_VERSION -ne $EXPECTED_PNPM_VERSION) {
129 npm i -gf pnpm@$EXPECTED_PNPM_VERSION
130}
131
132# -----------------------------------------------------------------------------
61# This is useful if we move from 'npm' to 'pnpm' for the main repo as well 133# This is useful if we move from 'npm' to 'pnpm' for the main repo as well
62if ( (Test-Path -Path ".\pnpm-lock.yaml") -and (Get-Command -ErrorAction Ignore -Type Application pnpm) ) 134if ((Test-Path -Path ".\pnpm-lock.yaml") -and (Get-Command -ErrorAction Ignore -Type Application pnpm))
63{ 135{
64 $BASE_CMD="pnpm" 136 $BASE_CMD="pnpm"
65 $env:EXEC_CMD="pnpm dlx" 137 $env:EXEC_CMD="pnpm dlx"
@@ -74,27 +146,28 @@ else
74& $BASE_CMD i 146& $BASE_CMD i
75& $BASE_CMD run prepare-code 147& $BASE_CMD run prepare-code
76 148
77# Check if the 'recipes' folder is present either as a git submodule or a symbolic link 149# -----------------------------------------------------------------------------
78if (-not (Test-Path -Path ".\recipes\package.json")) 150Write-Host "\n*************** Building recipes ***************\n"
79{
80 try {
81 git submodule update --init --recursive --remote --rebase --force
82 } catch {
83 Write-Host "FAILING since 'recipes' folder/submodule has not been checked out"
84 exit 1
85 }
86}
87
88# Note: 'recipes' is already using only pnpm - can switch to $BASE_CMD AFTER both repos are using pnpm 151# Note: 'recipes' is already using only pnpm - can switch to $BASE_CMD AFTER both repos are using pnpm
89Set-Location recipes 152Push-Location recipes
90pnpm i 153pnpm i
91pnpm run package 154pnpm run package
92Set-Location .. 155Pop-Location
93 156
157# -----------------------------------------------------------------------------
158Write-Host "\n*************** Building app ***************\n"
94$TARGET_ARCH="x64" 159$TARGET_ARCH="x64"
95& $BASE_CMD run build -- --$TARGET_ARCH --dir 160& $BASE_CMD run build -- --$TARGET_ARCH --dir
96 161
162Write-Host "*************** App successfully built! ***************"
163
97# Final check to ensure that the version built is the same as the latest commit 164# Final check to ensure that the version built is the same as the latest commit
98# TODO: Need to make this an assertion similar to tthe unix-equivalent 165$VERSION_BUILT_HASH = (Get-Content "build/buildInfo.json" | ConvertFrom-Json).gitHashShort
99Get-Content "build/buildInfo.json" | ConvertFrom-Json 166$GIT_BUILT_HASH = (git rev-parse --short HEAD)
100git log -1 167if ($VERSION_BUILT_HASH -ne $GIT_BUILT_HASH)
168{
169 Write-Host "The built version is not on the latest commit!"
170 Write-Host " latest commit : [$GIT_BUILT_HASH]"
171 Write-Host " actual build : [$VERSION_BUILT_HASH]"
172 exit 1
173}