# HG changeset patch # User Conrad Hoffmann # Date 1736167416 -3600 # Mon Jan 06 13:43:36 2025 +0100 # Node ID 9bc595e93baaa8ae130035f4aaa4df61572c4b9b # Parent c8355583428714f19a683a34e004a452a34fe294 Convert to new shared asset distribution This comes with the following changes: * All executables renamed to "service.sr.ht-exe" * Makefile - becomes standalone, setting SRHT_PATH no longer required - expects SCSS in $(PREFIX)/share/sourcehut - installs assets in $(PREFIX)/share/sourcehut * Python module - no longer contains any static assets (except for the GQL schema) - setup.py reduced to stub - no longer calls `make` when building diff --git a/.hgignore b/.hgignore --- a/.hgignore +++ b/.hgignore @@ -16,5 +16,5 @@ .pgp build *_gen.go -hgsrht-keys/hgsrht-keys -api/api +hg.sr.ht-keys +hg.sr.ht-api diff --git a/Makefile b/Makefile --- a/Makefile +++ b/Makefile @@ -1,15 +1,69 @@ -SRHT_PATH?=/usr/lib/python3.12/site-packages/srht -MODULE=hgsrht/ -include ${SRHT_PATH}/Makefile +PREFIX?=/usr/local +BINDIR?=$(PREFIX)/bin +LIBDIR?=$(PREFIX)/lib +SHAREDIR?=$(PREFIX)/share/sourcehut + +SERVICE=hg.sr.ht +STATICDIR=$(SHAREDIR)/static/$(SERVICE) + +SASSC?=sassc +SASSC_INCLUDE=-I$(SHAREDIR)/scss/ + +BINARIES=\ + $(SERVICE)-api \ + $(SERVICE)-keys + +all: all-bin all-share + +install: install-bin install-share + +clean: clean-bin clean-share + +all-bin: $(BINARIES) + +all-share: static/main.min.css -all: api hgsrht-keys +install-bin: all-bin + mkdir -p $(BINDIR) + for bin in $(BINARIES); \ + do \ + install -Dm755 $$bin $(BINDIR)/; \ + done + +install-share: all-share + mkdir -p $(STATICDIR) + install -Dm644 static/*.css $(STATICDIR) + install -Dm644 api/graph/schema.graphqls $(SHAREDIR)/$(SERVICE).graphqls + +clean-bin: + rm -f $(BINARIES) -api: +clean-share: + rm -f static/main.min.css static/main.css + +.PHONY: all all-bin all-share +.PHONY: install install-bin install-share +.PHONY: clean clean-bin clean-share + +static/main.css: scss/main.scss + mkdir -p $(@D) + $(SASSC) $(SASSC_INCLUDE) $< $@ + +static/main.min.css: static/main.css + minify -o $@ $< + cp $@ $(@D)/main.min.$$(sha256sum $@ | cut -c1-8).css + +api/loaders/*_gen.go &: api/loaders/generate.go api/loaders/gen go.sum cd api && go generate ./loaders + +api/graph/api/generated.go: api/graph/schema.graphqls api/graph/generate.go go.sum api/loaders/*_gen.go cd api && go generate ./graph - cd api && go build -hgsrht-keys: - cd hgsrht-keys && go build +$(SERVICE)-api: api/graph/api/generated.go api/loaders/*_gen.go + go build -o $@ ./api -.PHONY: all api hgsrht-keys +$(SERVICE)-keys: + cd keys && go build -o ../$@ + +# Always rebuild +.PHONY: $(BINARIES) diff --git a/api/graph/schema.resolvers.go b/api/graph/schema.resolvers.go --- a/api/graph/schema.resolvers.go +++ b/api/graph/schema.resolvers.go @@ -515,7 +515,7 @@ // Version is the resolver for the version field. func (r *queryResolver) Version(ctx context.Context) (*model.Version, error) { conf := config.ForContext(ctx) - sshUser, _ := conf.Get("git.sr.ht::dispatch", "/usr/bin/hgsrht-keys") + sshUser, _ := conf.Get("git.sr.ht::dispatch", "/usr/bin/hg.sr.ht-keys") sshUser = strings.Split(sshUser, ":")[0] return &model.Version{ diff --git a/config.example.ini b/config.example.ini --- a/config.example.ini +++ b/config.example.ini @@ -99,7 +99,7 @@ disable-publishing=false # # A post-update script which is installed in every mercurial repo. -changegroup-script=/usr/bin/hgsrht-hook-changegroup +changegroup-script=/usr/bin/hg.sr.ht-hook-changegroup # # hg.sr.ht's OAuth client ID and secret for meta.sr.ht # Register your client at meta.example.org/oauth @@ -154,7 +154,7 @@ # and is expected to emit an AuthorizedKeys file. # # Uncomment the relevant lines to enable the various sr.ht dispatchers. -/usr/bin/hgsrht-keys=hg:hg +/usr/bin/hg.sr.ht-keys=hg:hg [meta.sr.ht] origin=http://meta.sr.ht.local diff --git a/hgsrht-clonebundles b/hg.sr.ht-clonebundles rename from hgsrht-clonebundles rename to hg.sr.ht-clonebundles diff --git a/hgsrht-hook-changegroup b/hg.sr.ht-hook-changegroup rename from hgsrht-hook-changegroup rename to hg.sr.ht-hook-changegroup diff --git a/hgsrht-initdb b/hg.sr.ht-initdb rename from hgsrht-initdb rename to hg.sr.ht-initdb diff --git a/hgsrht-install-ext b/hg.sr.ht-install-ext rename from hgsrht-install-ext rename to hg.sr.ht-install-ext --- a/hgsrht-install-ext +++ b/hg.sr.ht-install-ext @@ -14,7 +14,7 @@ publishing_disabled = cfgb("hg.sr.ht", "disable-publishing", False) changegroup_script = cfg("hg.sr.ht", "changegroup-script", - "/usr/bin/hgsrht-hook-changegroup") + "/usr/bin/hg.sr.ht-hook-changegroup") def get_partial_hgrc_path(name): return f'/etc/sr.ht/hgrcs/{name}' diff --git a/hgsrht-migrate b/hg.sr.ht-migrate rename from hgsrht-migrate rename to hg.sr.ht-migrate diff --git a/hgsrht-periodic b/hg.sr.ht-periodic rename from hgsrht-periodic rename to hg.sr.ht-periodic diff --git a/hgsrht-shell b/hg.sr.ht-shell old mode 100644 new mode 100755 rename from hgsrht-shell rename to hg.sr.ht-shell --- a/hgsrht-shell +++ b/hg.sr.ht-shell @@ -18,7 +18,7 @@ log_to_console = bool(os.getenv('LOG2CONSOLE')) if not log_to_console: try: - _logf = open("/var/log/hgsrht-shell", "a") + _logf = open("/var/log/hg.sr.ht-shell", "a") except Exception as ex: sys.stderr.write("Unable to open log for writing\n") sys.stderr.write(str(ex) + "\n") @@ -59,13 +59,13 @@ b'hooks', b'pretxnopen.hgsrht-shell', b'python:__main__.rejectpush', - b'hgsrht-shell', + b'hg.sr.ht-shell', ) req.ui.setconfig( b'hooks', b'prepushkey.hgsrht-shell', b'python:__main__.rejectpush', - b'hgsrht-shell', + b'hg.sr.ht-shell', ) dispatch.dispatch(req) diff --git a/hgsrht-upgraderepos b/hg.sr.ht-upgraderepos rename from hgsrht-upgraderepos rename to hg.sr.ht-upgraderepos diff --git a/hgsrht/blueprints/internal.py b/hgsrht/blueprints/internal.py --- a/hgsrht/blueprints/internal.py +++ b/hgsrht/blueprints/internal.py @@ -1,5 +1,5 @@ """ -This blueprint is used internally by hgsrht-shell to speed up SSH access, by +This blueprint is used internally by hg.sr.ht-shell to speed up SSH access, by taking advantage of the database connection already established by the web app. """ import base64 diff --git a/hgsrht/submit.py b/hgsrht/submit.py --- a/hgsrht/submit.py +++ b/hgsrht/submit.py @@ -71,7 +71,7 @@ def get_clone_url(self): origin = get_origin("hg.sr.ht", external=True) - hg_user = cfg("git.sr.ht::dispatch", "/usr/bin/hgsrht-keys", "hg:hg").split(":")[0] + hg_user = cfg("git.sr.ht::dispatch", "/usr/bin/hg.sr.ht-keys", "hg:hg").split(":")[0] owner_name = self.repo.owner.canonical_name repo_name = self.repo.name if self.repo.visibility == RepoVisibility.PRIVATE: diff --git a/hgsrht/urls.py b/hgsrht/urls.py --- a/hgsrht/urls.py +++ b/hgsrht/urls.py @@ -2,7 +2,7 @@ from scmsrht.urls import get_clone_urls origin_url = cfg("hg.sr.ht", "origin") -hg_user = cfg("git.sr.ht::dispatch", "/usr/bin/hgsrht-keys", "hg:hg").split(":")[0] +hg_user = cfg("git.sr.ht::dispatch", "/usr/bin/hg.sr.ht-keys", "hg:hg").split(":")[0] ssh_url_root = f'ssh://{hg_user}@' def clone_urls(repo): diff --git a/keys/main.go b/keys/main.go --- a/keys/main.go +++ b/keys/main.go @@ -11,13 +11,13 @@ ) func main() { - // hgsrht-keys is run by sshd to generate an authorized_key file on stdout. + // hg.sr.ht-keys is run by sshd to generate an authorized_key file on stdout. // In order to facilitate this, we do one of two things: // - Attempt to fetch the cached key info from Redis (preferred) // - Fetch the key from meta.sr.ht and store it in SQL and Redis (slower) service := "hg.sr.ht" - shellName := "hgsrht-shell" - logFile := "/var/log/hgsrht-keys" + shellName := "hg.sr.ht-shell" + logFile := "/var/log/hg.sr.ht-keys" var ( config ini.File diff --git a/pyproject.toml b/pyproject.toml --- a/pyproject.toml +++ b/pyproject.toml @@ -31,22 +31,20 @@ "hgsrht.blueprints.api", "hgsrht.hgext", "hgsrht.hgrcs", - "hgsrht.static", - "hgsrht.static.icons", "hgsrht.templates", "hgsrht.templates.macros", "hgsrht.templates.partials", "hgsrht.types", ] script-files = [ - "hgsrht-clonebundles", - "hgsrht-hook-changegroup", - "hgsrht-initdb", - "hgsrht-install-ext", - "hgsrht-migrate", - "hgsrht-periodic", - "hgsrht-shell", - "hgsrht-upgraderepos" + "hg.sr.ht-clonebundles", + "hg.sr.ht-hook-changegroup", + "hg.sr.ht-initdb", + "hg.sr.ht-install-ext", + "hg.sr.ht-migrate", + "hg.sr.ht-periodic", + "hg.sr.ht-shell", + "hg.sr.ht-upgraderepos" ] [tool.setuptools.package-data] "hgsrht" = ['default_query.graphql', 'schema.graphqls'] @@ -54,7 +52,5 @@ "hgsrht.templates" = ['*.html'] "hgsrht.templates.macros" = ['*.html'] "hgsrht.templates.partials" = ['*.html'] -"hgsrht.static" = ['*'] -"hgsrht.static.icons" = ['*'] [tool.setuptools_scm] diff --git a/setup.py b/setup.py --- a/setup.py +++ b/setup.py @@ -1,16 +1,3 @@ -#!/usr/bin/env python3 from setuptools import setup -import subprocess -import os -import sys -import importlib.resources - -with importlib.resources.path('srht', 'Makefile') as f: - srht_path = f.parent.as_posix() - -make = os.environ.get("MAKE", "make") -subp = subprocess.run([make, "SRHT_PATH=" + srht_path]) -if subp.returncode != 0: - sys.exit(subp.returncode) setup() diff --git a/static b/static deleted file mode 120000 --- a/static +++ /dev/null @@ -1,1 +0,0 @@ -hgsrht/static/ \ No newline at end of file