From ce14b5a6ea7992d9c898caca0f5c045661a8dc94 Mon Sep 17 00:00:00 2001 From: pnlmon Date: Wed, 23 Mar 2022 01:03:10 +0800 Subject: [PATCH 1/2] Fixed issue with tests.lua on Linux 1. Windows mode not properly switching (Fixed by introducing a new argument) 2. ``.`` and ``..`` mistakenly being treated as actual files (Fixed by adding a check to only allow .lua file) --- tests.lua | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests.lua b/tests.lua index 0797e5d..37f0376 100644 --- a/tests.lua +++ b/tests.lua @@ -19,6 +19,12 @@ local code = [=[ ]=]; +for _, currArg in pairs(arg) do + if currArg == "--Linux" then + isWindows = false + end +end + -- Enable/Disable Console Colors - this may be needed because cmd.exe and powershell.exe do not support ANSI Color Escape Sequences. The Windows Terminal Application is needed Prometheus.colors.enabled = not noColors; @@ -39,8 +45,10 @@ local function scandir(directory) local i, t, popen = 0, {}, io.popen local pfile = popen(isWindows and 'dir "'..directory..'" /b' or 'ls -a "'..directory..'"') for filename in pfile:lines() do - i = i + 1 - t[i] = filename + if string.sub(filename, -4) == ".lua" then + i = i + 1 + t[i] = filename + end end pfile:close() return t From efb0f66817b1b53e0f049c915b2e888317be9c8c Mon Sep 17 00:00:00 2001 From: pnlmon Date: Wed, 23 Mar 2022 18:17:16 +0800 Subject: [PATCH 2/2] CI Workflow --- .github/workflows/CI.yml | 61 ++++++++++++++++++++++++++++++++++++++++ src/config.lua | 13 +++++++++ tests.lua | 7 +++++ 3 files changed, 81 insertions(+) create mode 100644 .github/workflows/CI.yml diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml new file mode 100644 index 0000000..69f8fe6 --- /dev/null +++ b/.github/workflows/CI.yml @@ -0,0 +1,61 @@ +name: CI + +on: + push: + branches: + main + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@master + - name: Install Lua + uses: leafo/gh-actions-lua@master + with: + luaVersion: 5.1 + - name: Run test case + run: lua ./tests.lua --Linux --CI + + build: + runs-on: windows-latest # gh-actions-lua doesn't work on windows + steps: + - name: Checkout repo + uses: actions/checkout@master + - name: Download srlua-mingw + run: curl -o srlua.zip "https://raw.githubusercontent.com/joedf/LuaBuilds/gh-pages/hdata/srlua-5.1.5_Win32_bin.zip" + - name: Unzip srlua-mingw + run: | + tar -xf srlua.zip + Rename-Item -Path srglue.exe -NewName glue.exe + - name: Download Lua53 + run: curl -o Lua53.zip "https://raw.githubusercontent.com/joedf/LuaBuilds/gh-pages/hdata/lua-5.3.5_Win64_bin.zip" + - name: Unzip Lua53 + run: | + tar -xf Lua53.zip + - run: dir + - name: Build the project + run: | + ./build.bat + shell: bash + - name: Zip the build + uses: papeloto/action-zip@v1 + with: + files: build/ + dest: build.zip + - name: Load version and name + run: | # I have no idea why but 5.1 just won't work for some reason + echo "prometheus_full_version=$(./lua.exe ./src/config.lua --FullVersion)" >> $GITHUB_ENV + echo "prometheus_version=$(./lua.exe ./src/config.lua --Version)" >> $GITHUB_ENV + shell: bash + - name: Upload binaries to release + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: build.zip + asset_name: ${{ env.prometheus_full_version }}.zip + tag: release-${{ github.ref }}-${{ env.prometheus_version }} + release_name: ${{ env.prometheus_version }} + overwrite: true + body: ${{ env.prometheus_full_version }} ${{ github.event.commits[0].message }} \ No newline at end of file diff --git a/src/config.lua b/src/config.lua index 83899a3..c558cc6 100644 --- a/src/config.lua +++ b/src/config.lua @@ -11,6 +11,19 @@ local REVISION = "Alpha"; local VERSION = "v0.2"; local BY = "levno-710"; +for _, currArg in pairs(arg) do + if currArg == "--CI" then + local releaseName = string.gsub(string.format("%s %s %s", NAME, REVISION, VERSION), "%s", "-") + print(releaseName) + return + end + + if currArg == "--FullVersion" then + print(VERSION) + return + end +end + -- Config Starts here return { Name = NAME, diff --git a/tests.lua b/tests.lua index 37f0376..112be1c 100644 --- a/tests.lua +++ b/tests.lua @@ -13,6 +13,7 @@ local Prometheus = require("src.prometheus") local noColors = false; -- Wether Colors in the Console output should be enabled local noHighlight = false; -- Disable Syntax Highlighting of Outputed Code local isWindows = true; -- Wether the Test are Performed on a Windows or Linux System +local ciMode = false; -- Wether the Test error are ignored or not -- The Code to Obfuscate local code = [=[ @@ -23,6 +24,9 @@ for _, currArg in pairs(arg) do if currArg == "--Linux" then isWindows = false end + if currArg == "--CI" then + ciMode = true + end end -- Enable/Disable Console Colors - this may be needed because cmd.exe and powershell.exe do not support ANSI Color Escape Sequences. The Windows Terminal Application is needed @@ -122,6 +126,9 @@ for i, filename in ipairs(scandir(testdir)) do print(Prometheus.colors("[FAILED] ", "red") .. "(" .. filename .. ") " .. step.Name); print("[OUTA] ", outa); print("[OUTB] ", outb); + if ciMode then + error("Test Failed!") + end fc = fc + 1; end end