-
-
Notifications
You must be signed in to change notification settings - Fork 17
287 lines (237 loc) · 13.4 KB
/
build-macos-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
name: Build macOS release
on:
workflow_dispatch:
release:
types:
- published
jobs:
build-macos-release:
runs-on: macos-15
env:
RELEASE_VERSION: ${{ github.event.release.tag_name }}
BUCKET_NAME: github-release-files-storage
steps:
- name: Checkout repository
uses: actions/checkout@v3
# - name: Debug dependencies
# run: |
# root="$HOME/EcoAssist"
# mkdir -p "${root}"
# git clone --depth 1 https://github.com/PetervanLunteren/visualise_detection.git "${root}/visualise_detection"
- name: Install Miniconda
run: |
mkdir "$HOME/miniforge"
curl -L "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-MacOSX-arm64.sh" -o miniforge.sh
bash miniforge.sh -b -u -p "$HOME/miniforge"
echo "succesfully installed at $HOME/miniforge"
- name: Install dependencies
run: |
### refresh root
root="$HOME/EcoAssist_files"
if [ -d "${root}" ]; then
rm -rf "${root}"
echo "$root folder removed"
else
echo "$root folder does not exist"
fi
### create folder structure
mkdir -p "${root}"
mkdir -p "${root}/envs"
mkdir -p "${root}/models"
mkdir -p "${root}/models/det"
mkdir -p "${root}/models/cls"
mkdir -p "${root}/models/det/MegaDetector 5a"
mkdir -p "${root}/yolov5_versions/yolov5_old"
mkdir -p "${root}/yolov5_versions/yolov5_new"
echo "Hello world!" >> "${root}/first-startup.txt"
## clone repositories
git clone --depth 1 https://github.com/PetervanLunteren/EcoAssist.git "${root}/EcoAssist"
rm -rf "${root}/EcoAssist/.git"
mv "${root}/EcoAssist/main.py" "${root}/main.py"
RAW_VERSION=${{ env.RELEASE_VERSION }}
CLEAN_VERSION="${RAW_VERSION#v}"
echo "$CLEAN_VERSION" > "${root}/EcoAssist/version.txt"
echo "EcoAssist cloned"
git clone https://github.com/agentmorris/MegaDetector.git "${root}/MegaDetector"
git -C "${root}/MegaDetector" checkout e8a4fc19a2b9ad1892dd9ce65d437252df271576
rm -rf "${root}/MegaDetector/.git"
mv "${root}/MegaDetector" "${root}/cameratraps"
echo "MegaDetector cloned"
git clone https://github.com/ultralytics/yolov5.git "${root}/yolov5_versions/yolov5_old/yolov5"
git -C "${root}/yolov5_versions/yolov5_old/yolov5" checkout 868c0e9bbb45b031e7bfd73c6d3983bcce07b9c1
rm -rf "${root}/yolov5_versions/yolov5_old/yolov5/.git"
echo "yolov5 old version cloned"
git clone https://github.com/ultralytics/yolov5.git "${root}/yolov5_versions/yolov5_new/yolov5"
git -C "${root}/yolov5_versions/yolov5_new/yolov5" checkout 3e55763d45f9c5f8217e4dad5ba1e6c1f42e3bf8
rm -rf "${root}/yolov5_versions/yolov5_new/yolov5/.git"
echo "yolov5 new version cloned"
git clone --branch pyside6 --depth 1 https://github.com/PetervanLunteren/Human-in-the-loop.git "${root}/Human-in-the-loop"
rm -rf "${root}/Human-in-the-loop/.git"
echo "Human-in-the-loop cloned"
git clone --depth 1 https://github.com/PetervanLunteren/visualise_detection.git "${root}/visualise_detection"
rm -rf "${root}/visualise_detection/.git"
echo "visualise_detection cloned"
### download megadetector
curl -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"
### source conda
source "$HOME/miniforge/etc/profile.d/conda.sh"
source "$HOME/miniforge/bin/activate"
conda_exe="$HOME/miniforge/bin/conda"
### install mamba
$conda_exe install mamba -n base -c conda-forge -y
conda_exe="$HOME/miniforge/bin/mamba"
### install env-base
$conda_exe env create --file="${root}/cameratraps/envs/environment-detector-m1.yml" -p "${root}/envs/env-base"
$conda_exe run -p "${root}/envs/env-base" conda install pytorch==1.13.1 torchvision==0.14.1 -c pytorch -y
$conda_exe run -p "${root}/envs/env-base" conda uninstall opencv -y
$conda_exe run -p "${root}/envs/env-base" pip install opencv-python
$conda_exe run -p "${root}/envs/env-base" pip install RangeSlider
$conda_exe run -p "${root}/envs/env-base" pip install gpsphoto
$conda_exe run -p "${root}/envs/env-base" pip install exifread
$conda_exe run -p "${root}/envs/env-base" pip install piexif
$conda_exe run -p "${root}/envs/env-base" pip install openpyxl
$conda_exe run -p "${root}/envs/env-base" pip install customtkinter
$conda_exe run -p "${root}/envs/env-base" pip install CTkTable
$conda_exe run -p "${root}/envs/env-base" pip install folium
$conda_exe run -p "${root}/envs/env-base" pip install plotly
$conda_exe run -p "${root}/envs/env-base" pip install "gitpython>=3.1.30"
$conda_exe run -p "${root}/envs/env-base" pip install "tensorboard>=2.4.1"
$conda_exe run -p "${root}/envs/env-base" pip install "thop>=0.1.1"
$conda_exe run -p "${root}/envs/env-base" pip install "protobuf<=3.20.1"
$conda_exe run -p "${root}/envs/env-base" pip install "setuptools>=65.5.1"
$conda_exe run -p "${root}/envs/env-base" pip install PySide6
$conda_exe run -p "${root}/envs/env-base" conda install lxml -y
"${root}/envs/env-base/bin/pyside6-rcc" -o "${root}/Human-in-the-loop/libs/resources.py" "${root}/Human-in-the-loop/resources.qrc"
### install env-tensorflow
$conda_exe env create --file="${root}/EcoAssist/classification_utils/envs/tensorflow-macos-silicon.yml" -p "${root}/envs/env-tensorflow"
### install env-pytorch
$conda_exe create -p "${root}/envs/env-pytorch" python=3.8 -y
$conda_exe run -p "${root}/envs/env-pytorch" pip install torch==2.0.1 torchvision==0.15.2
$conda_exe run -p "${root}/envs/env-pytorch" pip install "ultralytics==8.0.191"
$conda_exe run -p "${root}/envs/env-pytorch" pip install "numpy==1.24.1"
$conda_exe run -p "${root}/envs/env-pytorch" pip install "humanfriendly==10.0"
$conda_exe run -p "${root}/envs/env-pytorch" pip install "jsonpickle==3.0.2"
$conda_exe run -p "${root}/envs/env-pytorch" pip install timm
$conda_exe run -p "${root}/envs/env-pytorch" pip install dill
### install env-pywildlife
$conda_exe create -p "${root}/envs/env-pywildlife" python=3.8 -y
$conda_exe run -p "${root}/envs/env-pywildlife" pip install pytorchwildlife
$conda_exe run -p "${root}/envs/env-pywildlife" pip install "setuptools<70"
$conda_exe run -p "${root}/envs/env-pywildlife" pip install jsonpickle
### run pyinstaller from fresh environment
$conda_exe create -p "$HOME/miniforge/envs/env-fresh" python=3.8 pyinstaller -y
$conda_exe run -p "$HOME/miniforge/envs/env-fresh" pyinstaller --onefile --windowed --icon="${root}/EcoAssist/imgs/logo_small_bg.icns" --distpath="${HOME}/dist" --workpath="${HOME}/build" "${root}/main.py"
### clean
$conda_exe clean --all --yes --force-pkgs-dirs
$conda_exe clean --all --yes
### move and rename executables
# cp "${HOME}/dist/main" "${root}/EcoAssist ${RELEASE_VERSION} installer" # installer executable
mv "${HOME}/dist/main" "${root}/EcoAssist ${RELEASE_VERSION} debug" # debug executable
mv "${HOME}/dist/main.app" "${root}/EcoAssist ${RELEASE_VERSION}.app" # main app executable
- name: Zip folder contents
run: |
cd "$HOME"
tar -caf "macos-${{ env.RELEASE_VERSION }}.tar.xz" EcoAssist_files
# - name: Upload files to Google Cloud
# run: |
# cd "$HOME"
# # init vars
# BUCKET_NAME="${{ env.BUCKET_NAME }}"
# PINNED_FOLDER_NAME="${{ env.RELEASE_VERSION }}"
# LATEST_FOLDER_NAME="latest"
# PINNED_FILE_NAME="macos-${{ env.RELEASE_VERSION }}.tar.xz"
# LATEST_FILE_NAME="macos-latest.tar.xz"
# # upload release pinned version
# gsutil cp -r $PINNED_FILE_NAME gs://$BUCKET_NAME/$PINNED_FOLDER_NAME/$PINNED_FILE_NAME
# - name: Get the release body
# id: get_release
# run: |
# release=$(gh release view ${{ github.ref_name }} --json body -q .body)
# echo "$release" > release_body.txt
# - name: Append link to release body
# id: append_link
# run: |
# new_body="$(cat release_body.txt)
# - Install for **macOS** (Apple Silicon - M1, M2, M3, etc.): [macos-${{ env.RELEASE_VERSION }}.tar.xz](https://storage.googleapis.com/${{ env.BUCKET_NAME }}/${{ env.RELEASE_VERSION }}/macos-${{ env.RELEASE_VERSION }}.tar.xz)"
# echo "$new_body" > new_release_body.txt
# - name: Update the release body
# run: |
# gh release edit ${{ github.ref_name }} --notes "$(cat new_release_body.txt)"
- name: Install Platypus
run: |
# copy files into the right directory
sudo mkdir -p '/usr/local/share/platypus/'
sudo cp "${{ github.workspace }}/install_files/macos/ScriptExec" '/usr/local/share/platypus/'
sudo cp "${{ github.workspace }}/install_files/macos/platypus_clt" '/usr/local/share/platypus/'
sudo cp -r "${{ github.workspace }}/install_files/macos/MainMenu.nib" '/usr/local/share/platypus/'
# make executable
sudo chmod +x '/usr/local/share/platypus/ScriptExec'
sudo chmod +x '/usr/local/share/platypus/platypus_clt'
- name: Append VERSION to Platypus Installer Script
shell: bash
run: |
# Define the file path
FILE_PATH="${{ github.workspace }}/install_files/macos/platypus-install-compiler.sh"
# Create a new file with the VERSION line
echo "VERSION=\"${{ env.RELEASE_VERSION }}\"" > newFile.sh
# Append the original file's content
cat "$FILE_PATH" >> newFile.sh
# Replace the original file with the new file
mv newFile.sh "$FILE_PATH"
- name: Create Installer
run: |
sudo '/usr/local/share/platypus/platypus_clt' --app-icon '${{ github.workspace }}/install_files/macos/logo.icns' --name 'EcoAssist-${{ env.RELEASE_VERSION }}-installer' --interface-type 'Progress Bar' --interpreter '/bin/bash' --app-version '${{ env.RELEASE_VERSION }}' '${{ github.workspace }}/install_files/macos/platypus-install-compiler.sh'
- name: Compress the macOS installer
run: |
cd "${{ github.workspace }}/install_files/macos"
zip -r "EcoAssist-${{ env.RELEASE_VERSION }}-installer.zip" "EcoAssist-${{ env.RELEASE_VERSION }}-installer.app"
- name: Get Upload URL for Release
id: get_upload_url
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
const fs = require('fs');
fs.appendFileSync(process.env.GITHUB_ENV, `UPLOAD_URL=${release.data.upload_url}\n`);
- name: Authenticate GitHub CLI
run: echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token
- name: Upload Asset to GitHub Release
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ env.UPLOAD_URL }}
asset_path: "${{ github.workspace }}/install_files/macos/EcoAssist-${{ env.RELEASE_VERSION }}-installer.zip"
asset_name: "MacOS-installer-${{ env.RELEASE_VERSION }}.zip"
asset_content_type: application/octet-stream
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- 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 program files to Google Cloud
run: |
cd "$HOME"
# init vars
BUCKET_NAME="${{ env.BUCKET_NAME }}"
PINNED_FOLDER_NAME="${{ env.RELEASE_VERSION }}"
LATEST_FOLDER_NAME="latest"
PINNED_FILE_NAME="macos-${{ env.RELEASE_VERSION }}.tar.xz"
LATEST_FILE_NAME="macos-latest.tar.xz"
# upload release pinned version
gsutil cp -r $PINNED_FILE_NAME gs://$BUCKET_NAME/$PINNED_FOLDER_NAME/$PINNED_FILE_NAME
# upload latest release version
gsutil cp -r $PINNED_FILE_NAME gs://$BUCKET_NAME/$LATEST_FOLDER_NAME/$LATEST_FILE_NAME
- name: Upload installer to Google Cloud
run: |
cd "${{ github.workspace }}/install_files/macos/"
INSTALLER="EcoAssist-${{ env.RELEASE_VERSION }}-installer.zip"
gsutil cp -r $INSTALLER gs://${{ env.BUCKET_NAME }}/latest/EcoAssist-latest-installer.zip