Skip to content

Commit 0d7e087

Browse files
committed
new unified build script: here goes nothing
1 parent ec3019b commit 0d7e087

16 files changed

+309
-379
lines changed

.github/workflows/notion-repackaged.yml

Lines changed: 27 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
name: Notion Repackaged Main
1+
name: repackage-notion-app
22

33
on:
44
push:
55
branches: [main]
66
paths:
7-
- 'notion-repackaged.sh'
7+
- 'env.sh'
88
- '.github/workflows/notion-repackaged.yml'
99

1010
workflow_dispatch:
@@ -15,31 +15,26 @@ env:
1515

1616
jobs:
1717
preload-variables:
18-
name: Preload variables
18+
name: preload variables
1919
runs-on: ubuntu-latest
2020
steps:
2121
- uses: actions/checkout@v2
2222
- id: preload-variables
2323
name: Load variables and set them as outputs
2424
run: |
25-
source notion-repackaged.sh
25+
source env.sh
2626
2727
echo "::set-output name=notion_version::$NOTION_VERSION"
2828
echo "::set-output name=notion_repackaged_revision::$NOTION_REPACKAGED_REVISION"
29-
echo "::set-output name=notion_download_hash::$NOTION_DOWNLOAD_HASH"
30-
echo "::set-output name=notion_enhancer_commit::$NOTION_ENHANCER_COMMIT"
3129
32-
NOTION_REPACKAGED_VERSION_REV="${NOTION_VERSION}-${NOTION_REPACKAGED_REVISION}"
3330
echo "::set-output name=notion_repackaged_version_rev::$NOTION_REPACKAGED_VERSION_REV"
3431
outputs:
3532
notion_version: ${{ steps.preload-variables.outputs.notion_version }}
3633
notion_repackaged_revision: ${{ steps.preload-variables.outputs.notion_repackaged_revision }}
3734
notion_repackaged_version_rev: ${{ steps.preload-variables.outputs.notion_repackaged_version_rev }}
38-
notion_download_hash: ${{ steps.preload-variables.outputs.notion_download_hash }}
39-
notion_enhancer_commit: ${{ steps.preload-variables.outputs.notion_enhancer_commit }}
4035

4136
create-release:
42-
name: Create release
37+
name: create release
4338
runs-on: ubuntu-latest
4439
needs: [preload-variables]
4540
steps:
@@ -50,62 +45,36 @@ jobs:
5045
with:
5146
version: ${{ needs.preload-variables.outputs.notion_repackaged_version_rev }}
5247

53-
make-vanilla-sources:
54-
name: Make vanilla sources
48+
generate-sources:
49+
name: extract and patch vanilla and enhanced sources
5550
runs-on: ubuntu-latest
56-
needs: [preload-variables]
57-
env:
58-
NOTION_VERSION: ${{ needs.preload-variables.outputs.notion_version }}
59-
NOTION_REPACKAGED_REVISION: ${{ needs.preload-variables.outputs.notion_repackaged_revision }}
51+
needs: [preload-variables, create-release]
6052
steps:
6153
- uses: actions/checkout@v2
62-
- name: Download official Windows build
63-
env:
64-
NOTION_DOWNLOAD_HASH: ${{ needs.preload-variables.outputs.notion_download_hash }}
65-
run: scripts/download-exe.sh
66-
- name: Extract sources from Windows Build
67-
run: scripts/extract-src.sh
68-
- name: Zip sources dir with 7z
54+
- name: install build dependencies
55+
run: sudo apt install --no-install-recommends -y curl p7zip-full coreutils jq git imagemagick icnsutils
56+
- name: run build script
57+
run: ./build.sh --reset
58+
- name: zip vanilla source dir with 7z
6959
working-directory: build
7060
run: 7z a vanilla-src.zip vanilla-src
71-
- name: Save vanilla sources as artifact
61+
- name: save vanilla source as artifact
7262
uses: actions/upload-artifact@v2
7363
with:
7464
name: vanilla-sources
7565
path: build/vanilla-src.zip
76-
77-
make-enhanced-sources:
78-
name: Make enhanced sources
79-
needs: [make-vanilla-sources, preload-variables]
80-
runs-on: ubuntu-latest
81-
steps:
82-
- uses: actions/checkout@v2
83-
- name: Retrieve saved vanilla sources
84-
uses: actions/download-artifact@v2
85-
with:
86-
name: vanilla-sources
87-
path: build/vanilla-src.zip
88-
- name: Unzip sources with 7z
89-
working-directory: build
90-
run: 7z x vanilla-src.zip
91-
- name: Install icnsutils
92-
run: sudo apt-get install -y icnsutils
93-
- name: Enhance extracted sources
94-
env:
95-
NOTION_ENHANCER_COMMIT: ${{ needs.preload-variables.outputs.notion_enhancer_commit }}
96-
run: scripts/enhance-src.sh
97-
- name: Zip sources dir with 7z
66+
- name: zip enhanced source dir with 7z
9867
working-directory: build
9968
run: 7z a enhanced-src.zip enhanced-src
100-
- name: Save enhanced sources as artifact
69+
- name: save enhanced source as artifact
10170
uses: actions/upload-artifact@v2
10271
with:
10372
name: enhanced-sources
10473
path: build/enhanced-src.zip
10574

10675
build-app:
107-
name: Build app
108-
needs: [make-vanilla-sources, make-enhanced-sources, preload-variables, create-release]
76+
name: build app
77+
needs: [generate-sources, preload-variables, create-release]
10978
runs-on: ${{ matrix.os }}
11079
env:
11180
NOTION_VERSION: ${{ needs.preload-variables.outputs.notion_version }}
@@ -131,34 +100,34 @@ jobs:
131100
- uses: actions/setup-node@v1
132101
with:
133102
node-version: 14
134-
- name: Retrieve saved sources
103+
- name: retrieve saved sources
135104
uses: actions/download-artifact@v2
136105
with:
137106
name: ${{ matrix.edition }}-sources
138-
path: sources.zip
139-
- name: Unzip sources with 7z
140-
run: 7z x sources.zip
107+
path: build/${{ matrix.edition }}-src.zip
108+
- name: unzip sources with 7z
109+
run: 7z x build/${{ matrix.edition }}-src.zip
141110
- name: Install Linux build dependencies
142111
if: matrix.os == 'ubuntu-latest'
143112
run: sudo apt-get install --no-install-recommends -y libopenjp2-tools rpm libarchive-tools
144-
- name: Install dependencies
113+
- name: install dependencies
145114
working-directory: ${{ matrix.edition }}-src
146115
run: npm install
147-
- name: Run patch-package
116+
- name: run patch-package
148117
working-directory: ${{ matrix.edition }}-src
149118
run: npx patch-package
150-
- name: Install electron and electron-builder
119+
- name: install electron and electron-builder
151120
working-directory: ${{ matrix.edition }}-src
152121
run: npm install electron@11 electron-builder --save-dev
153-
- name: Run electron-builder
122+
- name: run electron-builder
154123
working-directory: ${{ matrix.edition }}-src
155124
env:
156125
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
157126
NOTION_REPACKAGED_EDITION: ${{ matrix.edition }}
158127
run: npx electron-builder --${{ matrix.target }} -c ../electron-builder.js
159128

160129
cleanup:
161-
name: Cleanup artifacts
130+
name: cleanup artifacts
162131
if: always()
163132
needs: [build-app]
164133
strategy:

build.sh

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
source env.sh
5+
6+
if [ "${NOTION_REPACKAGED_DEBUG}" = true ]; then
7+
set -x
8+
fi
9+
10+
11+
function log() {
12+
echo "[$1]: ${@:2}"
13+
}
14+
15+
function check-cmd() {
16+
for cmd_name in "$@"; do
17+
if ! command -v ${cmd_name} > /dev/null; then
18+
log "dependency-check" "missing required command dependency: $1"
19+
exit -1
20+
fi
21+
done
22+
}
23+
24+
# sudo apt install curl p7zip-full coreutils jq git imagemagick icnsutils
25+
26+
check-cmd npm
27+
28+
reset_build=false
29+
enhance_build=true
30+
31+
compile_vanilla=false
32+
compile_enhanced=false
33+
34+
while [[ $# -gt 0 ]]; do
35+
key="$1"
36+
case $key in
37+
--reset)
38+
reset_build=true
39+
shift
40+
;;
41+
--skip-enhance)
42+
enhance_build=false
43+
shift
44+
;;
45+
--compile-vanilla)
46+
compile_vanilla=true
47+
shift
48+
;;
49+
--compile-enhanced)
50+
compile_enhanced=true
51+
shift
52+
;;
53+
*)
54+
shift
55+
;;
56+
esac
57+
done
58+
59+
if $reset_build && [ -d "${WORKSPACE_DIR}/build" ]; then
60+
log "reset" "removing previous build artifacts..."
61+
rm -rf "${WORKSPACE_DIR}/build"
62+
fi
63+
64+
if ! [ -d "${WORKSPACE_DIR}/build" ]; then
65+
mkdir "${WORKSPACE_DIR}/build"
66+
pushd "${WORKSPACE_DIR}/build" > /dev/null
67+
68+
# download
69+
70+
log "download" "downloading notion.exe..."
71+
curl "${NOTION_DOWNLOAD_URL}" --output "${NOTION_DOWNLOADED_NAME}"
72+
73+
log "download" "verifying package checksum..."
74+
echo "${NOTION_DOWNLOAD_HASH} ${NOTION_DOWNLOADED_NAME}" | md5sum --check -
75+
76+
77+
# extract
78+
79+
log "extract" "extracting notion.exe..."
80+
81+
7z x -y "${NOTION_DOWNLOADED_NAME}" \
82+
-o"${NOTION_EXTRACTED_EXE_DIRNAME}" > /dev/null
83+
84+
log "extract" "extracting app.asar..."
85+
7z x -y "${NOTION_EXTRACTED_EXE_DIRNAME}/\$PLUGINSDIR/app-64.7z" \
86+
-o"${NOTION_EXTRACTED_APP_DIRNAME}" > /dev/null
87+
88+
log "extract" "copying vanilla src..."
89+
mkdir -p "${NOTION_VANILLA_SRC_DIRNAME}"
90+
cp -r "${NOTION_EXTRACTED_APP_DIRNAME}/resources/app/"* "${NOTION_VANILLA_SRC_DIRNAME}"
91+
92+
log "extract" "removing old node_modules to ensure platform compatibility..."
93+
rm -rf "${NOTION_VANILLA_SRC_DIRNAME}/node_modules"
94+
95+
log "extract" "adding fields to package.json to prepare for compiling..."
96+
PATCHED_PACKAGE_JSON=$(jq \
97+
--arg homepage "${NOTION_REPACKAGED_HOMEPAGE}" \
98+
--arg repo "${NOTION_REPACKAGED_REPO}" \
99+
--arg author "${NOTION_REPACKAGED_AUTHOR}" \
100+
--arg version "${NOTION_REPACKAGED_VERSION_REV}" \
101+
'.dependencies.cld="2.7.0" |
102+
.name="notion-app" |
103+
.homepage=$homepage |
104+
.repository=$repo |
105+
.author=$author |
106+
.version=$version' "${NOTION_VANILLA_SRC_DIRNAME}/package.json"
107+
)
108+
echo "${PATCHED_PACKAGE_JSON}" > "${NOTION_VANILLA_SRC_DIRNAME}/package.json"
109+
110+
fi
111+
112+
if $enhance_build; then
113+
114+
# enhance
115+
116+
if [ -d "${NOTION_ENHANCED_SRC_DIRNAME}" ]; then
117+
log "enhance" "removing previous enhanced src copy..."
118+
rm -rf "${NOTION_ENHANCED_SRC_DIRNAME}"
119+
fi
120+
121+
log "enhance" "copying enhanced src..."
122+
cp -r "${NOTION_VANILLA_SRC_DIRNAME}" "${NOTION_ENHANCED_SRC_DIRNAME}"
123+
124+
log "enhance" "adding enhancer dependencies to package.json..."
125+
PATCHED_PACKAGE_JSON=$(jq '
126+
.dependencies += {"keyboardevent-from-electron-accelerator": "^2.0.0"} |
127+
.name="notion-app-enhanced"' "${NOTION_ENHANCED_SRC_DIRNAME}/package.json")
128+
echo "${PATCHED_PACKAGE_JSON}" > "${NOTION_ENHANCED_SRC_DIRNAME}/package.json"
129+
130+
log "enhance" "downloading enhancer src..."
131+
132+
git clone "${NOTION_ENHANCER_REPO_URL}" "${NOTION_EMBEDDED_DIRNAME}"
133+
134+
pushd "${NOTION_EMBEDDED_DIRNAME}" > /dev/null
135+
git reset "${NOTION_ENHANCER_COMMIT}" --hard
136+
rm -rf .git
137+
138+
log "enhance" "injecting enhancer loader..."
139+
for patchable_file in $(find . -type d \( -path "./${NOTION_EMBEDDED_DIRNAME}" -o -path ./node_modules \) -prune -false -o -name '*.js'); do
140+
patchable_file_dir=$(dirname $patchable_file)
141+
rel_loader_path=$(realpath "${NOTION_EMBEDDED_DIRNAME}/pkg/loader.js" --relative-to "$patchable_file_dir")
142+
[ $patchable_file_dir = '.' ] && rel_loader_path="./"$rel_loader_path
143+
rel_loader_require="require('${rel_loader_path}')(__filename, exports);"
144+
145+
echo -e "\n\n" >> $patchable_file
146+
echo "//notion-enhancer" >> $patchable_file
147+
echo "${rel_loader_require}" >> $patchable_file
148+
done
149+
150+
# patch
151+
152+
log "patch" "applying notion patches..."
153+
pushd "${NOTION_ENHANCED_SRC_DIRNAME}" > /dev/null
154+
find "${WORKSPACE_DIR}/patches/notion" -type f -wholename "*.patch" -print0 | while IFS= read -r -d '' file; do
155+
patch -p0 --binary < "$file"
156+
done
157+
sed -i 's|process.platform === "win32"|process.platform !== "darwin"|g' main/main.js
158+
159+
log "patch" "applying enhancer patches..."
160+
pushd "${NOTION_EMBEDDED_DIRNAME}" > /dev/null
161+
find "${WORKSPACE_DIR}/patches/enhancer" -type f -wholename "*.patch" -print0 | while IFS= read -r -d '' file; do
162+
patch -p0 --binary < "$file"
163+
done
164+
165+
log "patch" "converting app icon to png..."
166+
pushd "${NOTION_ENHANCED_SRC_DIRNAME}" > /dev/null
167+
convert "icon.ico[0]" "icon.png"
168+
169+
log "patch" "swapping out vanilla icons..."
170+
mkdir -p vanilla
171+
mv icon.icns vanilla/icon.icns
172+
mv icon.png vanilla/icon.png
173+
mv icon.ico vanilla/icon.ico
174+
175+
enhancer_icons="${WORKSPACE_DIR}/assets/enhancer-icons"
176+
177+
cp "${enhancer_icons}/512x512.png" icon.png
178+
179+
log "patch" "converting icon to multi-size ico for windows"
180+
# http://www.imagemagick.org/Usage/thumbnails/#favicon
181+
convert "${enhancer_icons}/512x512.png" -resize 256x256 \
182+
-define icon:auto-resize="256,128,96,64,48,32,16" \
183+
icon.ico
184+
185+
log "patch" "converting icon to multi-size for mac and linux"
186+
# https://askubuntu.com/questions/223215/how-can-i-convert-a-png-file-to-icns
187+
png2icns icon.icns \
188+
"${enhancer_icons}/512x512.png" \
189+
"${enhancer_icons}/256x256.png" \
190+
"${enhancer_icons}/128x128.png" \
191+
"${enhancer_icons}/32x32.png" \
192+
"${enhancer_icons}/16x16.png"
193+
194+
fi
195+
196+
197+
if $compile_vanilla; then
198+
pushd "${NOTION_VANILLA_SRC_DIRNAME}" > /dev/null
199+
fi
200+
if $compile_enhanced; then
201+
pushd "${NOTION_ENHANCED_SRC_DIRNAME}" > /dev/null
202+
fi
203+
204+
if $compile_vanilla || $compile_enhanced; then
205+
log "compile" "installing dependencies..."
206+
npm install
207+
208+
log "compile" "install electron and electron-builder..."
209+
npm install electron@11 electron-builder --save-dev
210+
211+
log "compile" "running electron-builder..."
212+
node_modules/.bin/electron-builder \
213+
--config $WORKSPACE_DIR/electron-builder.js $@
214+
fi
215+

0 commit comments

Comments
 (0)