Skip to content

luau-project/setup-lua

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

Overview

Installs Lua / LuaJIT / OpenResty + LuaRocks in a single step inside the .lua folder in the current directory.

Usage

name: Setup Lua
on: push
jobs:
  install-lua:
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os:
          - ubuntu-latest
          - windows-latest
          - macos-latest
        lua-version:
          - 5.1
          - 5.2
          - 5.3
          - 5.4
          - 5.5
          - luajit
          - openresty
        toolchain:
          - msvc
          - cc
        exclude:
          - os: ubuntu-latest
            toolchain: msvc
          - os: macos-latest
            toolchain: msvc
    steps:
      - uses: actions/checkout@v7
      - name: Setup MSVC developer prompt
        uses: step-security/msvc-dev-cmd@v1
        if: ${{ runner.os == 'Windows' && matrix.toolchain == 'msvc' }}
      - name: Install Lua
        uses: luau-project/setup-lua@v2
        with:
          lua-version: ${{ matrix.lua-version }}
      - name: Display the Lua version
        run: lua -v
      - name: Test Lua
        run: lua -e "print('this is a test from ' .. _VERSION)"
      - name: Display LuaRocks version
        run: luarocks --version

Explanation: This snippet installs Lua (or LuaJIT or OpenResty, depending on the matrix) + LuaRocks, and configures the environment for the toolchain that was used to build Lua. When the lua-version field of the matrix assumes luajit or openresty values, it fetches the latest source code from their GitHub repositories, https://github.com/LuaJIT/LuaJIT/ and https://github.com/openresty/luajit2/, respectively.

Note

  • On most operating systems, setup-lua uses cc as the default C compiler and linker to build Lua / LuaJIT / OpenResty, which is often GCC or Clang.

  • On Windows, when you load Visual Studio developer prompt details (e.g.: step-security/msvc-dev-cmd) for the Microsoft Visual Studio C/C++ compiler (MSVC), setup-lua adopts MSVC as the selected toolchain to build Lua / LuaJIT / OpenResty. Otherwise, if you don't load Visual Studio developer prompt, setup-lua examines environment variables to decide between the use of gcc or cc to build Lua / LuaJIT / OpenResty.

Further usage

In setup-lua, the most important inputs are lua-version and luarocks-version, so that you can choose specific versions to install. There are many options to tweak setup-lua: see GitHub Actions docs for an exhaustive list of inputs.

Version requirements

  • Lua:
    • PUC-Lua (≥ 5.1.1)
    • LuaJIT (≥ v2.0.0)
    • OpenResty (≥ v2.0.0)
  • LuaRocks (≥ 3.9.1)

Install specific Lua and LuaRocks version

      - name: Install Lua
        uses: luau-project/setup-lua@v2
        with:
          lua-version: 5.3.4
          luarocks-version: 3.12.0

Install Lua, but skip LuaRocks installation

In order to skip LuaRocks installation, use none as the value for the luarocks-version input as follows:

      - name: Install Lua
        uses: luau-project/setup-lua@v2
        with:
          lua-version: 5.4.7
          luarocks-version: none

Install specific LuaJIT and LuaRocks version

Use the syntax luajit@ref with ref meaning a branch name, a tag or the sha of a commit. The example below installs LuaJIT from the commit 871db2c84ecefd70a850e03a6c340214a81739f0:

      - name: Install LuaJIT
        uses: luau-project/setup-lua@v2
        with:
          lua-version: luajit@871db2c84ecefd70a850e03a6c340214a81739f0
          luarocks-version: 3.12.1

Install specific OpenResty and LuaRocks version

Use the syntax openresty@ref with ref meaning a branch name, a tag or the sha of a commit. The example below installs OpenResty from the tag v2.1-20250826:

      - name: Install OpenResty
        uses: luau-project/setup-lua@v2
        with:
          lua-version: openresty@v2.1-20250826
          luarocks-version: 3.12.2

Install on MSYS2

Since setup-lua version 1.1.0, through the CLI interface (see the parameters), there is builtin support to install Lua / LuaJIT / OpenResty + LuaRocks on MSYS2 MinGW-w64 environments.

name: Setup Lua on MSYS2
on: push
jobs:
  msys2-install-lua:
    runs-on: windows-latest
    defaults:
      run:
        shell: msys2 {0}
    strategy:
      fail-fast: false
      matrix:
        lua-version:
          - 5.1
          - 5.2
          - 5.3
          - 5.4
          - 5.5
          - luajit
          - openresty
        sys:
          - MINGW64
          - UCRT64
          - CLANG64
    steps:
      - uses: msys2/setup-msys2@v2
        with:
          msystem: ${{ matrix.sys }}
          install: |
            base-devel
            unzip
          pacboy: |
            cc:p
            make:p
      - name: Download `setup-lua`
        run: curl -LO "https://github.com/luau-project/setup-lua/archive/refs/tags/v2.tar.gz"
      - name: Extract `setup-lua`
        run: tar -xf v2.tar.gz
      - name: Setup Lua
        run: |
          env \
            LUA_VERSION=${{ matrix.lua-version }} \
            "/c/Program Files/nodejs/node.exe" \
            ./setup-lua-2/dist/cli/index.js
      - name: Display the Lua version
        run: lua.exe -v
      - name: Display LuaRocks version
        run: luarocks --version

Note

  • Without any changes, at the moment, LuaRocks does need a few patches to work nicely on MSYS2. See here for the list of patches we apply by default to make it work;
  • When using Lua 5.1, Lua 5.2 and LuaJIT / OpenResty, it is required to use lua.exe and not only lua. The reason for this is the presence of a lua directory inside the bin folder. Thus, bash tries to execute such lua directory as an executable and fails.

Tip

By default, MSYS2 does not update environment variables according to changes on ${{ github.env }} or ${{ github.path }}. In order to set environment variables on MSYS2, we store Lua and LuaRocks environment variables at /etc/profile.d/setup-lua.sh.

Install work versions of Lua

Tip

setup-lua also handles work versions of Lua (≥ 5.1.1):

      - name: Install Lua 5.5.1 (RC1)
        uses: luau-project/setup-lua@v2
        with:
          lua-version: 5.5.1-rc1
          luarocks-version: 3.13.0

Working modes

setup-lua works in two modes: i) as a GitHub Action; ii) as a standalone CLI nodejs application.

In order to ease navigation and avoid excess of information, a complete reference for both modes can be found in the following documents:

  1. GitHub Actions docs;
  2. CLI docs.

Security

Have you found a security issue on this software? Visit the security page for instructions to report privately.

Contributing

Do you want to fix a bug or have an idea to improve this project? See the contribution page.

History

Browse the changelog.


Back to Top

About

Installs Lua / LuaJIT / OpenResty + LuaRocks in a single step

Resources

License

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Packages

 
 
 

Contributors

Languages