diff options
author | André Oliveira <37463445+SpecialAro@users.noreply.github.com> | 2022-04-23 12:05:13 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-23 11:05:13 +0000 |
commit | 1c35622c66309984cecddd6892fe2060ef21a447 (patch) | |
tree | 27651692f01cbdd4e2b2b6be8a057524035e5a97 /scripts | |
parent | 6.0.0-nightly.9 [skip ci] (diff) | |
download | ferdium-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-x | scripts/build-unix.sh | 52 | ||||
-rw-r--r-- | scripts/build-windows.ps1 | 155 |
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 | ||
10 | set -e | 10 | set -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 |
34 | command_exists node || fail_with_docs "Node is not installed" | 34 | command_exists node || fail_with_docs "Node is not installed" |
35 | command_exists jq || fail_with_docs "jq is not installed" | 35 | command_exists jq || fail_with_docs "jq is not installed" |
36 | command_exists python || fail_with_docs "python is not installed" | ||
36 | 37 | ||
38 | # Check node version | ||
37 | EXPECTED_NODE_VERSION=$(cat .nvmrc) | 39 | EXPECTED_NODE_VERSION=$(cat .nvmrc) |
38 | ACTUAL_NODE_VERSION=$(node -v) | 40 | ACTUAL_NODE_VERSION=$(node -v) |
39 | if [ "v$EXPECTED_NODE_VERSION" != "$ACTUAL_NODE_VERSION" ]; then | 41 | if [ "v$EXPECTED_NODE_VERSION" != "$ACTUAL_NODE_VERSION" ]; then |
@@ -73,23 +75,40 @@ else | |||
73 | fi | 75 | fi |
74 | 76 | ||
75 | # ----------------------------------------------------------------------------- | 77 | # ----------------------------------------------------------------------------- |
76 | printf "\n*************** Installing node dependencies ***************\n" | 78 | # Ensure that the system dependencies are at the correct version - fail if not |
79 | # Check python version | ||
80 | EXPECTED_PYTHON_VERSION="3.10.4" | ||
81 | ACTUAL_PYTHON_VERSION=$(python --version | sed -e "s/Python //") | ||
82 | if [[ "$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]" | ||
86 | fi | ||
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 |
78 | command_exists asdf && asdf reshim nodejs | 91 | command_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 |
81 | EXPECTED_NPM_VERSION=$(jq --raw-output .engines.npm <"package.json") | 94 | # Check npm version |
82 | EXPECTED_PNPM_VERSION=$(jq --raw-output .engines.pnpm <"./recipes/package.json") | 95 | EXPECTED_NPM_VERSION=$(jq --raw-output .engines.npm ./package.json) |
83 | if [[ "$(npm --version)" != "$EXPECTED_NPM_VERSION" ]]; then | 96 | ACTUAL_NPM_VERSION=$(npm --version) |
84 | npm i -gf "npm@$EXPECTED_NPM_VERSION" | 97 | if [[ "$ACTUAL_NPM_VERSION" != "$EXPECTED_NPM_VERSION" ]]; then |
98 | npm i -gf npm@$EXPECTED_NPM_VERSION | ||
85 | fi | 99 | fi |
86 | if [[ "$(pnpm --version)" != "$EXPECTED_PNPM_VERSION" ]]; then | 100 | |
87 | npm i -gf "pnpm@$EXPECTED_PNPM_VERSION" | 101 | # Check pnpm version |
102 | EXPECTED_PNPM_VERSION=$(jq --raw-output .engines.pnpm ./recipes/package.json) | ||
103 | ACTUAL_PNPM_VERSION=$(pnpm --version) | ||
104 | if [[ "$ACTUAL_PNPM_VERSION" != "$EXPECTED_PNPM_VERSION" ]]; then | ||
105 | npm i -gf pnpm@$EXPECTED_PNPM_VERSION | ||
88 | fi | 106 | fi |
89 | 107 | ||
90 | # If 'asdf' is installed, reshim for new nodejs if necessary | 108 | # If 'asdf' is installed, reshim for new nodejs if necessary |
91 | command_exists asdf && asdf reshim nodejs | 109 | command_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 |
94 | if [[ -s 'pnpm-lock.yaml' ]]; then | 113 | if [[ -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" |
124 | fi | 143 | fi |
125 | 144 | ||
126 | $BASE_CMD run build -- "--$TARGET_ARCH" --"$TARGET_OS" --dir | 145 | $BASE_CMD run build -- --$TARGET_ARCH --$TARGET_OS --dir |
127 | 146 | ||
128 | printf "\n*************** App successfully built! ***************\n" | 147 | printf "\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 |
130 | cat build/buildInfo.json | 150 | VERSION_BUILT_HASH=$(jq --raw-output .gitHashShort ./build/buildInfo.json) |
131 | git --no-pager log -1 | 151 | GIT_BUILT_HASH=$(git rev-parse --short HEAD) |
132 | if [[ $(git rev-parse --short HEAD) != $(jq --raw-output .gitHashShort <"build/buildInfo.json") ]]; then | 152 | if [[ $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 |
135 | fi | 157 | 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 @@ | |||
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 | ||
24 | if ( "v$EXPECTED_NODE_VERSION" -ne $ACTUAL_NODE_VERSION) | 18 | Function 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 | ||
32 | if ( $env:CLEAN -eq "true" ) | 26 | Function 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 | ||
41 | Test-CommandExists node "Node is not installed" | ||
42 | Test-CommandExists npm "npm is not installed" | ||
43 | Test-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) | ||
49 | if ("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 | ||
56 | if (-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 | ||
66 | if ($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 | # ----------------------------------------------------------------------------- |
58 | npm i -gf npm@8.7.0 | 92 | # Ensure that the system dependencies are at the correct version - fail if not |
59 | npm 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 ") | ||
96 | if ([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) | ||
106 | if ([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) | ||
117 | if ($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 | ||
127 | ACTUAL_PNPM_VERSION=$(pnpm --version) | ||
128 | if ($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 |
62 | if ( (Test-Path -Path ".\pnpm-lock.yaml") -and (Get-Command -ErrorAction Ignore -Type Application pnpm) ) | 134 | if ((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 | # ----------------------------------------------------------------------------- |
78 | if (-not (Test-Path -Path ".\recipes\package.json")) | 150 | Write-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 |
89 | Set-Location recipes | 152 | Push-Location recipes |
90 | pnpm i | 153 | pnpm i |
91 | pnpm run package | 154 | pnpm run package |
92 | Set-Location .. | 155 | Pop-Location |
93 | 156 | ||
157 | # ----------------------------------------------------------------------------- | ||
158 | Write-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 | ||
162 | Write-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 |
99 | Get-Content "build/buildInfo.json" | ConvertFrom-Json | 166 | $GIT_BUILT_HASH = (git rev-parse --short HEAD) |
100 | git log -1 | 167 | if ($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 | } | ||