diff options
author | Nathanaël Houn <contact@nathanaelhoun.fr> | 2022-04-22 11:51:48 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-22 09:51:48 +0000 |
commit | 81b4aae66515b6eec2ac98fda50b1a59bffd94e3 (patch) | |
tree | e61886514667101ff8169aa09daa375c9853eb35 /scripts/build-unix.sh | |
parent | Fix build for snapcraft: command not found (diff) | |
download | ferdium-app-81b4aae66515b6eec2ac98fda50b1a59bffd94e3.tar.gz ferdium-app-81b4aae66515b6eec2ac98fda50b1a59bffd94e3.tar.zst ferdium-app-81b4aae66515b6eec2ac98fda50b1a59bffd94e3.zip |
Added build scripts for linux, macos and windows to help new contributors get setup quickly (#21)
Co-authored-by: Vijay A <vraravam@users.noreply.github.com>
Co-authored-by: André Oliveira <oliveira.andrerodrigues95@gmail.com>
Diffstat (limited to 'scripts/build-unix.sh')
-rwxr-xr-x | scripts/build-unix.sh | 135 |
1 files changed, 135 insertions, 0 deletions
diff --git a/scripts/build-unix.sh b/scripts/build-unix.sh new file mode 100755 index 000000000..e80c38059 --- /dev/null +++ b/scripts/build-unix.sh | |||
@@ -0,0 +1,135 @@ | |||
1 | #!/bin/bash | ||
2 | |||
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). | ||
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) | ||
7 | # I sometimes symlink my 'recipes' folder so that any changes that I need to do in it can also be committed and pushed | ||
8 | # This file can live anywhere in your PATH | ||
9 | |||
10 | set -e | ||
11 | |||
12 | export ELECTRON_CACHE=$HOME/.cache/electron | ||
13 | export ELECTRON_BUILDER_CACHE=$HOME/.cache/electron-builder | ||
14 | export CSC_IDENTITY_AUTO_DISCOVERY=false | ||
15 | export CI=true | ||
16 | |||
17 | # ----------------------------------------------------------------------------- | ||
18 | # Utility functions | ||
19 | fail_with_docs() { | ||
20 | printf "\n*************** FAILING ***************\n" | ||
21 | echo "$1" | ||
22 | echo "" | ||
23 | echo "Please read the developer documentation in CONTRIBUTING.md" | ||
24 | exit 1 | ||
25 | } | ||
26 | |||
27 | command_exists() { | ||
28 | type "$1" &>/dev/null 2>&1 | ||
29 | } | ||
30 | |||
31 | # ----------------------------------------------------------------------------- | ||
32 | # Checking the developer environment | ||
33 | # checking for installed programmes | ||
34 | command_exists node || fail_with_docs "Node is not installed" | ||
35 | command_exists jq || fail_with_docs "jq is not installed" | ||
36 | |||
37 | EXPECTED_NODE_VERSION=$(cat .nvmrc) | ||
38 | ACTUAL_NODE_VERSION=$(node -v) | ||
39 | if [ "v$EXPECTED_NODE_VERSION" != "$ACTUAL_NODE_VERSION" ]; then | ||
40 | fail_with_docs "You are not running the expected version of node! | ||
41 | expected: [v$EXPECTED_NODE_VERSION] | ||
42 | actual : [$ACTUAL_NODE_VERSION]" | ||
43 | fi | ||
44 | |||
45 | # Check if the 'recipes' folder is present either as a git submodule or a symbolic link | ||
46 | if ! [ -f "recipes/package.json" ]; then | ||
47 | fail_with_docs "'recipes' folder is missing or submodule has not been checked out" | ||
48 | fi | ||
49 | |||
50 | # This log statement is only to remind me which 'recipes' folder I am using (symlink or git submodule) | ||
51 | if [[ -L recipes ]]; then | ||
52 | printf "\n*************** CONTINUING for 'recipes' symlinked ***************\n" | ||
53 | else | ||
54 | printf "\n*************** CONTINUING for 'recipes' submodule ***************\n" | ||
55 | fi | ||
56 | |||
57 | # ----------------------------------------------------------------------------- | ||
58 | # If you are moving to a new version of node or any other system dependency, then cleaning is recommended | ||
59 | # so that there's no irregular results due to cached modules | ||
60 | if [ "$CLEAN" != "true" ]; then | ||
61 | printf "\n*************** SKIPPING Cleaning ***************\n" | ||
62 | else | ||
63 | printf "\n*************** Cleaning!!!!!! ***************\n" | ||
64 | npm cache clean --force | ||
65 | rm -rf ~/.npm ~/.node-gyp ~/.asdf/installs/nodejs/*/.npm/ | ||
66 | if [[ -s 'pnpm-lock.yaml' ]]; then | ||
67 | pnpm store prune || true # in case the pnpm executable itself is not present | ||
68 | rm -rf ~/.pnpm-store ~/.pnpm-state | ||
69 | fi | ||
70 | |||
71 | git -C recipes clean -fxd # Clean recipes folder/submodule | ||
72 | git clean -fxd # Note: This will blast away the 'recipes' folder if you have symlinked it | ||
73 | fi | ||
74 | |||
75 | # ----------------------------------------------------------------------------- | ||
76 | printf "\n*************** Installing node dependencies ***************\n" | ||
77 | # If 'asdf' is installed, reshim for new nodejs if necessary | ||
78 | command_exists asdf && asdf reshim nodejs | ||
79 | |||
80 | # Ensure that the system dependencies are at the correct version | ||
81 | EXPECTED_NPM_VERSION=$(jq --raw-output .engines.npm <"package.json") | ||
82 | EXPECTED_PNPM_VERSION=$(jq --raw-output .engines.pnpm <"./recipes/package.json") | ||
83 | if [[ "$(npm --version)" != "$EXPECTED_NPM_VERSION" ]]; then | ||
84 | npm i -gf "npm@$EXPECTED_NPM_VERSION" | ||
85 | fi | ||
86 | if [[ "$(pnpm --version)" != "$EXPECTED_PNPM_VERSION" ]]; then | ||
87 | npm i -gf "pnpm@$EXPECTED_PNPM_VERSION" | ||
88 | fi | ||
89 | |||
90 | # If 'asdf' is installed, reshim for new nodejs if necessary | ||
91 | command_exists asdf && asdf reshim nodejs | ||
92 | |||
93 | # This is useful if we move from 'npm' to 'pnpm' for the main repo as well | ||
94 | if [[ -s 'pnpm-lock.yaml' ]]; then | ||
95 | BASE_CMD=pnpm | ||
96 | else | ||
97 | BASE_CMD=npm | ||
98 | fi | ||
99 | |||
100 | # Now the meat..... | ||
101 | $BASE_CMD i | ||
102 | $BASE_CMD run prepare-code | ||
103 | |||
104 | # ----------------------------------------------------------------------------- | ||
105 | printf "\n*************** Building recipes ***************\n" | ||
106 | # Note: 'recipes' is already using only pnpm - can switch to $BASE_CMD AFTER both repos are using pnpm | ||
107 | pushd recipes | ||
108 | pnpm i | ||
109 | pnpm run package | ||
110 | popd | ||
111 | |||
112 | # ----------------------------------------------------------------------------- | ||
113 | printf "\n*************** Building app ***************\n" | ||
114 | if [[ "$(uname -m)" =~ "arm" ]]; then | ||
115 | TARGET_ARCH=arm64 | ||
116 | else | ||
117 | TARGET_ARCH=x64 | ||
118 | fi | ||
119 | |||
120 | if [[ "$(uname)" =~ "Darwin" ]]; then | ||
121 | TARGET_OS="mac" | ||
122 | else | ||
123 | TARGET_OS="linux" | ||
124 | fi | ||
125 | |||
126 | $BASE_CMD run build -- "--$TARGET_ARCH" --"$TARGET_OS" --dir | ||
127 | |||
128 | printf "\n*************** App successfully built! ***************\n" | ||
129 | # Final check to ensure that the version built is the same as the latest commit | ||
130 | cat build/buildInfo.json | ||
131 | git --no-pager log -1 | ||
132 | if [[ $(git rev-parse --short HEAD) != $(jq --raw-output .gitHashShort <"build/buildInfo.json") ]]; then | ||
133 | echo "The built version is not on the latest commit" | ||
134 | exit 1 | ||
135 | fi | ||