forked from Chia-Network/chia-blockchain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_windows.ps1
182 lines (148 loc) · 5.73 KB
/
build_windows.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# $env:path should contain a path to editbin.exe and signtool.exe
$ErrorActionPreference = "Stop"
mkdir build_scripts\win_build
Set-Location -Path ".\build_scripts\win_build" -PassThru
git status
Write-Output " ---"
Write-Output "curl miniupnpc"
Write-Output " ---"
Invoke-WebRequest -Uri "https://pypi.chia.net/simple/miniupnpc/miniupnpc-2.2.2-cp39-cp39-win_amd64.whl" -OutFile "miniupnpc-2.2.2-cp39-cp39-win_amd64.whl"
Write-Output "Using win_amd64 python 3.9 wheel from https://github.com/miniupnp/miniupnp/pull/475 (2.2.0-RC1)"
Write-Output "Actual build from https://github.com/miniupnp/miniupnp/commit/7783ac1545f70e3341da5866069bde88244dd848"
If ($LastExitCode -gt 0){
Throw "Failed to download miniupnpc!"
}
else
{
Set-Location -Path - -PassThru
Write-Output "miniupnpc download successful."
}
Write-Output " ---"
Write-Output "Create venv - python3.9 is required in PATH"
Write-Output " ---"
python -m venv venv
. .\venv\Scripts\Activate.ps1
python -m pip install --upgrade pip
pip install wheel pep517
pip install pywin32
pip install pyinstaller==4.5
pip install setuptools_scm
Write-Output " ---"
Write-Output "Get CHIA_INSTALLER_VERSION"
# The environment variable CHIA_INSTALLER_VERSION needs to be defined
$env:CHIA_INSTALLER_VERSION = python .\build_scripts\installer-version.py -win
if (-not (Test-Path env:CHIA_INSTALLER_VERSION)) {
$env:CHIA_INSTALLER_VERSION = '0.0.0'
Write-Output "WARNING: No environment variable CHIA_INSTALLER_VERSION set. Using 0.0.0"
}
Write-Output "Chia Version is: $env:CHIA_INSTALLER_VERSION"
Write-Output " ---"
Write-Output "Checking if madmax exists"
Write-Output " ---"
if (Test-Path -Path .\madmax\) {
Write-Output " madmax exists, moving to expected directory"
mv .\madmax\ .\venv\lib\site-packages\
}
Write-Output "Checking if bladebit exists"
Write-Output " ---"
if (Test-Path -Path .\bladebit\) {
Write-Output " bladebit exists, moving to expected directory"
mv .\bladebit\ .\venv\lib\site-packages\
}
Write-Output " ---"
Write-Output "Build chia-blockchain wheels"
Write-Output " ---"
pip wheel --use-pep517 --extra-index-url https://pypi.chia.net/simple/ -f . --wheel-dir=.\build_scripts\win_build .
Write-Output " ---"
Write-Output "Install chia-blockchain wheels into venv with pip"
Write-Output " ---"
Write-Output "pip install miniupnpc"
Set-Location -Path ".\build_scripts" -PassThru
pip install --no-index --find-links=.\win_build\ miniupnpc
# Write-Output "pip install setproctitle"
# pip install setproctitle==1.2.2
Write-Output "pip install chia-blockchain"
pip install --no-index --find-links=.\win_build\ chia-blockchain
Write-Output " ---"
Write-Output "Use pyinstaller to create chia .exe's"
Write-Output " ---"
$SPEC_FILE = (python -c 'import chia; print(chia.PYINSTALLER_SPEC_PATH)') -join "`n"
pyinstaller --log-level INFO $SPEC_FILE
Write-Output " ---"
Write-Output "Copy chia executables to chia-blockchain-gui\"
Write-Output " ---"
Copy-Item "dist\daemon" -Destination "..\chia-blockchain-gui\packages\gui\" -Recurse
Write-Output " ---"
Write-Output "Setup npm packager"
Write-Output " ---"
Set-Location -Path ".\npm_windows" -PassThru
npm ci
$Env:Path = $(npm bin) + ";" + $Env:Path
Set-Location -Path "..\" -PassThru
Set-Location -Path "..\chia-blockchain-gui" -PassThru
# We need the code sign cert in the gui subdirectory so we can actually sign the UI package
If ($env:HAS_SECRET) {
Copy-Item "win_code_sign_cert.p12" -Destination "packages\gui\"
}
git status
Write-Output " ---"
Write-Output "Prepare Electron packager"
Write-Output " ---"
$Env:NODE_OPTIONS = "--max-old-space-size=3000"
lerna clean -y
npm ci
# Audit fix does not currently work with Lerna. See https://github.com/lerna/lerna/issues/1663
# npm audit fix
git status
Write-Output " ---"
Write-Output "Electron package Windows Installer"
Write-Output " ---"
npm run build
If ($LastExitCode -gt 0){
Throw "npm run build failed!"
}
# Change to the GUI directory
Set-Location -Path "packages\gui" -PassThru
Write-Output " ---"
Write-Output "Increase the stack for chia command for (chia plots create) chiapos limitations"
# editbin.exe needs to be in the path
editbin.exe /STACK:8000000 daemon\chia.exe
Write-Output " ---"
$packageVersion = "$env:CHIA_INSTALLER_VERSION"
$packageName = "Chia-$packageVersion"
Write-Output "packageName is $packageName"
Write-Output " ---"
Write-Output "fix version in package.json"
choco install jq
cp package.json package.json.orig
jq --arg VER "$env:CHIA_INSTALLER_VERSION" '.version=$VER' package.json > temp.json
rm package.json
mv temp.json package.json
Write-Output " ---"
Write-Output " ---"
Write-Output "electron-packager"
electron-packager . Chia --asar.unpack="**\daemon\**" --overwrite --icon=.\src\assets\img\chia.ico --app-version=$packageVersion
Write-Output " ---"
Write-Output " ---"
Write-Output "node winstaller.js"
node winstaller.js
Write-Output " ---"
git status
If ($env:HAS_SECRET) {
Write-Output " ---"
Write-Output "Add timestamp and verify signature"
Write-Output " ---"
signtool.exe timestamp /v /t http://timestamp.comodoca.com/ .\release-builds\windows-installer\ChiaSetup-$packageVersion.exe
signtool.exe verify /v /pa .\release-builds\windows-installer\ChiaSetup-$packageVersion.exe
} Else {
Write-Output "Skipping timestamp and verify signatures - no authorization to install certificates"
}
git status
Write-Output " ---"
Write-Output "Moving final installers to expected location"
Write-Output " ---"
Copy-Item ".\Chia-win32-x64" -Destination "$env:GITHUB_WORKSPACE\chia-blockchain-gui\" -Recurse
Copy-Item ".\release-builds" -Destination "$env:GITHUB_WORKSPACE\chia-blockchain-gui\" -Recurse
Write-Output " ---"
Write-Output "Windows Installer complete"
Write-Output " ---"