Skip to content

Commit

Permalink
Clean up make_lib_releases, and move packaging code into packager
Browse files Browse the repository at this point in the history
  • Loading branch information
gaymeowing committed Aug 14, 2024
1 parent 33dce15 commit cb46bc7
Showing 1 changed file with 26 additions and 112 deletions.
138 changes: 26 additions & 112 deletions scripts/make_lib_releases.luau
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,39 @@
local process = require("@lune/process")
process.env.RUST_BACKTRACE = "full"

local impl_module_source_prop = require("impl_module_source_prop")
local DateTime = require("@lune/DateTime")
local diff_reader = require("diff_reader")
local process = require("@lune/process")
local build_rbxm = require("build_rbxm")
local roblox = require("@lune/roblox")
local modulify = require("modulify")
local depgraph = require("depgraph")
local packager = require("packager")
local libinfo = require("libinfo")
local summon = require("summon")
local fs = require("@lune/fs")
local zip = require("zip")

type Commit = {
author: string,
title: string,
hash: string,
date: number,
url: string,
}

local GIT_LOG_PATTERN = "commit (%x+)\nAuthor: (.-) <.->\nDate:%s+(.-)\n\n%s+(.-)\n?\n"
local GIT_DATE_FORMAT = "(%w+) (%w+) (%d+) (%d+):(%d+):(%d+) (%d+) ([?%+%-]%d%d)(%d%d)"
local BASE_REPO_URL = "https://github.com/kalrnlo/rbxlibs"
local BASE_COMMIT_URL = `{BASE_REPO_URL}/commits/`

local RELEASES = summon("gh", { "release", "list", "--repo", "kalrnlo/rbxlibs", "--limit", "1000" })
local RELEASES = summon("gh", "release list --repo kalrnlo/rbxlibs --limit 1000")
local MONTHS = table.freeze({
Jan = 1, Feb = 2, Mar = 3, Apr = 4, May = 5, Jun = 6,
Jul = 7, Aug = 8, Sep = 9, Oct = 10, Nov = 11, Dec = 12
}) :: { [string]: number }
local BUILT_LIBS = {} :: { [string]: modulify.ModuleScript }
local LIBS_CHANGED = diff_reader.libs()
local RBXLIBS_CREATION_DATE = DateTime.fromUniversalTime({
year = 2024, day = 24, month = 6,
hour = 8, minute = 0, second = 0,
}).unixTimestamp
local RELEASE_LIBS: { string }
local ARGS = process.args

-- local CREATE = roblox.Instance.new
local GMATCH = string.gmatch
Expand All @@ -56,13 +57,12 @@ local function get_latest_release_time(lib: string): number
end
end
end
return 0
return RBXLIBS_CREATION_DATE
end

local function parse_git_date(date: string): number
-- git log date format: "Day Mon DD HH:MM:SS YYYY +-ZZZZ"
local _, month, day, hour, minutes, seconds, year, zone_hours, zone_minutes = MATCH(date, GIT_DATE_FORMAT)
print(month, day, hour, minutes, seconds, year, zone_hours, zone_minutes)
local zone_minutes = tonumber(zone_minutes)
local zone_hours = tonumber(zone_hours)
local seconds = tonumber(seconds)
Expand All @@ -88,12 +88,11 @@ local function parse_git_date(date: string): number
end

local function get_commits_after_time(lib: string, time: number): { Commit }
local log = summon("git", { "log", "--after", tostring(time), "--", `libs/{lib}` })
local log = summon("git", `log --after {time} -- libs/{lib}`)
local commits = {}

for hash, author, date, title in GMATCH(log, GIT_LOG_PATTERN) do
table.insert(commits, {
url = `{BASE_COMMIT_URL}{hash}`,
date = parse_git_date(date),
author = author,
title = title,
Expand All @@ -103,119 +102,34 @@ local function get_commits_after_time(lib: string, time: number): { Commit }
return commits
end

local args = table.clone(process.args)

-- with lune run, required scripts cant implement a property so
-- were doing it a jank way via an arg
local implprop_index = table.find(args, "implprop")

if implprop_index then
table.remove(args, implprop_index)
local SOURCES = {} :: {[roblox.Instance]: string}

roblox.implementProperty(
"ModuleScript", "Source",
function(module)
return SOURCES[module] or ""
end,
function(module, new_val)
if type(new_val) == "string" then
SOURCES[module] = new_val
else
error("property source must be of type string!")
end
end
)
end

if table.find(args, "all") then
LIBS_CHANGED = fs.readDir("libs")
elseif #args ~= 0 then
table.move(args, 1, #args, #LIBS_CHANGED + 1, LIBS_CHANGED)
end

local OUTPUT_DIR = "output"

if fs.isDir(OUTPUT_DIR) then
fs.removeDir(OUTPUT_DIR)
local function get_pr_for_commit(commit: Commit): number?
return tonumber(MATCH(commit.title, "Merge pull request #(%d+).-"))
end
fs.writeDir(OUTPUT_DIR)

local function get_or_create_module(lib: string): modulify.ModuleScript
local built = BUILT_LIBS[lib]

if built then
return built
else
local module = modulify(lib)
BUILT_LIBS[lib] = module
return module
end
end
RELEASE_LIBS = if table.find(ARGS, "all") then
fs.readDir("libs")
elseif #ARGS ~= 0 then
table.move(ARGS, 1, #ARGS, #LIBS_CHANGED + 1, LIBS_CHANGED)
else
LIBS_CHANGED

print(LIBS_CHANGED)
impl_module_source_prop()

for _, lib in LIBS_CHANGED do
for _, lib in RELEASE_LIBS do
local latest_release_time = get_latest_release_time(lib)
local commits = get_commits_after_time(lib, latest_release_time)
--local package_libinfo = packager.package(lib)
local libinfo = libinfo(lib)

local version = libinfo.version

local lib_output_dir = `{OUTPUT_DIR}/{lib}-{version}`
local lib_output_dir_with_deps = `{lib_output_dir}-deps`
local depinfo = depgraph[lib]
local libdir = `libs/{lib}`
local has_deps = depinfo.has_deps
for _, commit in commits do
local pr = get_pr_for_commit(commit)

fs.writeDir(lib_output_dir)

local initdir = `{libdir}/init`
local initdir_exists = fs.isDir(initdir)
local initext = if initdir_exists then initdir else `{initdir}.luau`

if fs.isDir(initdir) then
fs.copy(initdir, lib_output_dir, true)
else
fs.copy(initext, `{lib_output_dir}/init.luau`, true)
end

--zip(lib_output_dir, `{lib_output_dir}.zip`)
local module = get_or_create_module(lib)
local rbxm_with_deps: string

fs.writeFile(`{lib_output_dir}.rbxm`, build_rbxm(module))

if has_deps then
fs.writeDir(lib_output_dir_with_deps)

if initdir_exists then
fs.copy(lib_output_dir, `{lib_output_dir_with_deps}/{lib}`, true)
else
fs.copy(`{lib_output_dir}/init.luau`, `{lib_output_dir_with_deps}/{lib}.luau`, true)
end
local modules = { module }

for _, deplib in depinfo.deep do
table.insert(modules, get_or_create_module(deplib))
local deplibdir = `libs/{deplib}`
local initdir = `{deplibdir}/init`
local initdir_exists = fs.isDir(initdir)
local initext = if initdir_exists then initdir else `{initdir}.luau`

if fs.isDir(initdir) then
fs.copy(initdir, `{lib_output_dir_with_deps}/{deplib}`, true)
else
fs.copy(initext, `{lib_output_dir_with_deps}/init.luau`, true)
end
if pr then
print(pr)
end

rbxm_with_deps = roblox.serializeModel(modules)
fs.writeFile(`{lib_output_dir_with_deps}.rbxm`, rbxm_with_deps)
end



end

process.exit()

0 comments on commit cb46bc7

Please sign in to comment.