-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
162 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Deploy to Workshop | ||
|
||
on: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@master | ||
- uses: leafo/gh-actions-lua@v10 | ||
with: | ||
luaVersion: "luajit-2.1.0-beta3" | ||
|
||
- name: Run gma packer | ||
run: | | ||
lua .github/workflows/gma.lua webaudio.gma | ||
- name: Download gmodws | ||
run: | | ||
curl -o gmodws.zip -L https://github.com/Meachamp/gmodws/releases/download/v1.5/gmodws.zip | ||
unzip gmodws.zip | ||
- name: Deploy | ||
run: | | ||
set STEAM_PASSWORD=${{ secrets.STEAM_PASSWORD }} | ||
./gmodws ${{ secrets.STEAM_USERNAME }} 2466875474 webaudio.gma "Deployment via github actions" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
-- GMA packer in pure lua by Vurv | ||
assert(arg[1], "Missing argument #1 (output file)") | ||
|
||
local function u8(n --[[@param n number]]) | ||
return string.char(n) | ||
end | ||
|
||
local U8_MAX = 256 | ||
local U16_MAX = 65536 | ||
local U32_MAX = 4294967296 | ||
|
||
local function u16(n --[[@param n number]]) | ||
return u8(n % U8_MAX) .. u8( math.floor(n / U8_MAX) ) | ||
end | ||
|
||
local function u32(n --[[@param n number]]) | ||
return u16(n % U16_MAX) .. u16( math.floor(n / U16_MAX) ) | ||
end | ||
|
||
local function u64(n --[[@param n number]]) | ||
return u32(n % U32_MAX) .. u32( math.floor(n / U32_MAX) ) | ||
end | ||
|
||
local function cstr(s --[[@param s string]]) | ||
return s .. "\0" | ||
end | ||
|
||
---@generic T, V | ||
---@param t T[] | ||
---@param f fun(v: T, k: integer): V | ||
---@return V[] | ||
local function map(t, f) | ||
local out = {} | ||
for k, v in ipairs(t) do out[k] = f(v, k) end | ||
return out | ||
end | ||
|
||
---@param name string | ||
---@param description string | ||
---@param author string | ||
---@param files { path: string, content: string }[] # List of 'files' | ||
---@return string gma # Packed gma file contents | ||
local function pack(name, description, author, files) | ||
return table.concat { | ||
"GMAD", -- identifier | ||
u8(3), -- gma version | ||
u64(0), -- steamid | ||
u64( os.time() ), -- timestamp | ||
u8(0), | ||
cstr(name), | ||
cstr(description), | ||
cstr(author), | ||
u32(1), | ||
table.concat(map(files, function(v, k) | ||
return u32(k) | ||
.. cstr(v.path) | ||
.. u64(#v.content) | ||
.. u32(0) | ||
end)), | ||
u32(0), | ||
table.concat(map(files, function(v, k) | ||
return v.content | ||
end)), | ||
u32(0) | ||
} | ||
end | ||
|
||
local path_sep = package.config:sub(1, 1) | ||
local traverse_cmd = path_sep == "\\" and "dir /b " or "ls " | ||
|
||
local ignore = { -- Don't need the full list since we're only packing what's inside of lua/materials/models/resource/sound. | ||
[".*%.txt"] = true, | ||
[".*%.md"] = true, | ||
} | ||
|
||
---@generic T | ||
---@param val T? | ||
---@return T | ||
local function assert(val, msg) | ||
if not val then error(msg) end | ||
return val | ||
end | ||
|
||
---@param path string | ||
---@param callback fun(filename: string, path: string) | ||
local function iterFiles(path, callback) | ||
path = string.gsub(path, "/", path_sep) | ||
|
||
local dir = assert(io.popen(traverse_cmd .. path)) | ||
for file in dir:lines() do | ||
local full = path .. path_sep .. file | ||
for ignore in pairs(ignore) do | ||
if full:match(ignore) then | ||
goto skip | ||
end | ||
end | ||
|
||
local ext = file:match("%.(%w+)$") | ||
if ext then | ||
callback(file, full) | ||
else | ||
iterFiles(full, callback) | ||
end | ||
|
||
::skip:: | ||
end | ||
dir:close() | ||
end | ||
|
||
---@type { path: string, content: string }[] | ||
local files = {} | ||
|
||
---@param name string | ||
---@param path string | ||
local function handle(name, path) | ||
local handle = assert(io.open(path, "rb")) | ||
files[#files + 1] = { path = path, content = handle:read("*a") } | ||
handle:close() | ||
end | ||
|
||
iterFiles("lua", handle) | ||
|
||
local gma = pack( | ||
"WebAudio", | ||
"An addon that adds a WebAudio class to allow for server sync with client IGmodAudioChannels to make efficient & safe E2 Media URL Streams", | ||
"Vurv", | ||
files | ||
) | ||
|
||
local handle = assert(io.open(arg[1], "wb"), "Failed to create/overwrite output file") | ||
handle:write(gma) | ||
handle:close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.vscode | ||
.vs | ||
/readme_tables | ||
/readme_tables | ||
webaudio.gma |