161 lines
4.7 KiB
Text
161 lines
4.7 KiB
Text
--!strict
|
|
local datetime = require("@lune/datetime")
|
|
local fs = require("@lune/fs")
|
|
local net = require("@lune/net")
|
|
local process = require("@lune/process")
|
|
local serde = require("@lune/serde")
|
|
local stdio = require("@lune/stdio")
|
|
|
|
local progress_bar = require("./util/progress")
|
|
local result = require("./util/result")
|
|
local types = require("./types")
|
|
|
|
-- Returns an ISO 8601 date (YYYYmmddThhmmssZ)
|
|
local function iso_date_light(now: datetime.DateTime): string
|
|
return now:formatUniversalTime("%Y%m%dT%H%M%SZ")
|
|
end
|
|
|
|
local function make_pesde_manifest(version: string, scope: string): types.PesdeManifest
|
|
return {
|
|
name = scope,
|
|
version = version,
|
|
authors = { "jecs authors" },
|
|
repository = "https://git.devmarked.win/jecs-nightly",
|
|
license = "MIT",
|
|
includes = {
|
|
"init.luau",
|
|
"pesde.toml",
|
|
"README.md",
|
|
"CHANGELOG.md",
|
|
"LICENSE",
|
|
".luaurc",
|
|
},
|
|
|
|
target = {
|
|
environment = "luau",
|
|
lib = "jecs.luau",
|
|
},
|
|
|
|
indices = {
|
|
default = "https://github.com/daimond113/pesde-index",
|
|
},
|
|
}
|
|
end
|
|
|
|
local function make_wally_manifest(version: string, scope: string): types.WallyManifest
|
|
return {
|
|
package = {
|
|
name = scope,
|
|
version = version,
|
|
registry = "https://github.com/UpliftGames/wally-index",
|
|
realm = "shared",
|
|
license = "MIT",
|
|
include = {
|
|
"default.project.json",
|
|
"jecs.luau",
|
|
"wally.toml",
|
|
"README.md",
|
|
"CHANGELOG.md",
|
|
"LICENSE",
|
|
},
|
|
exclude = { "**" },
|
|
},
|
|
}
|
|
end
|
|
|
|
local function round_to(n: number, places: number)
|
|
local x = 10 ^ (places or 0)
|
|
return math.round(n * x) / x
|
|
end
|
|
|
|
--- Fetches the given file raw from the jecs github
|
|
local function fetch_raw(file: string): result.Identity<string>
|
|
local res = net.request(`https://raw.githubusercontent.com/Ukendio/jecs/refs/heads/main/{file}`)
|
|
if not res.ok then
|
|
return result(false, `Not ok: {res.statusMessage} @ {res.statusCode}`)
|
|
end
|
|
return result(true, res.body)
|
|
end
|
|
|
|
local function release(origin: string, scopes: { wally: string, pesde: string }, dry: boolean?): result.Identity<nil>
|
|
local begin = os.clock()
|
|
local now = datetime.now()
|
|
|
|
local progress = progress_bar
|
|
.new()
|
|
:withStage("init", "Initializing")
|
|
:withStage("pull", "Pull latest version")
|
|
:withStage("prepare", "Preparing manifests")
|
|
:withStage("release (pesde)", "Releasing on pesde")
|
|
:withStage("release (wally)", "Releasing on wally")
|
|
progress:start()
|
|
|
|
dry = dry or true
|
|
|
|
if not fs.metadata(origin).exists then
|
|
progress:stop()
|
|
stdio.ewrite(`🔥 {origin} is not a valid directory which exists.\n`)
|
|
return result(false, `{origin} is not a valid directory which exists.`)
|
|
end
|
|
|
|
progress:nextStage()
|
|
|
|
local wally_contents = fetch_raw("wally.toml")
|
|
if not wally_contents.ok then
|
|
progress:stop()
|
|
stdio.ewrite(`🔥 Couldn't get the jecs wally manifest:\n{wally_contents.err}\n`)
|
|
return result(false, `Couldn't get the jecs wally manifest:\n{wally_contents.err}`)
|
|
end
|
|
|
|
local parsed: types.WallyManifest = serde.decode("toml", wally_contents.val)
|
|
local version = `{parsed.package.version}-nightly.{iso_date_light(now)}`
|
|
|
|
progress:nextStage()
|
|
|
|
do
|
|
local manifest = make_pesde_manifest(version, scopes.pesde)
|
|
local encoded = serde.encode("toml", manifest)
|
|
fs.writeFile(`{origin}/pesde.toml`, encoded)
|
|
end
|
|
|
|
do
|
|
local manifest = make_wally_manifest(version, scopes.wally)
|
|
local encoded = serde.encode("toml", manifest)
|
|
fs.writeFile(`{origin}/wally.toml`, encoded)
|
|
end
|
|
|
|
progress:nextStage()
|
|
|
|
local cwd = process.cwd .. origin
|
|
|
|
if not dry then
|
|
process.spawn("pesde", { "publish", "-y" }, { cwd = cwd })
|
|
else
|
|
process.spawn("pesde", { "publish", "-d", "-y" }, { cwd = cwd })
|
|
end
|
|
|
|
progress:nextStage()
|
|
|
|
if not dry then
|
|
process.spawn("wally", { "publish" }, { cwd = cwd })
|
|
else
|
|
process.spawn("wally", { "package", "--output", "wally.tar.gz" }, { cwd = cwd })
|
|
end
|
|
|
|
progress:stop()
|
|
|
|
local took = round_to((os.clock() - begin) * 1_000, 2)
|
|
if not dry then
|
|
print(`🚀 Published packages {stdio.style("dim")}(took {took}ms){stdio.style("reset")}`)
|
|
else
|
|
print(`📦 Packaged packages {stdio.style("dim")}(took {took}ms){stdio.style("reset")}`)
|
|
end
|
|
print({
|
|
pesde = `{scopes.pesde}@{version}`,
|
|
wally = `{scopes.wally}@{version}`,
|
|
})
|
|
|
|
return result(true, nil)
|
|
end
|
|
|
|
return release
|