This commit is contained in:
kento2 2026-08-19 02:15:15 +02:00
parent 46978ae799
commit ce56c6e105
53 changed files with 776 additions and 891 deletions

37
rules/BUILD Normal file
View file

@ -0,0 +1,37 @@
load("//rules:dev_server.bzl", "dev_server")
load("//rules:fetch_file.bzl", "fetch_file")
dev_server(
name = "dev",
server_jar = ":papermc",
plugins = [
":luckperms",
":viaversion",
":viabackwards",
],
local_plugins = [
"//core/bukkit:plugin",
"//buildserver/configurator:plugin",
],
)
fetch_file(
name = "papermc",
filename = "paper.jar",
url = "https://fill-data.papermc.io/v1/objects/5953a1f1deaa3572be420c3a5b18406c4b752412a78be4acab7c8b467633caed/paper-26.2-100.jar",
)
fetch_file(
name = "luckperms",
filename = "LuckPerms.jar",
url = "https://download.luckperms.net/1652/bukkit/loader/LuckPerms-Bukkit-5.5.65.jar",
)
fetch_file(
name = "viaversion",
filename = "ViaVersion.jar",
url = "https://hangarcdn.papermc.io/plugins/ViaVersion/ViaVersion/versions/5.11.0/PAPER/ViaVersion-5.11.0.jar"
)
fetch_file(
name = "viabackwards",
filename = "ViaBackwards.jar",
url = "https://hangarcdn.papermc.io/plugins/ViaVersion/ViaBackwards/versions/5.11.0/PAPER/ViaBackwards-5.11.0.jar"
)

51
rules/dev_server.bzl Normal file
View file

@ -0,0 +1,51 @@
def _dev_server_impl(ctx):
script = ctx.actions.declare_file(ctx.label.name + "_runner")
content = """
#!/bin/sh
set -eu
cp -f '%s' server.jar
printf eula=true > eula.txt
mkdir -p plugins
rm -f plugins/*.jar
for plugin in %s
do
cp -v \"$plugin\" plugins/
done
mkdir -p postgres-data
podman run \
--rm \
--name scrow-postgres-dev \
-p 5432:5432 \
-v ./postgres-data/:/data \
-e POSTGRES_USER=postgres \
-e POSTGRES_HOST_AUTH_METHOD=trust \
-d \
docker.io/postgres:alpine || true
echo "Starting paper server in $PWD"
exec env HOST_POSTGRES='jdbc:postgresql://127.0.0.1:5432/postgres' java -jar server.jar --nogui %s
""" % (
ctx.file.server_jar.short_path,
" ".join([p.short_path for p in ctx.files.plugins]),
" ".join(["--add-plugin %s" % p.short_path for p in ctx.files.local_plugins]),
)
ctx.actions.write(
output = script,
content = content,
is_executable = True,
)
return DefaultInfo(
executable = script,
runfiles = ctx.runfiles(files = [ctx.file.server_jar] + ctx.files.plugins + ctx.files.local_plugins)
)
dev_server = rule(
implementation = _dev_server_impl,
executable = True,
attrs = {
"server_jar": attr.label(allow_single_file = True, mandatory = True),
"plugins": attr.label_list(),
"local_plugins": attr.label_list(),
},
)

22
rules/fetch_file.bzl Normal file
View file

@ -0,0 +1,22 @@
# TODO implement sha256sum attribute + checksum verification
def _fetch_file_impl(ctx):
out_file = ctx.actions.declare_file(ctx.attr.filename)
ctx.actions.run_shell(
outputs = [out_file],
command = "curl -Lso \"$1\" \"$2\"",
arguments = [out_file.path, ctx.attr.url],
execution_requirements = {
"requires-network": "1",
},
progress_message = "Downloading plugin %s" % ctx.attr.filename,
)
return [DefaultInfo(files = depset([out_file]))]
fetch_file = rule(
implementation = _fetch_file_impl,
attrs = {
"url": attr.string(mandatory = True),
"filename": attr.string(mandatory = True),
},
)

68
rules/publish_plugin.bzl Normal file
View file

@ -0,0 +1,68 @@
# see https://forgejo.org/docs/latest/user/packages/generic/
# We need to delete the previous version to
# FIXME we're leaking credentials in the process listing(args can be seen in ps(1) output)
# solvable by using a temporary .netrc file(create with umask 0600 or smth)
_TEMPLATE = """#!/bin/sh
set -eux
: ${GENERIC_USERNAME:=__USERNAME__}
: ${GENERIC_PASSWORD:=__PASSWORD__}
: ${GENERIC_REPO:=__REPOSITORY__}
URL="$GENERIC_REPO"'/__PACKAGE__/UNVERSIONED/__FILENAME__'
CREDS="$GENERIC_USERNAME:$GENERIC_PASSWORD"
delete_previous_version() {
curl \
--fail \
--user "$CREDS" \
-X DELETE \
"$URL" || true
}
publish_new_version() {
curl \
--fail \
--user "$CREDS" \
--upload-file '__SOURCE__' \
"$URL"
}
echo "Deleting previous version at $URL"
delete_previous_version || echo "Note: 404 is expected if this is the first published version"
echo "Pushing new version to $URL"
publish_new_version
"""
def _publish_plugin_impl(ctx):
script = ctx.actions.declare_file(ctx.label.name + "_publisher")
src = ctx.attr.src[DefaultInfo].files.to_list()[0]
repository = ctx.var.get("generic_repo", "")
username = ctx.var.get("generic_user", "")
password = ctx.var.get("generic_password", "")
ctx.actions.write(
output = script,
is_executable = True,
content = _TEMPLATE
.replace("__USERNAME__", username)
.replace("__PASSWORD__", password)
.replace("__REPOSITORY__", repository)
.replace("__PACKAGE__", ctx.attr.package)
.replace("__SOURCE__", src.short_path)
.replace("__FILENAME__", ctx.attr.filename)
)
return DefaultInfo(
executable = script,
runfiles = ctx.runfiles(files = [src]),
)
publish_plugin = rule(
implementation = _publish_plugin_impl,
executable = True,
attrs = {
"src": attr.label(allow_single_file = True, mandatory = True),
"package": attr.string(mandatory = True),
"filename": attr.string(mandatory = True),
},
)