-
-
Notifications
You must be signed in to change notification settings - Fork 17
307 lines (260 loc) · 14.5 KB
/
build-windows-release.yml
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
name: Build Windows release
on:
workflow_dispatch:
inputs:
tag_name:
description: "What is tag name of the latest release? E.g., v5.29"
required: true
release:
types:
- published
jobs:
build-windows-release:
runs-on: windows-2022
env:
RELEASE_VERSION: ${{ github.event_name == 'release' && github.event.release.tag_name || inputs.tag_name }}
BUCKET_NAME: github-release-files-storage
CONDA_DIR: C:\Miniconda
steps:
- name: Checkout repository
uses: actions/checkout@v3
# - name: Debug dependencies
# shell: cmd
# run: |
# set root=%USERPROFILE%\EcoAssist
# echo root=%root%
# mkdir "%root%"
# git clone --ipv4 --depth 1 https://github.com/PetervanLunteren/visualise_detection.git "%root%\visualise_detection"
- name: Install dependencies
shell: cmd
run: |
echo off
@setlocal EnableDelayedExpansion
@REM init environment vars
set root=%USERPROFILE%\EcoAssist
set conda_exe=${{ env.CONDA_DIR }}\Scripts\conda.exe
echo Using conda %conda_exe%
@REM set high timeout value and ip address for ipv4 fallback issues
call "%conda_exe%" config --set remote_connect_timeout_secs 120
call "%conda_exe%" config --set remote_max_retries 5
call "%conda_exe%" config --set remote_read_timeout_secs 120
call "%conda_exe%" config --set ssl_verify False
call "%conda_exe%" config --set fetch_threads 2
call "%conda_exe%" config --show
@REM refresh dir
if exist "%root%" (
rmdir /s /q "%root%"
echo %root% folder removed
)
@REM set IPv4
set PIP_NO_IPV6=1
set CONDA_SSL_VERIFY=0
set CONDA_USE_IPV4=1
@REM create folder structure
mkdir "%root%"
mkdir "%root%\envs"
mkdir "%root%\models"
mkdir "%root%\models\det"
mkdir "%root%\models\cls"
mkdir "%root%\models\det\MegaDetector 5a"
mkdir "%root%\yolov5_versions\yolov5_old"
mkdir "%root%\yolov5_versions\yolov5_new"
echo Hello world! > "%root%\first-startup.txt"
@REM EcoAssist
git clone --ipv4 --depth 1 https://github.com/PetervanLunteren/EcoAssist.git "%root%\EcoAssist"
rmdir /s /q "%root%\EcoAssist\.git"
move "%root%\EcoAssist\main.py" "%root%\main.py"
set RAW_VERSION=${{ env.RELEASE_VERSION }}
set CLEAN_VERSION=%RAW_VERSION:v=%
echo %CLEAN_VERSION% > "%root%\EcoAssist\version.txt"
echo EcoAssist cloned
@REM MegaDetector
git clone --ipv4 https://github.com/agentmorris/MegaDetector.git "%root%\cameratraps"
pushd "%root%\cameratraps"
git checkout a64a8f8c467ae6c87b5ca09f54b1abe502168b50
popd
rmdir /s /q "%root%\cameratraps\.git"
echo MegaDetector cloned
@REM YOLOv5 old
git clone --ipv4 https://github.com/ultralytics/yolov5.git "%root%\yolov5_versions\yolov5_old\yolov5"
pushd "%root%\yolov5_versions\yolov5_old\yolov5"
git checkout c23a441c9df7ca9b1f275e8c8719c949269160d1
popd
rmdir /s /q "%root%\yolov5_versions\yolov5_old\yolov5\.git"
echo YOLOv5 old cloned
@REM YOLOv5 new
git clone --ipv4 https://github.com/ultralytics/yolov5.git "%root%\yolov5_versions\yolov5_new\yolov5"
pushd "%root%\yolov5_versions\yolov5_new\yolov5"
git checkout 3e55763d45f9c5f8217e4dad5ba1e6c1f42e3bf8
popd
rmdir /s /q "%root%\yolov5_versions\yolov5_new\yolov5\.git"
echo YOLOv5 new cloned
@REM Human in the loop
git clone --ipv4 --depth 1 https://github.com/PetervanLunteren/Human-in-the-loop.git "%root%\Human-in-the-loop"
rmdir /s /q "%root%\Human-in-the-loop\.git"
echo Human-in-the-loop cloned
@REM Visualise detections
git clone --ipv4 --depth 1 https://github.com/PetervanLunteren/visualise_detection.git "%root%\visualise_detection"
rmdir /s /q "%root%\visualise_detection\.git"
echo visualise_detection cloned
@REM MegaDetector model 5A
curl --ipv4 -L https://github.com/agentmorris/MegaDetector/releases/download/v5.0/md_v5a.0.0.pt -o "%root%/models\det\MegaDetector 5a\md_v5a.0.0.pt"
@REM install mamba
call "%conda_exe%" install -n base -c conda-forge mamba -y
@REM DEBUG
set conda_exe=${{ env.CONDA_DIR }}\condabin\mamba.bat
@REM env-base
call "%conda_exe%" env create --file "%root%\cameratraps\envs\environment-detector.yml" -p "%root%\envs\env-base"
call "%conda_exe%" run -p "%root%\envs\env-base" pip install --timeout=120 pyqt5==5.15.2 lxml
call "%conda_exe%" run -p "%root%\envs\env-base" pip install --timeout=120 RangeSlider gpsphoto exifread piexif openpyxl pyarrow customtkinter CTkTable
call "%conda_exe%" run -p "%root%\envs\env-base" pip install --timeout=120 GitPython==3.1.30
call "%conda_exe%" run -p "%root%\envs\env-base" pip install --timeout=120 folium plotly
call "%conda_exe%" run -p "%root%\envs\env-base" pip install --timeout=120 numpy==1.23.4
call "%conda_exe%" run -p "%root%\envs\env-base" pip install --timeout=120 pytorchwildlife==1.0.2.15
call "%conda_exe%" run -p "%root%\envs\env-base" pip uninstall torch torchvision -y
call "%conda_exe%" run -p "%root%\envs\env-base" pip install --timeout=120 torch==2.3.1+cu118 torchvision==0.18.1+cu118 --index-url https://download.pytorch.org/whl/cu118
@REM env-pytorch
call "%conda_exe%" create -p "%root%\envs\env-pytorch" python=3.8 -y
call "%conda_exe%" run -p "%root%\envs\env-pytorch" "%conda_exe%" pytorch==2.3.0 torchvision==0.18.0 torchaudio==2.3.0 pytorch-cuda=11.8 -c pytorch -c nvidia -y
call "%conda_exe%" run -p "%root%\envs\env-pytorch" pip install --timeout=120 ultralytics==8.0.230
call "%conda_exe%" run -p "%root%\envs\env-pytorch" pip install --timeout=120 timm
call "%conda_exe%" run -p "%root%\envs\env-pytorch" pip install --timeout=120 pandas
call "%conda_exe%" run -p "%root%\envs\env-pytorch" pip install --timeout=120 numpy
call "%conda_exe%" run -p "%root%\envs\env-pytorch" pip install --timeout=120 opencv-python
call "%conda_exe%" run -p "%root%\envs\env-pytorch" pip install --timeout=120 pillow
call "%conda_exe%" run -p "%root%\envs\env-pytorch" pip install --timeout=120 dill
call "%conda_exe%" run -p "%root%\envs\env-pytorch" pip install --timeout=120 hachoir
call "%conda_exe%" run -p "%root%\envs\env-pytorch" pip install --timeout=120 versions
call "%conda_exe%" run -p "%root%\envs\env-pytorch" pip install --timeout=120 jsonpickle
@REM env-tensorflow
call "%conda_exe%" env create --file "%root%\EcoAssist\classification_utils\envs\tensorflow-linux-windows.yml" -p "%root%\envs\env-tensorflow"
# @REM install PyInstaller
# call "%conda_exe%" create -p "${{ env.CONDA_DIR }}\envs\env-fresh" python=3.8 pyinstaller -y
# @REM normal executable
# call "%conda_exe%" run -p "${{ env.CONDA_DIR }}\envs\env-fresh" pyinstaller --onefile --noconsole --icon="%root%\EcoAssist\imgs\logo_small_bg.ico" --distpath="%USERPROFILE%\dist" --workpath="%USERPROFILE%\build" "%root%\main.py"
# move "%USERPROFILE%\dist\main.exe" "%root%/EcoAssist %RELEASE_VERSION%.exe"
# @REM debug executable
# call "%conda_exe%" run -p "${{ env.CONDA_DIR }}\envs\env-fresh" pyinstaller --onefile --console --icon="%root%\EcoAssist\imgs\logo_small_bg.ico" --distpath="%USERPROFILE%\dist" --workpath="%USERPROFILE%\build" "%root%\main.py"
# move "%USERPROFILE%\dist\main.exe" "%root%/EcoAssist %RELEASE_VERSION% debug.exe"
@REM conda clean
call "%conda_exe%" clean --all --yes --force-pkgs-dirs
call "%conda_exe%" clean --all --yes
call ${{ env.CONDA_DIR }}\condabin\mamba.bat clean --all --yes --force-pkgs-dirs
call ${{ env.CONDA_DIR }}\condabin\mamba.bat clean --all --yes
call ${{ env.CONDA_DIR }}\condabin\conda.bat clean --all --yes --force-pkgs-dirs
call ${{ env.CONDA_DIR }}\condabin\conda.bat clean --all --yes
- name: Create archive
shell: cmd
run: |
"C:\Program Files\7-Zip\7z.exe" a -t7z -mx9 "windows-${{ env.RELEASE_VERSION }}.7z" "%USERPROFILE%\EcoAssist\*"
- name: Authenticate with Google Cloud
uses: google-github-actions/auth@v1
with:
credentials_json: ${{ secrets.GOOGLE_STORAGE_UPLOAD_KEY }}
- name: Set up Google Cloud
uses: google-github-actions/setup-gcloud@v1
with:
project_id: github-file-storage
- name: Upload pinned 7z version to Google Cloud
shell: cmd
run: |
set BUCKET_NAME=${{ env.BUCKET_NAME }}
set PINNED_FOLDER_NAME=${{ env.RELEASE_VERSION }}
set LATEST_FOLDER_NAME=latest
set PINNED_FILE_NAME=windows-${{ env.RELEASE_VERSION }}.7z
set LATEST_FILE_NAME=windows-latest.7z
gsutil cp -r "%PINNED_FILE_NAME%" gs://%BUCKET_NAME%/%PINNED_FOLDER_NAME%/%PINNED_FILE_NAME%
- name: Upload latest 7z version to Google Cloud
shell: cmd
run: |
set BUCKET_NAME=${{ env.BUCKET_NAME }}
set PINNED_FOLDER_NAME=${{ env.RELEASE_VERSION }}
set LATEST_FOLDER_NAME=latest
set PINNED_FILE_NAME=windows-${{ env.RELEASE_VERSION }}.7z
set LATEST_FILE_NAME=windows-latest.7z
gsutil cp -r "%PINNED_FILE_NAME%" gs://%BUCKET_NAME%/%LATEST_FOLDER_NAME%/%LATEST_FILE_NAME%
# - name: Get the release body
# shell: pwsh
# run: Invoke-RestMethod -Uri https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ github.event.release.tag_name }} | ForEach-Object { $_.body } | Out-File -FilePath release_body.txt -Encoding utf8
# - name: Append link to release body
# shell: pwsh
# run: |
# Add-Content -Path "release_body.txt" -Value '- Install for **Windows**: [windows-${{ env.RELEASE_VERSION }}.7z](https://storage.googleapis.com/${{ env.BUCKET_NAME }}/${{ env.RELEASE_VERSION }}/windows-${{ env.RELEASE_VERSION }}.7z)'
# - name: Update the release body
# shell: cmd
# env:
# GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# run: |
# @echo off
# set RELEASE_NAME=${{ github.ref_name }}
# gh release edit %RELEASE_NAME% --notes-file release_body.txt
- name: Install Nsis7z Plugin
run: |
curl --ipv4 --retry 5 -L -o "%GITHUB_WORKSPACE%\Nsis7z_plugin.zip" "https://nsis.sourceforge.io/mediawiki/images/9/93/Nsis7z.zip"
dir "%GITHUB_WORKSPACE%\Nsis7z_plugin.zip"
7z x -bb3 -o"%GITHUB_WORKSPACE%\NSIS_Plugins" "%GITHUB_WORKSPACE%\Nsis7z_plugin.zip"
shell: cmd
- name: Install Inetc Plugin
run: |
curl --ipv4 --retry 5 -L -o "%GITHUB_WORKSPACE%\Inetc_plugin.zip" "https://nsis.sourceforge.io/mediawiki/images/c/c9/Inetc.zip"
dir "%GITHUB_WORKSPACE%\Inetc_plugin.zip"
7z x -bb3 -o"%GITHUB_WORKSPACE%\NSIS_Plugins" "%GITHUB_WORKSPACE%\Inetc_plugin.zip"
shell: cmd
- name: Append VERSION to NSIS script
shell: cmd
run: |
echo !define VERSION "${{ env.RELEASE_VERSION }}" > newFile.nsi
type "%GITHUB_WORKSPACE%\install_files\windows\nsis-install-compiler.nsi" >> newFile.nsi
move /Y newFile.nsi "%GITHUB_WORKSPACE%\install_files\windows\nsis-install-compiler.nsi"
- name: Create NSIS installer
uses: joncloud/makensis-action@publish
with:
script-file: "install_files/windows/nsis-install-compiler.nsi"
additional-plugin-paths: ${{ github.workspace }}/NSIS_Plugins/Plugins
- name: Get Upload URL for Release
id: get_release
uses: actions/github-script@v6
with:
script: |
const release = await github.rest.repos.getReleaseByTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag: '${{ env.RELEASE_VERSION }}',
})
// Write the upload URL to the environment file instead of using set-output
const fs = require('fs');
fs.appendFileSync(process.env.GITHUB_ENV, `UPLOAD_URL=${release.data.upload_url}\n`);
- name: Remove existing asset if present
run: |
@echo off
setlocal
REM List all assets in the release using curl
curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" ^
https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ env.RELEASE_VERSION }} > release_info.json
REM Extract asset ID by matching the name
for /f "delims=" %%A in ('jq -r ".assets[] | select(.name == \"Windows-installer-${{ env.RELEASE_VERSION }}.exe\") | .id" release_info.json') do set asset_id=%%A
echo The asset_id is: %asset_id%
REM Check if the asset exists and delete it
if not "%asset_id%"=="" (
curl -X DELETE ^
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" ^
https://api.github.com/repos/${{ github.repository }}/releases/assets/%asset_id%
) else (
echo Asset not found. Continue with upload...
)
endlocal
shell: cmd
- name: Upload Asset to GitHub Release
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ env.UPLOAD_URL }}
asset_path: "install_files/windows/EcoAssist-${{ env.RELEASE_VERSION }}-installer.exe"
asset_name: "Windows-installer-${{ env.RELEASE_VERSION }}.exe"
asset_content_type: application/octet-stream
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload installer EXE to Google Cloud
shell: cmd
run: |
set INSTALLER=${{ github.workspace }}/install_files/windows/EcoAssist-${{ env.RELEASE_VERSION }}-installer.exe
gsutil cp -r "%INSTALLER%" gs://${{ env.BUCKET_NAME }}/latest/windows-installer-latest.exe