|
| 1 | +# Usage in CI servers |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +By the use of ```LuaInstaller.Console```, you can setup continuous integration / continuous delivery (CI CD) to buid and test your Lua-related project on Windows against the MSVC toolchain. |
| 6 | + |
| 7 | +## Table of Contents |
| 8 | + |
| 9 | +* [Setup Lua](#setup-lua) |
| 10 | +* [Setup Lua and LuaRocks](#setup-lua-and-luarocks) |
| 11 | + |
| 12 | +## Setup Lua |
| 13 | + |
| 14 | +Below, in a GitHub workflow, we setup different versions of Lua, building for x64 and x86 architectures. |
| 15 | + |
| 16 | +> [!TIP] |
| 17 | +> |
| 18 | +> After testing the built interpreter, as a bonus, we also make Lua discoverable by ```CMake``` and ```pkg-config```. |
| 19 | +
|
| 20 | +```yaml |
| 21 | +name: Setup Lua |
| 22 | + |
| 23 | +on: [push, pull_request] |
| 24 | + |
| 25 | +env: |
| 26 | + LUAINSTALLER_VERSION: 0.5.0.0 |
| 27 | + |
| 28 | +jobs: |
| 29 | + |
| 30 | + build: |
| 31 | + runs-on: windows-latest |
| 32 | + name: Build |
| 33 | + |
| 34 | + strategy: |
| 35 | + matrix: |
| 36 | + |
| 37 | + lua-version: |
| 38 | + - 5.1.5 |
| 39 | + - 5.2.4 |
| 40 | + - 5.3.6 |
| 41 | + - 5.4.7 |
| 42 | + |
| 43 | + arch: |
| 44 | + - x64 |
| 45 | + - x86 |
| 46 | + |
| 47 | + steps: |
| 48 | + |
| 49 | + - name: Sanity check the Lua version |
| 50 | + shell: pwsh |
| 51 | + run: | |
| 52 | + if (-not ("${{ matrix.lua-version }}" -match "^[0-9]+\.[0-9]+\.[0-9]+$")) |
| 53 | + { |
| 54 | + Write-Host "Invalid Lua version"; |
| 55 | + exit 1; |
| 56 | + } |
| 57 | + |
| 58 | + - name: Sanity check the architecture |
| 59 | + run: | |
| 60 | + if (-not ("${{ matrix.arch }}" -match "^[xX](64|86)$")) |
| 61 | + { |
| 62 | + Write-Host "Invalid architecture"; |
| 63 | + exit 1; |
| 64 | + } |
| 65 | +
|
| 66 | + - name: Set environment variable to hold Lua's installation directory |
| 67 | + shell: pwsh |
| 68 | + run: | |
| 69 | + $guid_string = [System.Guid]::NewGuid() | Select-Object -ExpandProperty Guid; |
| 70 | + $lua_dir = Join-Path -Path "${{ runner.temp }}" -ChildPath $guid_string; |
| 71 | + Add-Content "${{ github.env }}" "LUA_DIR=${lua_dir}"; |
| 72 | +
|
| 73 | + - name: Download and extract LuaInstaller.Console, and place it on PATH environment variable |
| 74 | + shell: pwsh |
| 75 | + env: |
| 76 | + LUAINSTALLER_URL: https://github.com/luau-project/LuaInstaller/releases/download/v${{ env.LUAINSTALLER_VERSION }}/LuaInstaller.Console-v${{ env.LUAINSTALLER_VERSION }}-${{ matrix.arch }}.zip |
| 77 | + run: | |
| 78 | + $guid_string = [System.Guid]::NewGuid() | Select-Object -ExpandProperty Guid; |
| 79 | + $luainstaller_zip_file = Join-Path -Path "${{ runner.temp }}" -ChildPath "${guid_string}.zip"; |
| 80 | +
|
| 81 | + # Download |
| 82 | + Invoke-WebRequest -Uri "${{ env.LUAINSTALLER_URL }}" -OutFile $luainstaller_zip_file; |
| 83 | +
|
| 84 | + # Unzip |
| 85 | + Expand-Archive -Path $luainstaller_zip_file -DestinationPath "${{ runner.temp }}"; |
| 86 | +
|
| 87 | + $luainstaller_path = Join-Path -Path "${{ runner.temp }}" -ChildPath "LuaInstaller.Console"; |
| 88 | +
|
| 89 | + # Add LuaInstaller.Console to the PATH environment variable |
| 90 | + Add-Content "${{ github.path }}" "${luainstaller_path}"; |
| 91 | + |
| 92 | + - name: Install Lua ${{ matrix.lua-version }} |
| 93 | + run: | |
| 94 | + LuaInstaller.Console install "dest-dir=${{ env.LUA_DIR }}" "version=${{ matrix.lua-version }}" "arch=${{ matrix.arch }}" |
| 95 | +
|
| 96 | + - name: Add Lua interpreter and DLL to PATH environment variable |
| 97 | + shell: pwsh |
| 98 | + run: | |
| 99 | + $lua_bin = Join-Path -Path "${{ env.LUA_DIR }}" -ChildPath "bin"; |
| 100 | + Add-Content "${{ github.path }}" "${lua_bin}"; |
| 101 | + |
| 102 | + - name: Test Lua ${{ matrix.lua-version }} |
| 103 | + run: lua -v |
| 104 | + |
| 105 | + - name: Setup Lua ${{ matrix.lua-version }} for CMake |
| 106 | + shell: pwsh |
| 107 | + run: | |
| 108 | + $cmake_module_path = "$env:CMAKE_MODULE_PATH"; |
| 109 | + Add-Content "${{ github.env }}" "CMAKE_MODULE_PATH=${{ env.LUA_DIR }};${cmake_module_path}"; |
| 110 | + |
| 111 | + - name: Setup Lua ${{ matrix.lua-version }} for pkg-config |
| 112 | + shell: pwsh |
| 113 | + run: | |
| 114 | + $lua_pc_dir = Get-ChildItem "${{ env.LUA_DIR }}" -File -Recurse | |
| 115 | + Where-Object Name -Like "lua*.pc" | |
| 116 | + Select-Object -ExpandProperty FullName -First 1 | |
| 117 | + Split-Path; |
| 118 | + |
| 119 | + $pkg_config_path = "$env:PKG_CONFIG_PATH"; |
| 120 | + Add-Content "${{ github.env }}" "PKG_CONFIG_PATH=${lua_pc_dir};${pkg_config_path}"; |
| 121 | +``` |
| 122 | +
|
| 123 | +## Setup Lua and LuaRocks |
| 124 | +
|
| 125 | +This time, in another GitHub workflow, we setup Lua and LuaRocks. At the end of the workflow, we install a few libraries using LuaRocks. |
| 126 | +
|
| 127 | +```yaml |
| 128 | +name: Setup Lua and LuaRocks |
| 129 | + |
| 130 | +on: [push, pull_request] |
| 131 | + |
| 132 | +env: |
| 133 | + LUAINSTALLER_VERSION: 0.5.0.0 |
| 134 | + LUAROCKS_VERSION: 3.11.1 |
| 135 | + |
| 136 | +jobs: |
| 137 | + |
| 138 | + build: |
| 139 | + runs-on: windows-latest |
| 140 | + name: Build |
| 141 | + |
| 142 | + strategy: |
| 143 | + matrix: |
| 144 | + |
| 145 | + lua-version: |
| 146 | + - 5.1.5 |
| 147 | + - 5.2.4 |
| 148 | + - 5.3.6 |
| 149 | + - 5.4.7 |
| 150 | + |
| 151 | + arch: |
| 152 | + - x64 |
| 153 | + - x86 |
| 154 | + |
| 155 | + steps: |
| 156 | + |
| 157 | + - name: Sanity check the Lua version |
| 158 | + shell: pwsh |
| 159 | + run: | |
| 160 | + if (-not ("${{ matrix.lua-version }}" -match "^[0-9]+\.[0-9]+\.[0-9]+$")) |
| 161 | + { |
| 162 | + Write-Host "Invalid Lua version"; |
| 163 | + exit 1; |
| 164 | + } |
| 165 | + |
| 166 | + - name: Sanity check the architecture |
| 167 | + run: | |
| 168 | + if (-not ("${{ matrix.arch }}" -match "^[xX](64|86)$")) |
| 169 | + { |
| 170 | + Write-Host "Invalid architecture"; |
| 171 | + exit 1; |
| 172 | + } |
| 173 | + |
| 174 | + - name: Set environment variable to hold Lua's installation directory |
| 175 | + shell: pwsh |
| 176 | + run: | |
| 177 | + $guid_string = [System.Guid]::NewGuid() | Select-Object -ExpandProperty Guid; |
| 178 | + $lua_dir = Join-Path -Path "${{ runner.temp }}" -ChildPath $guid_string; |
| 179 | + Add-Content "${{ github.env }}" "LUA_DIR=${lua_dir}"; |
| 180 | +
|
| 181 | + - name: Download and extract LuaInstaller.Console, and place it on PATH environment variable |
| 182 | + shell: pwsh |
| 183 | + env: |
| 184 | + LUAINSTALLER_URL: https://github.com/luau-project/LuaInstaller/releases/download/v${{ env.LUAINSTALLER_VERSION }}/LuaInstaller.Console-v${{ env.LUAINSTALLER_VERSION }}-${{ matrix.arch }}.zip |
| 185 | + run: | |
| 186 | + $guid_string = [System.Guid]::NewGuid() | Select-Object -ExpandProperty Guid; |
| 187 | + $luainstaller_zip_file = Join-Path -Path "${{ runner.temp }}" -ChildPath "${guid_string}.zip"; |
| 188 | +
|
| 189 | + # Download |
| 190 | + Invoke-WebRequest -Uri "${{ env.LUAINSTALLER_URL }}" -OutFile $luainstaller_zip_file; |
| 191 | +
|
| 192 | + # Unzip |
| 193 | + Expand-Archive -Path $luainstaller_zip_file -DestinationPath "${{ runner.temp }}"; |
| 194 | +
|
| 195 | + $luainstaller_path = Join-Path -Path "${{ runner.temp }}" -ChildPath "LuaInstaller.Console"; |
| 196 | +
|
| 197 | + # Add LuaInstaller.Console to the PATH environment variable |
| 198 | + Add-Content "${{ github.path }}" "${luainstaller_path}"; |
| 199 | + |
| 200 | + - name: Install Lua ${{ matrix.lua-version }} |
| 201 | + run: | |
| 202 | + LuaInstaller.Console install "dest-dir=${{ env.LUA_DIR }}" "version=${{ matrix.lua-version }}" "arch=${{ matrix.arch }}" |
| 203 | +
|
| 204 | + - name: Add Lua interpreter and DLL to PATH environment variable |
| 205 | + shell: pwsh |
| 206 | + run: | |
| 207 | + $lua_bin = Join-Path -Path "${{ env.LUA_DIR }}" -ChildPath "bin"; |
| 208 | + Add-Content "${{ github.path }}" "${lua_bin}"; |
| 209 | + |
| 210 | + - name: Test Lua ${{ matrix.lua-version }} |
| 211 | + run: lua -v |
| 212 | + |
| 213 | + - name: Setup Lua ${{ matrix.lua-version }} for CMake |
| 214 | + shell: pwsh |
| 215 | + run: | |
| 216 | + $cmake_module_path = "$env:CMAKE_MODULE_PATH"; |
| 217 | + Add-Content "${{ github.env }}" "CMAKE_MODULE_PATH=${{ env.LUA_DIR }};${cmake_module_path}"; |
| 218 | + |
| 219 | + - name: Setup Lua ${{ matrix.lua-version }} for pkg-config |
| 220 | + shell: pwsh |
| 221 | + run: | |
| 222 | + $lua_pc_dir = Get-ChildItem "${{ env.LUA_DIR }}" -File -Recurse | |
| 223 | + Where-Object Name -Like "lua*.pc" | |
| 224 | + Select-Object -ExpandProperty FullName -First 1 | |
| 225 | + Split-Path; |
| 226 | + |
| 227 | + $pkg_config_path = "$env:PKG_CONFIG_PATH"; |
| 228 | + Add-Content "${{ github.env }}" "PKG_CONFIG_PATH=${lua_pc_dir};${pkg_config_path}"; |
| 229 | + |
| 230 | + # Setting up LuaRocks |
| 231 | + - name: Set environment variable to LuaRocks download URL depending on arch |
| 232 | + shell: pwsh |
| 233 | + run: | |
| 234 | + $allowed_archs = @{ x86 = "32"; x64 = "64" }; |
| 235 | + $arch_lower = "${{ matrix.arch }}".ToLower(); |
| 236 | +
|
| 237 | + if ($allowed_archs.Keys -contains $arch_lower) |
| 238 | + { |
| 239 | + $v = $allowed_archs[$arch_lower]; |
| 240 | +
|
| 241 | + Add-Content "${{ github.env }}" "LUAROCKS_URL=https://luarocks.github.io/luarocks/releases/luarocks-${{ env.LUAROCKS_VERSION }}-windows-${v}.zip"; |
| 242 | + } |
| 243 | + else |
| 244 | + { |
| 245 | + Write-Host "Invalid arch: x64 or x86 expected, but got ${{ matrix.arch }}"; |
| 246 | + exit 1; |
| 247 | + } |
| 248 | +
|
| 249 | + - name: Download and extract LuaRocks, and place it on PATH environment variable |
| 250 | + shell: pwsh |
| 251 | + run: | |
| 252 | + $uri = [System.Uri]::new("${{ env.LUAROCKS_URL }}"); |
| 253 | + $zipname = $uri | Select-Object -ExpandProperty Segments | Select-Object -Last 1; |
| 254 | +
|
| 255 | + $luarocks_zip = Join-Path -Path "${{ runner.temp }}" -ChildPath "${zipname}"; |
| 256 | +
|
| 257 | + # Download |
| 258 | + Invoke-WebRequest -Uri "${{ env.LUAROCKS_URL }}" -OutFile "${luarocks_zip}"; |
| 259 | +
|
| 260 | + # Extract |
| 261 | + Expand-Archive -Path "${luarocks_zip}" -DestinationPath "${{ runner.temp }}"; |
| 262 | +
|
| 263 | + $luarocks_dir = Get-ChildItem -Path "${{ runner.temp }}" -Recurse -File | |
| 264 | + Where-Object Name -EQ "luarocks.exe" | |
| 265 | + Select-Object -ExpandProperty FullName -First 1 | |
| 266 | + Split-Path; |
| 267 | + |
| 268 | + # Add LuaRocks to PATH |
| 269 | + Add-Content "${{ github.path }}" "${luarocks_dir}"; |
| 270 | + |
| 271 | + - name: Setup MSVC dev-prompt for LuaRocks configuration |
| 272 | + uses: ilammy/msvc-dev-cmd@v1 |
| 273 | + with: |
| 274 | + arch: ${{ matrix.arch }} |
| 275 | + |
| 276 | + - name: Configure LuaRocks for Lua ${{ matrix.lua-version }} |
| 277 | + shell: pwsh |
| 278 | + run: | |
| 279 | + luarocks config lua_dir "${{ env.LUA_DIR }}"; |
| 280 | +
|
| 281 | + $lua_short_version = "${{ matrix.lua-version }}" -split "\." | |
| 282 | + Select-Object -First 2 | |
| 283 | + Join-String -Separator "."; |
| 284 | + |
| 285 | + luarocks config lua_version $lua_short_version; |
| 286 | +
|
| 287 | + # Update environment variables with variables from LuaRocks |
| 288 | + $luarocks_path = luarocks path; |
| 289 | + Add-Content "${{ github.env }}" $luarocks_path.Replace("""", "").Replace("'", "").Replace("SET ", ""); |
| 290 | + |
| 291 | + - name: Install a few libraries through LuaRocks |
| 292 | + run: | |
| 293 | + luarocks install luafilesystem |
| 294 | + luarocks install luasocket |
| 295 | + luarocks install lua-cjson |
| 296 | +``` |
| 297 | +
|
| 298 | +[Back to the Docs](../docs/README.md) |
0 commit comments