From 172599adcf5e1421f5681c985a021103ac61de82 Mon Sep 17 00:00:00 2001 From: Xuwznln <18435084+Xuwznln@users.noreply.github.com> Date: Sun, 12 Oct 2025 18:52:23 +0800 Subject: [PATCH] add auto install script for conda-pack-build.yml --- .github/workflows/conda-pack-build.yml | 136 +++++++++++++++++++++++-- scripts/install_unilab.bat | 136 +++++++++++++++++++++++++ scripts/install_unilab.sh | 115 +++++++++++++++++++++ 3 files changed, 380 insertions(+), 7 deletions(-) create mode 100644 scripts/install_unilab.bat create mode 100755 scripts/install_unilab.sh diff --git a/.github/workflows/conda-pack-build.yml b/.github/workflows/conda-pack-build.yml index c04e4936..ddd5b5e4 100644 --- a/.github/workflows/conda-pack-build.yml +++ b/.github/workflows/conda-pack-build.yml @@ -152,12 +152,123 @@ jobs: echo "Pack file created:" ls -lh unilab-env-${{ matrix.platform }}.tar.gz - - name: Upload packed environment + - name: Prepare distribution package (scripts + environment) + if: steps.should_build.outputs.should_build == 'true' + run: | + echo "==========================================" + echo "Creating distribution package..." + echo "Platform: ${{ matrix.platform }}" + echo "==========================================" + mkdir -p dist-package + + # Copy packed environment + echo "Adding: unilab-env-${{ matrix.platform }}.tar.gz" + cp unilab-env-${{ matrix.platform }}.tar.gz dist-package/ + + # Copy installation script (platform specific) + if [ "${{ matrix.platform }}" == "win-64" ]; then + echo "Adding: install_unilab.bat" + cp scripts/install_unilab.bat dist-package/ + else + echo "Adding: install_unilab.sh" + cp scripts/install_unilab.sh dist-package/ + chmod +x dist-package/install_unilab.sh + fi + + # Copy verification script + echo "Adding: verify_installation.py" + cp scripts/verify_installation.py dist-package/ + + # Create README + echo "Creating: README.txt" + cat > dist-package/README.txt << 'EOFREADME' + UniLabOS Conda-Pack Environment + ================================ + + This package contains a pre-built UniLabOS environment. + + Installation Instructions: + -------------------------- + + Windows: + 1. Extract unilab-pack-win-64.zip + 2. Double-click install_unilab.bat (or run in cmd) + 3. Follow the prompts + + macOS/Linux: + 1. Extract unilab-pack-{platform}.tar.gz + 2. Run: bash install_unilab.sh + 3. Follow the prompts + + The installation script will: + - Automatically find your conda installation + - Extract the environment to conda's envs/unilab directory + - Run conda-unpack to finalize setup + + After installation: + conda activate unilab + python verify_installation.py + + Package Contents: + - install_unilab script (automatic installation) + - unilab-env-{platform}.tar.gz (packed environment) + - verify_installation.py (verification tool) + - README.txt (this file) + + Branch: ${{ github.event.inputs.branch }} + Platform: ${{ matrix.platform }} + Python: 3.11.11 + Build Date: $(date -u +"%Y-%m-%d %H:%M:%S UTC") + EOFREADME + + echo "" + echo "Distribution package contents:" + ls -lh dist-package/ + echo "" + + - name: Create final distribution archive (ZIP/TAR.GZ) + if: steps.should_build.outputs.should_build == 'true' + run: | + echo "==========================================" + if [ "${{ matrix.platform }}" == "win-64" ]; then + echo "Creating Windows ZIP archive..." + echo "Archive: unilab-pack-win-64.zip" + echo "Contents: install_unilab.bat + unilab-env-win-64.tar.gz + extras" + cd dist-package + powershell -Command "Compress-Archive -Path * -DestinationPath ../unilab-pack-${{ matrix.platform }}.zip -Force" + cd .. + else + echo "Creating Unix/Linux TAR.GZ archive..." + echo "Archive: unilab-pack-${{ matrix.platform }}.tar.gz" + echo "Contents: install_unilab.sh + unilab-env-${{ matrix.platform }}.tar.gz + extras" + tar -czf unilab-pack-${{ matrix.platform }}.tar.gz -C dist-package . + fi + echo "==========================================" + + echo "" + echo "Final package created:" + ls -lh unilab-pack-* + echo "" + + if [ "${{ matrix.platform }}" == "win-64" ]; then + echo "Users can now:" + echo " 1. Download unilab-pack-win-64.zip" + echo " 2. Extract it" + echo " 3. Run install_unilab.bat" + else + echo "Users can now:" + echo " 1. Download unilab-pack-${{ matrix.platform }}.tar.gz" + echo " 2. Extract it: tar -xzf unilab-pack-${{ matrix.platform }}.tar.gz" + echo " 3. Run: bash install_unilab.sh" + fi + echo "" + + - name: Upload distribution package if: steps.should_build.outputs.should_build == 'true' uses: actions/upload-artifact@v4 with: - name: unilab-env-${{ matrix.platform }}-${{ github.event.inputs.branch }} - path: unilab-env-${{ matrix.platform }}.tar.gz + name: unilab-pack-${{ matrix.platform }}-${{ github.event.inputs.branch }} + path: unilab-pack-* retention-days: 90 if-no-files-found: error @@ -170,9 +281,20 @@ jobs: echo "Platform: ${{ matrix.platform }}" echo "Branch: ${{ github.event.inputs.branch }}" echo "Python version: 3.11.11" - echo "Package size:" - ls -lh unilab-env-${{ matrix.platform }}.tar.gz echo "" - echo "This package contains the complete unilab environment." - echo "Download and extract to use the environment." + echo "Package contents:" + if [ "${{ matrix.platform }}" == "win-64" ]; then + echo " - unilab-pack-${{ matrix.platform }}.zip" + else + echo " - unilab-pack-${{ matrix.platform }}.tar.gz" + fi + echo " - unilab-env-${{ matrix.platform }}.tar.gz (packed environment)" + echo " - install_unilab script" + echo " - verify_installation.py" + echo " - README.txt" + echo "" + echo "Package size:" + ls -lh unilab-pack-* 2>/dev/null || ls -lh unilab-env-${{ matrix.platform }}.tar.gz + echo "" + echo "Download the artifact and run the install script!" echo "==========================================" diff --git a/scripts/install_unilab.bat b/scripts/install_unilab.bat new file mode 100644 index 00000000..993f8374 --- /dev/null +++ b/scripts/install_unilab.bat @@ -0,0 +1,136 @@ +@echo off +setlocal enabledelayedexpansion + +echo ================================================ +echo UniLabOS Environment Installation Script +echo ================================================ +echo. + +REM Get the directory where this script is located +set "SCRIPT_DIR=%~dp0" +cd /d "%SCRIPT_DIR%" + +REM Find conda installation using 'where conda' +echo Searching for conda installation... +for /f "tokens=*" %%i in ('where conda 2^>nul') do ( + set "CONDA_PATH=%%i" + goto :found_conda +) + +echo ERROR: Could not find conda installation! +echo Please make sure conda/mamba is installed and in your PATH. +echo. +pause +exit /b 1 + +:found_conda +REM Extract base directory from conda path +REM Path looks like: C:\Users\10230\miniforge3\Library\bin\conda.bat +REM or: C:\Users\10230\miniforge3\Scripts\conda.exe +for %%i in ("%CONDA_PATH%") do set "CONDA_FILE=%%~nxi" +for %%i in ("%CONDA_PATH%") do set "CONDA_BASE=%%~dpi" + +REM Go up two levels to get base directory +for %%i in ("%CONDA_BASE%..") do set "CONDA_BASE=%%~fi" +if "%CONDA_FILE%"=="conda.bat" ( + for %%i in ("%CONDA_BASE%..") do set "CONDA_BASE=%%~fi" +) + +echo Found conda at: %CONDA_BASE% +echo. + +REM Set target environment path +set "ENV_NAME=unilab" +set "ENV_PATH=%CONDA_BASE%\envs\%ENV_NAME%" + +REM Check if environment already exists +if exist "%ENV_PATH%" ( + echo WARNING: Environment '%ENV_NAME%' already exists at %ENV_PATH% + echo. + set /p "OVERWRITE=Do you want to overwrite it? (y/n): " + if /i not "!OVERWRITE!"=="y" ( + echo Installation cancelled. + pause + exit /b 0 + ) + echo Removing existing environment... + rmdir /s /q "%ENV_PATH%" +) + +REM Find the packed environment file +set "PACK_FILE=" +for %%f in (unilab-env*.tar.gz) do ( + set "PACK_FILE=%%f" + goto :found_pack +) + +:found_pack +if "%PACK_FILE%"=="" ( + echo ERROR: Could not find unilab-env*.tar.gz file! + echo Please make sure the packed environment file is in the same directory as this script. + echo. + pause + exit /b 1 +) + +echo Found packed environment: %PACK_FILE% +echo. + +REM Extract the packed environment +echo Extracting environment to %ENV_PATH%... +mkdir "%ENV_PATH%" + +REM Extract using tar (available in Windows 10+) +tar -xzf "%PACK_FILE%" -C "%ENV_PATH%" +if errorlevel 1 ( + echo ERROR: Failed to extract environment! + echo Make sure you have Windows 10 or later with tar support. + pause + exit /b 1 +) + +echo. +echo Unpacking conda environment... +echo Changing to environment directory: %ENV_PATH% +cd /d "%ENV_PATH%" + +REM Run conda-unpack from the environment directory +if exist "Scripts\conda-unpack.exe" ( + echo Running: .\Scripts\conda-unpack.exe + .\Scripts\conda-unpack.exe +) else if exist "Scripts\activate.bat" ( + echo Running: .\Scripts\activate.bat followed by conda-unpack + call .\Scripts\activate.bat + conda-unpack +) else ( + echo ERROR: Could not find Scripts\conda-unpack.exe or Scripts\activate.bat! + echo Current directory: %CD% + echo Expected location: %ENV_PATH%\Scripts\ + pause + exit /b 1 +) + +if errorlevel 1 ( + echo ERROR: conda-unpack failed! + pause + exit /b 1 +) + +echo. +echo ================================================ +echo Installation completed successfully! +echo ================================================ +echo. +echo To activate the environment, run: +echo conda activate %ENV_NAME% +echo. +echo or +echo. +echo call %ENV_PATH%\Scripts\activate.bat +echo. +echo You can verify the installation by running: +echo cd /d "%SCRIPT_DIR%" +echo python verify_installation.py +echo. +pause + diff --git a/scripts/install_unilab.sh b/scripts/install_unilab.sh new file mode 100755 index 00000000..b12d972e --- /dev/null +++ b/scripts/install_unilab.sh @@ -0,0 +1,115 @@ +#!/bin/bash +set -e + +echo "================================================" +echo "UniLabOS Environment Installation Script" +echo "================================================" +echo "" + +# Get the directory where this script is located +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +cd "$SCRIPT_DIR" + +# Find conda installation +echo "Searching for conda installation..." +CONDA_BASE="" + +# Try to find conda in PATH +if command -v conda &> /dev/null; then + CONDA_BASE=$(conda info --base) + echo "Found conda at: $CONDA_BASE" +elif [ -d "$HOME/miniforge3" ]; then + CONDA_BASE="$HOME/miniforge3" + echo "Found conda at: $CONDA_BASE" +elif [ -d "$HOME/miniconda3" ]; then + CONDA_BASE="$HOME/miniconda3" + echo "Found conda at: $CONDA_BASE" +elif [ -d "$HOME/anaconda3" ]; then + CONDA_BASE="$HOME/anaconda3" + echo "Found conda at: $CONDA_BASE" +elif [ -d "/opt/conda" ]; then + CONDA_BASE="/opt/conda" + echo "Found conda at: $CONDA_BASE" +else + echo "ERROR: Could not find conda installation!" + echo "Please make sure conda/mamba is installed." + exit 1 +fi + +echo "" + +# Initialize conda for this shell +if [ -f "$CONDA_BASE/etc/profile.d/conda.sh" ]; then + source "$CONDA_BASE/etc/profile.d/conda.sh" +fi + +# Set target environment path +ENV_NAME="unilab" +ENV_PATH="$CONDA_BASE/envs/$ENV_NAME" + +# Check if environment already exists +if [ -d "$ENV_PATH" ]; then + echo "WARNING: Environment '$ENV_NAME' already exists at $ENV_PATH" + read -p "Do you want to overwrite it? (y/n): " OVERWRITE + if [ "$OVERWRITE" != "y" ] && [ "$OVERWRITE" != "Y" ]; then + echo "Installation cancelled." + exit 0 + fi + echo "Removing existing environment..." + rm -rf "$ENV_PATH" +fi + +# Find the packed environment file +PACK_FILE=$(ls unilab-env*.tar.gz 2>/dev/null | head -n 1) + +if [ -z "$PACK_FILE" ]; then + echo "ERROR: Could not find unilab-env*.tar.gz file!" + echo "Please make sure the packed environment file is in the same directory as this script." + exit 1 +fi + +echo "Found packed environment: $PACK_FILE" +echo "" + +# Extract the packed environment +echo "Extracting environment to $ENV_PATH..." +mkdir -p "$ENV_PATH" +tar -xzf "$PACK_FILE" -C "$ENV_PATH" + +echo "" +echo "Unpacking conda environment..." +echo "Changing to environment directory: $ENV_PATH" +cd "$ENV_PATH" + +# Run conda-unpack from the environment directory +if [ -f "bin/conda-unpack" ]; then + echo "Running: ./bin/conda-unpack" + ./bin/conda-unpack +elif [ -f "bin/activate" ]; then + echo "Running: source bin/activate followed by conda-unpack" + source bin/activate + conda-unpack +else + echo "ERROR: Could not find bin/conda-unpack or bin/activate!" + echo "Current directory: $(pwd)" + echo "Expected location: $ENV_PATH/bin/" + exit 1 +fi + +echo "" +echo "================================================" +echo "Installation completed successfully!" +echo "================================================" +echo "" +echo "To activate the environment, run:" +echo " conda activate $ENV_NAME" +echo "" +echo "or" +echo "" +echo " source $ENV_PATH/bin/activate" +echo "" +echo "You can verify the installation by running:" +echo " cd $SCRIPT_DIR" +echo " python verify_installation.py" +echo "" +