|
| 1 | +name: Linux Build/Release (Python 3.10) |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - '*' |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + build-and-release: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + |
| 15 | + container: |
| 16 | + image: python:3.10-slim-bullseye |
| 17 | + |
| 18 | + steps: |
| 19 | + - name: Set PLATFORM Environment Variable |
| 20 | + run: echo "PLATFORM=linux" >> $GITHUB_ENV |
| 21 | + |
| 22 | + - name: Install Additional Dependencies |
| 23 | + run: | |
| 24 | + apt-get update |
| 25 | + apt-get install -y git zip bash build-essential cmake ninja-build g++ |
| 26 | +
|
| 27 | + - name: Install GitHub CLI |
| 28 | + run: | |
| 29 | + type -p wget >/dev/null || (apt-get update && apt-get install wget -y) |
| 30 | + mkdir -p -m 755 /etc/apt/keyrings |
| 31 | + wget -qO- https://cli.github.com/packages/githubcli-archive-keyring.gpg | tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null |
| 32 | + chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg |
| 33 | + echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null |
| 34 | + apt-get update |
| 35 | + apt-get install gh -y |
| 36 | +
|
| 37 | + - name: Mark repository as safe for Git |
| 38 | + run: | |
| 39 | + git config --global --add safe.directory /__w/EnvironmentLodTools/EnvironmentLodTools |
| 40 | +
|
| 41 | + - name: Check out code with submodules |
| 42 | + uses: actions/checkout@v4 |
| 43 | + with: |
| 44 | + submodules: true |
| 45 | + |
| 46 | + - name: Initialize and Update Git Submodules |
| 47 | + run: | |
| 48 | + git submodule update --init --recursive |
| 49 | +
|
| 50 | + - name: Set up Python Virtual Environment and Install Python Dependencies |
| 51 | + run: | |
| 52 | + python3 -m venv venv |
| 53 | + . venv/bin/activate |
| 54 | + if [ -f "requirements.txt" ]; then |
| 55 | + pip install --upgrade pip |
| 56 | + pip install --upgrade setuptools |
| 57 | + pip install --upgrade wheel |
| 58 | + pip install pybind11 |
| 59 | + pip install build |
| 60 | + pip install -r requirements.txt |
| 61 | + fi |
| 62 | +
|
| 63 | + - name: Get Blender Version from Installed Module |
| 64 | + id: get_blender_version |
| 65 | + run: | |
| 66 | + . venv/bin/activate |
| 67 | + if pip show bpy > /dev/null 2>&1; then |
| 68 | + BLENDER_VERSION=$(pip show bpy | grep -Po '(?<=Version: )\d+(\.\d+)+') |
| 69 | + echo "BLENDER_VERSION=$BLENDER_VERSION" >> $GITHUB_ENV |
| 70 | + else |
| 71 | + echo "bpy module not found in the virtual environment. Please ensure it is installed." |
| 72 | + exit 1 |
| 73 | + fi |
| 74 | +
|
| 75 | + - name: Build and Install Python Modules in enviro_lod_tools/external |
| 76 | + run: | |
| 77 | + . venv/bin/activate |
| 78 | + cd enviro_lod_tools/external |
| 79 | + for dir in */ ; do |
| 80 | + if [ -f "$dir/pyproject.toml" ]; then |
| 81 | + echo "Building Python module in $dir" |
| 82 | + cd "$dir" |
| 83 | + python3 -m build |
| 84 | + pip install dist/*.whl |
| 85 | + cd .. |
| 86 | + fi |
| 87 | + done |
| 88 | +
|
| 89 | + - name: Clean Up Unnecessary Files in enviro_lod_tools/external |
| 90 | + run: | |
| 91 | + cd enviro_lod_tools/external |
| 92 | + # Remove all files inside subdirectories but keep top-level directories |
| 93 | + find . -mindepth 2 -type f -exec rm -f {} \; || true |
| 94 | + |
| 95 | + # Remove all empty directories |
| 96 | + find . -mindepth 2 -type d -exec rm -rf {} \; || true |
| 97 | + cd ../.. |
| 98 | +
|
| 99 | + - name: Move Installed Modules Back to enviro_lod_tools/external |
| 100 | + run: | |
| 101 | + # Copy all files and directories starting with "pyfqmr" or "xatlas" ignoring version numbers |
| 102 | + cp -r venv/lib/python3.10/site-packages/pyfqmr* enviro_lod_tools/external/ |
| 103 | + cp -r venv/lib/python3.10/site-packages/xatlas* enviro_lod_tools/external/ |
| 104 | + |
| 105 | + # Clean up the temporary installation |
| 106 | + rm -rf temp_installation |
| 107 | +
|
| 108 | + - name: Get Tag Name |
| 109 | + id: get_tag |
| 110 | + shell: bash |
| 111 | + run: | |
| 112 | + TAG=$(git describe --tags --exact-match) |
| 113 | + echo "TAGS: $TAG" |
| 114 | + if [ -z "$TAG" ]; then |
| 115 | + echo "No tags on this commit." |
| 116 | + echo "TAG=" >> $GITHUB_ENV |
| 117 | + else |
| 118 | + echo "Found tag: $TAG" |
| 119 | + echo "TAG=$TAG" >> $GITHUB_ENV |
| 120 | + fi |
| 121 | +
|
| 122 | + - name: Exit if No Tag |
| 123 | + if: env.TAG == '' |
| 124 | + run: | |
| 125 | + echo "No valid tag found on this commit. Exiting." |
| 126 | + exit 0 |
| 127 | +
|
| 128 | + - name: Cleanup and Prepare for Zipping |
| 129 | + if: env.TAG != '' |
| 130 | + run: | |
| 131 | + cd enviro_lod_tools |
| 132 | + # Deactivate the virtual environment (if active) |
| 133 | + deactivate || true # Avoid error if already inactive |
| 134 | + # Remove unnecessary files and directories |
| 135 | + rm -rf __pycache__ |
| 136 | + rm -rf ../.github |
| 137 | + rm -rf ../venv |
| 138 | + rm -rf ../__pycache__ |
| 139 | + cd .. |
| 140 | +
|
| 141 | + - name: Create enviro_lod_tools_plugin_${{ env.TAG }}.zip |
| 142 | + if: env.TAG != '' |
| 143 | + run: | |
| 144 | + cd enviro_lod_tools |
| 145 | + zip -r ../enviro_lod_tools_plugin_${{ env.TAG }}_${{ env.BLENDER_VERSION }}_${{ env.PLATFORM }}.zip . |
| 146 | +
|
| 147 | + - name: Create enviro_lod_tools_gui_${{ env.TAG }}.zip |
| 148 | + if: env.TAG != '' |
| 149 | + run: | |
| 150 | + cd enviro_lod_tools |
| 151 | + cd .. |
| 152 | + zip -r enviro_lod_tools_gui_${{ env.TAG }}_${{ env.BLENDER_VERSION }}_${{ env.PLATFORM }}.zip . -x ".git/*" -x "*.zip" |
| 153 | +
|
| 154 | + - name: Check if Release Exists |
| 155 | + id: release_check |
| 156 | + shell: bash |
| 157 | + run: | |
| 158 | + if gh release view ${{ env.TAG }} > /dev/null 2>&1; then |
| 159 | + echo "release_exists=true" >> $GITHUB_ENV |
| 160 | + else |
| 161 | + echo "release_exists=false" >> $GITHUB_ENV |
| 162 | + fi |
| 163 | + env: |
| 164 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 165 | + |
| 166 | + - name: Create GitHub Release |
| 167 | + if: env.release_exists == 'false' && env.TAG != '' |
| 168 | + id: create_release |
| 169 | + uses: actions/create-release@v1 |
| 170 | + with: |
| 171 | + tag_name: ${{ env.TAG }} |
| 172 | + release_name: Release ${{ env.TAG }} |
| 173 | + draft: false |
| 174 | + prerelease: true |
| 175 | + env: |
| 176 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 177 | + continue-on-error: true |
| 178 | + |
| 179 | + - name: Upload Plugin Zip to Release |
| 180 | + if: env.TAG != '' |
| 181 | + run: | |
| 182 | + gh release upload ${{ env.TAG }} enviro_lod_tools_plugin_${{ env.TAG }}_${{ env.BLENDER_VERSION }}_${{ env.PLATFORM }}.zip |
| 183 | + env: |
| 184 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 185 | + |
| 186 | + - name: Upload GUI Zip to Release |
| 187 | + if: env.TAG != '' |
| 188 | + run: | |
| 189 | + gh release upload ${{ env.TAG }} enviro_lod_tools_gui_${{ env.TAG }}_${{ env.BLENDER_VERSION }}_${{ env.PLATFORM }}.zip |
| 190 | + env: |
| 191 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments