Skip to content

feature: C89 adherence #64

feature: C89 adherence

feature: C89 adherence #64

Workflow file for this run

name: CI
on:
push:
paths-ignore:
- "**.md"
- "docs/**"
pull_request:
paths-ignore:
- "**.md"
- "docs/**"
env:
ROCKSPEC_VERSION: 0.0.5
DEV_ROCKSPEC: lua-uuid-dev-1.rockspec
jobs:
c89-build:
name: Build C89
runs-on: ubuntu-latest
defaults:
run:
shell: pwsh
strategy:
matrix:
lua-version:
- 5.1.5
- 5.2.4
- 5.3.6
- 5.4.7
steps:
- name: Validate Lua version, and set environment variables
run: |
if (-not ("${{ matrix.lua-version }}" -match "^(\d+)\.(\d+)(\.\d+)*$"))
{
Write-Host "Invalid Lua version (X.Y.Z) expected";
exit 1;
}
$lua_short_version = "${{ matrix.lua-version }}" -split "\." |
Select-Object -First 2 |
Join-String -Separator ".";
Add-Content "${{ github.env }}" "LUA_SHORT_VERSION=${lua_short_version}";
- name: Set environment variable to hold the rockspec name
run: |
if ("${{ github.repository }}" -eq "luau-project/lua-uuid" -and "${{ github.ref_name }}" -eq "v${{ env.ROCKSPEC_VERSION }}" -and "${{ github.ref }}" -eq "refs/tags/v${{ env.ROCKSPEC_VERSION }}")
{
Add-Content "${{ github.env }}" "ROCKSPEC=lua-uuid-${{ env.ROCKSPEC_VERSION }}-1.rockspec";
}
else
{
Add-Content "${{ github.env }}" "ROCKSPEC=${{ env.DEV_ROCKSPEC }}";
}
- name: Checkout
uses: actions/checkout@v4
with:
path: lua-uuid
- name: Install libuuid-dev
run: sudo apt install -y uuid-dev
- name: Download and extract Lua ${{ matrix.lua-version }} source code, and set environment variables
run: |
$targz = "lua-${{ matrix.lua-version }}.tar.gz";
$targz_path = Join-Path -Path "${{ runner.temp }}" -ChildPath $targz;
Invoke-WebRequest -Uri "https://lua.org/ftp/${targz}" -OutFile "$targz_path";
tar -C "${{ runner.temp }}" -xf "$targz_path";
$lua_source_dir = Join-Path -Path "${{ runner.temp }}" -ChildPath "lua-${{ matrix.lua-version }}";
if (-not (Test-Path $lua_source_dir))
{
$color = (0x1b -as [char]) + "[36m";
Write-Host "Unable to find Lua source code directory: ${color}${lua_source_dir}";
exit 1;
}
$install_dir = Join-Path -Path "${{ runner.temp }}" -ChildPath "installed-lua-${{ matrix.lua-version }}";
Add-Content "${{ github.env }}" "LUA_SRC_DIR=${lua_source_dir}";
Add-Content "${{ github.env }}" "LUA_DIR=${install_dir}";
- name: Set environment variables depending on Lua version for C89 make targets
run: |
$c89_target = "";
$c89_macro = "";
if ("5.1", "5.2" -contains "${{ env.LUA_SHORT_VERSION }}")
{
$cc = "gcc";
$c89_src_dir = Join-Path -Path "${{ env.LUA_SRC_DIR }}" -ChildPath "src";
$c89_cflags_name = "MYCFLAGS";
$c89_libs_name = "MYLIBS";
$c89_target = "all";
$c89_macro = "LUA_ANSI";
}
else
{
$cc = "gcc -std=c89";
$c89_src_dir = "${{ env.LUA_SRC_DIR }}";
$c89_cflags_name = "MYCFLAGS";
$c89_libs_name = "SYSLIBS";
$c89_target = "c89";
$c89_macro = "LUA_USE_C89";
}
Add-Content "${{ github.env }}" "CC=${cc}";
Add-Content "${{ github.env }}" "C89_SRC_DIR=${c89_src_dir}";
Add-Content "${{ github.env }}" "C89_CFLAGS_NAME=${c89_cflags_name}";
Add-Content "${{ github.env }}" "C89_LIBS_NAME=${c89_libs_name}";
Add-Content "${{ github.env }}" "C89_TARGET=${c89_target}";
Add-Content "${{ github.env }}" "C89_MACRO=${c89_macro}";
- name: Build Lua ${{ matrix.lua-version }}
run: |
make -C "${{ env.C89_SRC_DIR }}" `
"${{ env.C89_TARGET }}" `
"${{ env.C89_CFLAGS_NAME }}=-DLUA_USE_DLOPEN" `
"${{ env.C89_LIBS_NAME }}=-Wl,-E -ldl" `
"CC=${{ env.CC }}";
- name: Install Lua ${{ matrix.lua-version }}, and set environment variables
run: |
make -C "${{ env.LUA_SRC_DIR }}" `
install `
"INSTALL_TOP=${{ env.LUA_DIR }}";
$lua_bindir = Join-Path -Path "${{ env.LUA_DIR }}" -ChildPath "bin";
$lua_incdir = Join-Path -Path "${{ env.LUA_DIR }}" -ChildPath "include";
Add-Content "${{ github.path }}" "${lua_bindir}";
Add-Content "${{ github.env }}" "LUA_INCDIR=${lua_incdir}";
- name: Compile lua-uuid
working-directory: lua-uuid
run: |
${{ env.CC }} `
"-c" `
"-fPIC" `
"-o" "src/lua-uuid.o" `
"-I${{ env.LUA_INCDIR }}" `
"-Isrc" `
"-I/usr/include/uuid" `
"-D${{ env.C89_MACRO }}" `
"-DLUA_USE_DLOPEN" `
"-DLUA_UUID_BUILD_SHARED" `
"-DLUA_UUID_USE_LIBUUID" `
"src/lua-uuid.c";
- name: Link lua-uuid
working-directory: lua-uuid
run: |
gcc "-shared" `
"-o" "lua-uuid.so" `
"src/lua-uuid.o" `
"-ldl" `
"-luuid";
- name: Run samples
working-directory: lua-uuid
run: |
Get-ChildItem "samples" -Recurse -File |
Where-Object Extension -EQ ".lua" |
Select-Object -ExpandProperty FullName |
Foreach-Object {
$color = (0x1b -as [char]) + "[36m";
Write-Host "Running sample file: ${color}$_";
lua "$_";
};
build:
name: Build
runs-on: ${{ matrix.os }}
defaults:
run:
shell: pwsh
strategy:
matrix:
lua-version:
- 5.1
- 5.2
- 5.3
- 5.4
- luajit
os:
- windows-latest
- ubuntu-latest
- macos-latest
exclude:
- os: macos-latest
lua-version: luajit
steps:
- name: Set environment variable to hold the rockspec name
run: |
if ("${{ github.repository }}" -eq "luau-project/lua-uuid" -and "${{ github.ref_name }}" -eq "v${{ env.ROCKSPEC_VERSION }}" -and "${{ github.ref }}" -eq "refs/tags/v${{ env.ROCKSPEC_VERSION }}")
{
Add-Content "${{ github.env }}" "ROCKSPEC=lua-uuid-${{ env.ROCKSPEC_VERSION }}-1.rockspec";
}
else
{
Add-Content "${{ github.env }}" "ROCKSPEC=${{ env.DEV_ROCKSPEC }}";
}
- name: Checkout
uses: actions/checkout@v4
with:
path: lua-uuid
- name: Install libuuid-dev
if: ${{ matrix.os == 'ubuntu-latest' }}
run: sudo apt install -y uuid-dev
- name: Setup MSVC dev-prompt
if: ${{ matrix.os == 'windows-latest' && matrix.lua-version != 'luajit' }}
uses: ilammy/msvc-dev-cmd@v1
- name: Setup Lua
uses: luarocks/gh-actions-lua@v10
with:
luaVersion: ${{ matrix.lua-version }}
- name: Setup LuaRocks
uses: luarocks/gh-actions-luarocks@v5
- name: Lint rockspecs
working-directory: lua-uuid
run: |
Get-ChildItem . -Recurse -File |
Where-Object Extension -Eq ".rockspec" |
Select-Object -ExpandProperty FullName |
Foreach-Object {
$color = (0x1b -as [char]) + "[36m";
Write-Host "Linting rockspec: ${color}$_";
luarocks lint "$_";
}
- name: Build lua-uuid
working-directory: lua-uuid
run: |
$rockspec = Get-ChildItem . -Recurse -File |
Where-Object Name -EQ "${{ env.ROCKSPEC }}" |
Select-Object -ExpandProperty FullName -First 1;
$color = (0x1b -as [char]) + "[36m";
Write-Host "Building rockspec file: ${color}${rockspec}";
luarocks make $rockspec;
- name: Run samples
working-directory: lua-uuid
run: |
Get-ChildItem "samples" -Recurse -File |
Where-Object Extension -EQ ".lua" |
Select-Object -ExpandProperty FullName |
Foreach-Object {
$color = (0x1b -as [char]) + "[36m";
Write-Host "Running sample file: ${color}$_";
lua "$_";
};
msys2-build:
name: MSYS2 Build
runs-on: windows-latest
defaults:
run:
shell: msys2 {0}
strategy:
matrix:
MSYS2_CONFIG:
- { sys: mingw64, env: x86_64 }
- { sys: ucrt64, env: ucrt-x86_64 }
- { sys: clang64, env: clang-x86_64 }
Lua:
- { version: '5.4', msys2-pkg-name: 'lua', msys2-lua-interpreter: 'lua' }
- { version: '5.3', msys2-pkg-name: 'lua53', msys2-lua-interpreter: 'lua5.3' }
- { version: '5.1', msys2-pkg-name: 'lua51', msys2-lua-interpreter: 'lua5.1' }
- { version: '5.1', msys2-pkg-name: 'luajit', msys2-lua-interpreter: 'luajit' }
env:
LUA_INTERPRETER: /${{ matrix.MSYS2_CONFIG.sys }}/bin/${{ matrix.Lua.msys2-lua-interpreter }}
steps:
- name: Setup MSYS2
uses: msys2/setup-msys2@v2
with:
msystem: ${{ matrix.MSYS2_CONFIG.sys }}
install: |
base-devel
git
mingw-w64-${{ matrix.MSYS2_CONFIG.env }}-cc
mingw-w64-${{ matrix.MSYS2_CONFIG.env }}-${{ matrix.Lua.msys2-pkg-name }}
mingw-w64-${{ matrix.MSYS2_CONFIG.env }}-lua-luarocks
- name: Set environment variable to hold the rockspec name
run: |
if [[ "${{ github.repository }}" == "luau-project/lua-uuid" ]] && [[ "${{ github.ref_name }}" == "v${{ env.ROCKSPEC_VERSION }}" ]] && [[ "${{ github.ref }}" == "refs/tags/v${{ env.ROCKSPEC_VERSION }}" ]];
then
echo "ROCKSPEC=lua-uuid-${{ env.ROCKSPEC_VERSION }}-1.rockspec" >> "${{ github.env }}";
else
echo "ROCKSPEC=${{ env.DEV_ROCKSPEC }}" >> "${{ github.env }}";
fi;
- name: Configure LuaRocks
run: |
source /etc/makepkg_mingw.conf
echo "CC=/${{ matrix.MSYS2_CONFIG.sys }}/bin/${CC}" >> "${{ github.env }}"
echo "CFLAGS=${CFLAGS}" >> "${{ github.env }}"
luarocks config lua_version "${{ matrix.Lua.version }}"
luarocks config lua_dir "/${{ matrix.MSYS2_CONFIG.sys }}"
- name: Checkout
uses: actions/checkout@v4
with:
path: lua-uuid
- name: Lint rockspecs
working-directory: lua-uuid
run: |
for rockspec in rockspecs/*.rockspec;
do
echo -e "Linting rockspec: \e[36m${rockspec}\e[0m";
luarocks lint "${rockspec}";
done;
- name: Build lua-uuid
working-directory: lua-uuid
run: |
rockspec="rockspecs/${{ env.ROCKSPEC }}";
echo -e "Building rockspec: \e[36m${rockspec}\e[0m";
luarocks make ${rockspec};
- name: Run samples
working-directory: lua-uuid
run: |
for sample in samples/*.lua;
do
echo -e "Running sample file: \e[36m${sample}\e[0m"
${{ env.LUA_INTERPRETER }} $sample;
done;
upload-rockspec:
name: Upload rockspec
runs-on: ubuntu-latest
if: ${{ github.repository == 'luau-project/lua-uuid' && github.ref_type == 'tag' }}
needs:
- c89-build
- build
- msys2-build
defaults:
run:
shell: pwsh
steps:
- name: Set environment variable to hold the rockspec name
run: |
if ("${{ github.repository }}" -eq "luau-project/lua-uuid" -and "${{ github.ref_name }}" -eq "v${{ env.ROCKSPEC_VERSION }}" -and "${{ github.ref }}" -eq "refs/tags/v${{ env.ROCKSPEC_VERSION }}")
{
Add-Content "${{ github.env }}" "ROCKSPEC=lua-uuid-${{ env.ROCKSPEC_VERSION }}-1.rockspec";
}
else
{
Add-Content "${{ github.env }}" "ROCKSPEC=${{ env.DEV_ROCKSPEC }}";
}
- name: Checkout
uses: actions/checkout@v4
with:
path: lua-uuid
- name: Setup Lua
uses: luarocks/gh-actions-lua@v10
- name: Setup LuaRocks
uses: luarocks/gh-actions-luarocks@v5
- name: Make sure that tags from GitHub and rockspec are equal
run: |
$rockspec = Get-ChildItem . -Recurse -File |
Where-Object Name -EQ "${{ env.ROCKSPEC }}" |
Select-Object -ExpandProperty FullName -First 1;
$rockspec_tag = lua -e "dofile(arg[0]); io.write(source.tag);" -- "${rockspec}";
$github_tag = "v${{ github.ref_name }}";
if ("${rockspec_tag}" -ne "${github_tag}")
{
$color_msg = (0x1b -as [char]) + "[31m";
$color_reset = (0x1b -as [char]) + "[0m";
$color_tag = (0x1b -as [char]) + "[33m";
Write-Host "${color_msg}Tag mismatch${color_reset}: GitHub tag (${color_tag}${github_tag}${color_reset}) != rockspec tag (${color_tag}${rockspec_tag}${color_reset})";
exit 1;
}
- name: Install LuaRocks dependencies to upload
run: |
sudo apt install -y uuid-dev libssl-dev;
luarocks install dkjson;
luarocks install luasocket;
luarocks install luasec;
- name: Upload rockspec to LuaRocks
working-directory: lua-uuid
env:
UPLOAD_KEY: ${{ secrets.LUAROCKS_APIKEY }}
run: |
$rockspec = Get-ChildItem . -Recurse -File |
Where-Object Name -EQ "${{ env.ROCKSPEC }}" |
Select-Object -ExpandProperty FullName -First 1;
$color = (0x1b -as [char]) + "[36m";
Write-Host "Uploading rockspec: ${color}${rockspec}";
luarocks upload $rockspec "--temp-key=$env:UPLOAD_KEY" --skip-pack