Skip to content

Build Windows release #2

Build Windows release

Build Windows release #2

name: Build Windows release
on:
workflow_dispatch:
release:
types:
- published
jobs:
build-windows-release:
runs-on: windows-2022
env:
RELEASE_VERSION: ${{ github.event.release.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 --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 refresh dir
if exist "%root%" (
rmdir /s /q "%root%"
echo %root% folder removed
)
@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 --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 https://github.com/agentmorris/MegaDetector.git "%root%\cameratraps"
pushd "%root%\cameratraps"
git checkout e8a4fc19a2b9ad1892dd9ce65d437252df271576
popd
rmdir /s /q "%root%\cameratraps\.git"
echo MegaDetector cloned
@REM YOLOv5 old
git clone 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 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 --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 --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 -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 pyqt5==5.15.2 lxml
call "%conda_exe%" run -p "%root%\envs\env-base" pip install RangeSlider gpsphoto exifread piexif openpyxl pyarrow customtkinter CTkTable
call "%conda_exe%" run -p "%root%\envs\env-base" pip install GitPython==3.1.30
call "%conda_exe%" run -p "%root%\envs\env-base" pip install folium plotly
call "%conda_exe%" run -p "%root%\envs\env-base" pip install numpy==1.23.4
call "%conda_exe%" run -p "%root%\envs\env-base" pip install 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 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 ultralytics==8.0.230
call "%conda_exe%" run -p "%root%\envs\env-pytorch" pip install timm
call "%conda_exe%" run -p "%root%\envs\env-pytorch" pip install pandas
call "%conda_exe%" run -p "%root%\envs\env-pytorch" pip install numpy
call "%conda_exe%" run -p "%root%\envs\env-pytorch" pip install opencv-python
call "%conda_exe%" run -p "%root%\envs\env-pytorch" pip install pillow
call "%conda_exe%" run -p "%root%\envs\env-pytorch" pip install dill
call "%conda_exe%" run -p "%root%\envs\env-pytorch" pip install hachoir
call "%conda_exe%" run -p "%root%\envs\env-pytorch" pip install versions
call "%conda_exe%" run -p "%root%\envs\env-pytorch" pip install 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 -L -o "${{ github.workspace }}/Nsis7z_plugin.zip" "https://nsis.sourceforge.io/mediawiki/images/9/93/Nsis7z.zip"
tar -xf "${{ github.workspace }}/Nsis7z_plugin.zip"
7z x -o"${{ github.workspace }}/NSIS_Plugins" "${{ github.workspace }}/Nsis7z_plugin.zip"
- name: Install Inetc Plugin
run: |
curl -L -o "${{ github.workspace }}/Inetc_plugin.zip" "https://nsis.sourceforge.io/mediawiki/images/c/c9/Inetc.zip"
tar -xf "${{ github.workspace }}/Inetc_plugin.zip"
7z x -o"${{ github.workspace }}/NSIS_Plugins" "${{ github.workspace }}/Inetc_plugin.zip"
- 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: Upload Asset to GitHub Release
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ env.UPLOAD_URL }} # Use the updated environment variable
# asset_path: "install_files/windows/EcoAssist-${{ env.RELEASE_VERSION }}-windows.exe"
asset_path: "install_files/windows/EcoAssist-${{ env.RELEASE_VERSION }}-installer.exe"
# asset_name: "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