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

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),
},
)