102 lines
2.5 KiB
YAML
102 lines
2.5 KiB
YAML
name: Minify Lua Code
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
paths:
|
|
- 'src/**'
|
|
pull_request:
|
|
branches:
|
|
- main
|
|
paths:
|
|
- 'src/**'
|
|
|
|
jobs:
|
|
minify:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v2
|
|
|
|
- name: Install Lua
|
|
run: |
|
|
sudo apt-get update
|
|
sudo apt-get install -y lua5.3
|
|
|
|
- name: Minify Lua files
|
|
run: |
|
|
mkdir -p release
|
|
|
|
echo "Creating minification script..."
|
|
cat > minify_script.lua << 'EOL'
|
|
local minify = loadfile("minify.lua")()
|
|
local lfs = require("lfs")
|
|
|
|
local files = {}
|
|
for file in lfs.dir("src") do
|
|
if file:match("%.lua$") then
|
|
table.insert(files, file)
|
|
end
|
|
end
|
|
|
|
local output = {
|
|
'local minified = true\n',
|
|
'local project = {}\n'
|
|
}
|
|
|
|
for _, file in ipairs(files) do
|
|
local f = io.open("src/" .. file, "r")
|
|
local content = f:read("*all")
|
|
f:close()
|
|
|
|
local success, minified = minify(content)
|
|
if not success then
|
|
print("Failed to minify " .. file)
|
|
print(minified)
|
|
os.exit(1)
|
|
end
|
|
|
|
table.insert(output, string.format(
|
|
'project["%s"] = function(...) %s end\n',
|
|
file, minified
|
|
))
|
|
end
|
|
|
|
table.insert(output, 'return project["main.lua"]')
|
|
|
|
local out = io.open("release/project.min.lua", "w")
|
|
out:write(table.concat(output))
|
|
out:close()
|
|
EOL
|
|
|
|
echo "Installing LuaFileSystem..."
|
|
sudo apt-get install -y lua-filesystem
|
|
|
|
echo "Running minification..."
|
|
if lua minify_script.lua; then
|
|
echo "Minification successful"
|
|
echo "Minified content:"
|
|
cat release/project.min.lua
|
|
else
|
|
echo "Minification failed"
|
|
exit 1
|
|
fi
|
|
|
|
- name: Commit minified Lua file
|
|
if: success()
|
|
run: |
|
|
if [ -s release/project.min.lua ]; then
|
|
git config --global user.name 'github-actions[bot]'
|
|
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
|
|
git add release/project.min.lua
|
|
git commit -m 'Minify all Lua files into project bundle'
|
|
git push
|
|
else
|
|
echo "Error: project.min.lua is empty or doesn't exist"
|
|
exit 1
|
|
fi
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|