Skip to content

Commit

Permalink
add installer script
Browse files Browse the repository at this point in the history
  • Loading branch information
paulhfu committed Jul 30, 2023
1 parent b394c99 commit 11fd2ce
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 0 deletions.
91 changes: 91 additions & 0 deletions .github/workflows/build_installers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: build_installers

on:
push:
tags:
- '**'
branches:
- '*'

jobs:
build_intaller:
name: ${{ matrix.os }}
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]

env:
PREPARE_SCRIPT: |
cd deployment
conda install -y -c conda-forge constructor
conda install -y -c conda-forge ruamel.yaml
conda install -y -c conda-forge mamba
mamba env create --file=env.yaml
RUN_SCRIPT: |
python version_getter.py
mkdir ./${{ matrix.os }}_x86_64
constructor --output-dir ./${{ matrix.os }}_x86_64 .
steps:
- name: checkout
uses: actions/checkout@v3

- name: setup conda
if: matrix.os == 'windows-latest' || matrix.os == 'ubuntu-latest'
uses: conda-incubator/setup-miniconda@v2
with:
miniconda-version: "latest"
auto-activate-base: true
activate-environment: ""
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true

- name: build ${{ matrix.os }}_x86_64
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
${{ env.PREPARE_SCRIPT }}
conda activate __MICROSAM_BUILD_ENV__
conda install -c anaconda menuinst
python windows_menu_setup.py
conda activate base
${{ env.RUN_SCRIPT }}
- name: build ${{ matrix.os }}_x86_64
if: matrix.os == 'ubuntu-latest'
shell: bash -el {0}
run: |
${{ env.PREPARE_SCRIPT }}
${{ env.RUN_SCRIPT }}
- name: build ${{ matrix.os }}_x86_64_step1
if: matrix.os == 'macos-latest'
shell: bash -el {0}
run: |
brew install micromamba
/usr/local/opt/micromamba/bin/micromamba shell init -s bash -p ~/micromamba
- name: build ${{ matrix.os }}_x86_64_step2
if: matrix.os == 'macos-latest'
shell: bash -el {0}
run: |
cd deployment
micromamba activate base
micromamba install -y -c conda-forge python=3.10
micromamba install -y -c conda-forge constructor
micromamba install -y -c conda-forge ruamel.yaml
micromamba install -y -c conda-forge mamba
mamba env create --file=env.yaml
python version_getter.py
mkdir ./${{ matrix.os }}_x86_64
constructor --conda-exe=$(which mamba) --output-dir ./${{ matrix.os }}_x86_64 .
- name: upload installer
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.os }}_x86_64
path: ./deployment/${{ matrix.os }}_x86_64
retention-days: 5
15 changes: 15 additions & 0 deletions deployment/construct.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: micro_sam
version: 0.1.0
license_file: ../LICENSE
installer_type: pkg #[osx] # This will trigger pkg build on Mac Os. On windows and linux, native build will be done and this has no effect.
environment: __MICROSAM_BUILD_ENV__
welcome_image: ../doc/images/micro-sam-logo.png
header_image: ../doc/images/micro-sam-logo.png
icon_image: ../doc/images/micro-sam-logo.png
channels:
- conda-forge
welcome_text: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua.
conclusion_text: Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat.
initialize_by_default: true
9 changes: 9 additions & 0 deletions deployment/env.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: __MICROSAM_BUILD_ENV__
channels:
- conda-forge
dependencies:
- napari
- pyqt
- pytorch::pytorch
- pytorch::torchvision
- micro_sam
15 changes: 15 additions & 0 deletions deployment/version_getter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import runpy
import ruamel.yaml
import os

yaml = ruamel.yaml.YAML()
yaml.preserve_quotes = True
ctor_fname = os.path.join("construct.yaml")

with open(ctor_fname, 'r') as stream:
ctor_conf = yaml.load(stream)

ctor_conf["version"] = runpy.run_path(os.path.join("..", "micro_sam", "__version__.py"))["__version__"]

with open(ctor_fname, 'w') as outfile:
yaml.dump(ctor_conf, outfile)
14 changes: 14 additions & 0 deletions deployment/windows_menu.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"menu_name": "micro_sam",
"menu_items":
[
{
"script": "${PREFIX}/Scripts/micro_sam.annotator.exe",
"name": "micro_sam",
"icon": "${PREFIX}/Menu/micro-sam-logo.ico",
"workdir": "${PREFIX}",
"desktop": true,
"quicklaunch": true
}
]
}
10 changes: 10 additions & 0 deletions deployment/windows_menu_setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import menuinst
import shutil
import os

conda_dir = os.environ["CONDA_PREFIX"]
menu_dir = os.path.join(conda_dir, "Menu")
os.makedirs(menu_dir, exist_ok = True)
shutil.copy("../doc/images/micro-sam-logo.ico", menu_dir)
shutil.copy("./windows_menu.json", menu_dir)
menuinst.install(os.path.join(menu_dir, 'windows_menu.json'), prefix=conda_dir)
Binary file added doc/images/micro-sam-logo.ico
Binary file not shown.

0 comments on commit 11fd2ce

Please sign in to comment.