Manual Release #60
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: 'Manual Release' | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| release_name: | |
| description: 'Release title' | |
| required: true | |
| release_type: | |
| description: 'Type of release (draft, private, public)' | |
| required: true | |
| default: 'draft' | |
| release_notes: | |
| description: 'Release notes' | |
| required: false | |
| # permissions: | |
| # # Give the default GITHUB_TOKEN write permission to commit and push the | |
| # # added or changed files to the repository. | |
| # contents: write | |
| jobs: | |
| build: | |
| name: Build for ${{ matrix.os }} | |
| # needs: create_release | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| os: [windows-latest] # builds for each platform, in seperate vm's, in this order | |
| continue-on-error: true | |
| steps: | |
| # 1. Pull down repo | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Fetch all history for proper Git submodule initialization | |
| ref: ${{ github.event.inputs.ref || github.ref }} # checks out code you specify in github UI | |
| # Only needed if we are building llama.cpp from source | |
| # - name: Install CUDA Toolkit (Windows) | |
| # uses: Jimver/cuda-toolkit@master | |
| # if: startsWith(runner.os, 'Windows') | |
| # id: cuda-toolkit | |
| # 2. Install Python | |
| - name: Install Python | |
| id: setup_python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.12' | |
| # cache: 'pip' # caches the downloaded package installers only, if you cache the venv then disabling this will save about 20s | |
| # 3. Load the cached python virtual environment | |
| - name: Restore cached venv | |
| id: restore-cache | |
| uses: actions/cache/restore@v4 | |
| with: | |
| key: venv-${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ hashFiles('requirements.release.txt') }} | |
| path: .venv | |
| # 4. Create virtual environment, Install package manager and dependencies for Python | |
| - name: Setup venv (install deps) | |
| shell: bash | |
| if: runner.os == 'Windows' | |
| run: | | |
| python -m venv .venv # noop if cache is found | |
| .venv/Scripts/activate | |
| .venv/Scripts/python -m pip list # Verify installed packages | |
| # Install pip and Python deps | |
| .venv/Scripts/python --version | |
| .venv/Scripts/python -m pip install --upgrade pip setuptools wheel # upgrades pip to latest | |
| .venv/Scripts/python -m pip install -r requirements.release.txt # install deps, use --prefer-binary to install from wheels instead of source | |
| # 5. Cache python virtual environment for later runs | |
| - name: Save cached venv | |
| uses: actions/cache/save@v4 | |
| with: | |
| key: venv-${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ hashFiles('requirements.release.txt') }} | |
| path: .venv | |
| # - name: List contents of GitHub workspace | |
| # shell: bash | |
| # run: | | |
| # echo "Contents of the GitHub workspace directory:" | |
| # ls -al "${{ github.workspace }}" | |
| # echo ".venv/lib/site-packages" | |
| # ls -al .venv/lib/site-packages | |
| # echo "Contents of the Python directory:" | |
| # ls -al "${{ env.pythonLocation }}" | |
| # Download and install UPX | |
| # - name: Download and install UPX (Windows) | |
| # shell: bash | |
| # if: runner.os == 'Windows' | |
| # run: | | |
| # curl -L https://github.com/upx/upx/releases/download/v4.0.2/upx-4.0.2-win64.zip -o upx.zip | |
| # # Use unzip to extract the zip file | |
| # unzip upx.zip -d C:/upx | |
| # echo "C:/upx/upx-4.0.2-win64" >> $GITHUB_PATH | |
| # 6. Build the app .exe (pyinstaller) | |
| - name: Build app | |
| shell: bash | |
| env: | |
| PATH: .venv/Scripts | |
| run: | | |
| # Must activate env before each step | |
| # `env.pythonLocation` should be used if no venv | |
| # For Windows | |
| if [ $RUNNER_OS == 'Windows' ]; then | |
| .venv/Scripts/activate | |
| # For Linux/macOS | |
| else | |
| source .venv/bin/activate | |
| fi | |
| # PyInstaller will output to "build/Obrew-Server" folder in root | --upx-dir C:/upx/upx-4.0.2-win64 \ | |
| pyinstaller --noconfirm --clean --onedir --windowed \ | |
| --log-level DEBUG \ | |
| --contents-directory _deps \ | |
| --icon "${{ github.workspace }}/backends/ui/favicon.ico" \ | |
| --name "Obrew-Server" \ | |
| --hidden-import "tiktoken_ext.openai_public" \ | |
| --hidden-import "tiktoken_ext" \ | |
| --add-data "${{ github.workspace }}/public:public/" \ | |
| --add-data "${{ github.workspace }}/backends/ui/public:public/" \ | |
| --add-data .venv/lib/site-packages/posthog:posthog/ \ | |
| --add-data .venv/lib/site-packages/chromadb:chromadb/ \ | |
| --add-data .venv/lib/site-packages/importlib_resources:importlib_resources/ \ | |
| --add-data .venv/lib/site-packages/backoff:backoff/ \ | |
| --add-data .venv/lib/site-packages/pypika:pypika/ \ | |
| --add-data .venv/lib/site-packages/hnswlib.cp312-win_amd64.pyd:. \ | |
| --add-data "${{ github.workspace }}/.env.example:.env" \ | |
| --add-data "${{ github.workspace }}/tools/functions:tools/functions/" \ | |
| "${{ github.workspace }}/backends/main.py" | |
| # Create a "servers" dir to be included in installer | |
| mkdir -p dist/Obrew-Server/_deps/servers | |
| # Debug | |
| echo "Workspace directory:" | |
| ls -al "${{ github.workspace }}" | |
| echo "Build directory:" | |
| ls -al build/Obrew-Server | |
| echo "Dist directory:" | |
| ls -al dist/Obrew-Server | |
| # 7a. Package with Inno-Setup (Windows) | |
| - name: Create Installer (Inno-Setup) | |
| uses: Minionguyjpro/[email protected] | |
| if: runner.os == 'Windows' | |
| with: | |
| path: ${{ github.workspace }}/inno-setup-config-github.iss | |
| options: /O+ | |
| # 7b. Package with CMake/CPack (macOS/Linux) | |
| - name: Install CMake | |
| uses: lukka/get-cmake@latest | |
| if: runner.os != 'Windows' | |
| with: | |
| cmakeVersion: latest | |
| - name: Configure CMake | |
| shell: bash | |
| if: runner.os != 'Windows' | |
| run: | | |
| echo "Listing files in the GitHub workspace: ${{ github.workspace }}" | |
| cmake -S "${{ github.workspace }}" -B build_temp -D CMAKE_INSTALL_PREFIX="${{ github.workspace }}/dist/Obrew-Server" | |
| - name: Build Project (CMake) | |
| shell: bash | |
| if: runner.os != 'Windows' | |
| run: cmake --build build_temp | |
| - name: Create Installer (CPack) | |
| shell: bash | |
| if: runner.os != 'Windows' | |
| run: | | |
| cmake --build build_temp --target package --config Release | |
| ls -la "${{ github.workspace }}/output" | |
| # 9. Zip all package files/folders in /build and put in /artifacts/windows-latest/ | |
| - name: Zip assets (Windows) | |
| shell: pwsh | |
| if: runner.os == 'Windows' | |
| # Ensure the output directory matches the OutputDir of CPack | |
| run: | | |
| mkdir -p ./artifacts/windows-latest | |
| ls -la "${{ github.workspace }}/output" | |
| Compress-Archive -Path "output/*.*" -DestinationPath ./artifacts/windows-latest/windows-latest-artifacts.zip | |
| # 10. Upload Installer Artifact | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v3 | |
| with: | |
| name: ${{ matrix.os }}-artifact | |
| path: ./artifacts/${{ matrix.os }}/${{ matrix.os }}-artifacts.zip # upload from | |
| # Assumes you created a git tag already | |
| create_release: | |
| name: Create GitHub Release | |
| needs: [build] | |
| runs-on: ubuntu-latest | |
| if: ${{ success() }} | |
| outputs: | |
| release_upload_url: ${{ steps.create_release.outputs.upload_url }} | |
| steps: | |
| - name: Create a release | |
| id: create_release | |
| uses: actions/create-release@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| tag_name: ${{ github.event.inputs.ref || github.ref_name }} | |
| release_name: ${{ github.event.inputs.release_name }} | |
| body: ${{ github.event.inputs.release_notes }} | |
| draft: ${{ github.event.inputs.release_type == 'draft' }} # not visible to the public | |
| prerelease: ${{ github.event.inputs.release_type == 'private' }} # visible only to collaborators | |
| upload_assets: | |
| name: Upload Assets to Release | |
| needs: [build, create_release] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Download Windows artifact | |
| if: always() | |
| uses: actions/download-artifact@v3 | |
| with: | |
| name: windows-latest-artifact | |
| path: ./artifacts/windows | |
| - name: Upload Windows asset archive | |
| if: always() | |
| uses: actions/upload-release-asset@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| upload_url: ${{ needs.create_release.outputs.release_upload_url }} | |
| asset_path: ./artifacts/windows/windows-latest-artifacts.zip # file location | |
| asset_name: ObrewServer.WIN.Setup.zip # display name on release page (not file name) | |
| asset_content_type: application/zip |