update for new release pattern

This commit is contained in:
Joe Kaufeld 2025-02-27 11:50:17 -05:00
parent 428005dbed
commit c70db47d70
6 changed files with 42 additions and 70 deletions

View file

@ -14,7 +14,7 @@ jobs:
- uses: https://github.com/actions/checkout@v2
- uses: https://github.com/actions/setup-python@v4
with:
python-version: '3.11.x'
python-version: '3.12.x'
- name: Install Env
# this should be all we need because shiv will download the deps itself
run: |
@ -27,7 +27,8 @@ jobs:
echo ${{ env.VERSION }}
- name: Build the sucker
run: |
sed -i -e "s/?????/${{ env.VERSION }}/g" src/__init__.py
sed -i -e "s/??version??/${{ env.VERSION }}/g" src/__init__.py
sed -i -e "s/??GITEA_TOKEN??/${{ secrets.READ_KEY }}/g" src/__init__.py
make build
- name: Create release!
run: |

View file

@ -1,3 +1,6 @@
activate:
source .venv/bin/activate
setup:
python src/poetry2setup.py > setup.py

View file

@ -4,7 +4,7 @@
Use this template by installing `copier` and running:
```shell
copier https://git.joekaufeld.com/jkaufeld/copier-shiv.git [dir]
copier copy https://git.joekaufeld.com/jkaufeld/copier-shiv.git [dir]
```
After that, you can set up the system with:

View file

@ -11,8 +11,9 @@ httpx = "^0.23.0"
click = "^8.1.3"
rich = "^12.5.1"
art = "^5.9"
python-dotenv = "^1.0.1"
[tool.poetry.dev-dependencies]
[poetry.group.dev.dependencies]
poetry = "^1.1.14"
black = "^22.6.0"
@ -21,4 +22,4 @@ requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
[tool.poetry.plugins."console_scripts"]
"[[ module_name ]]" = "src.cli:main"
"[[ module_name ]]" = "src.cli:entrypoint"

View file

@ -1 +0,0 @@
__version__ = "?????" # will be replaced during build by CI

View file

@ -1,28 +1,16 @@
import code
import io
import random
import string
import sys
import uuid
import art
import click
import httpx
from rich import console as rich_console, pretty
from rich.status import Status
from rich.traceback import install
from shiv.bootstrap import current_zipfile
from rich import console as rich_console, pretty, traceback
import src
from src.utils import _install, _uninstall, update_from_gitea
def print_help():
ctx = click.get_current_context()
click.echo(ctx.get_help())
ctx.exit()
class RichGroup(click.Group):
class RichCommand(click.Group):
def format_usage(self, ctx, formatter):
sio = io.StringIO()
console = rich_console.Console(file=sio, force_terminal=True)
@ -32,8 +20,8 @@ class RichGroup(click.Group):
formatter.write(sio.getvalue())
@click.group(
cls=RichGroup,
@click.command(
cls=RichCommand,
context_settings=dict(help_option_names=["-h", "--help", "--halp"]),
)
@click.pass_context
@ -50,7 +38,21 @@ class RichGroup(click.Group):
default=False,
help="Launch a REPL for testing.",
)
def main(ctx, update, shell):
@click.option(
"--install",
"install",
is_flag=True,
default=False,
help="Install as a service on Ubuntu systems."
)
@click.option(
"--uninstall",
"uninstall",
is_flag=True,
default=False,
help="Uninstall as an Ubuntu service."
)
def entrypoint(update, shell, install, uninstall):
"""
Launch [[ project_name ]] or drop into a command line REPL.
"""
@ -61,57 +63,23 @@ def main(ctx, update, shell):
banner = art.text2art("[[ module_name ]]")
pretty.install() # type: ignore
install() # traceback handler
traceback.install() # traceback handler
code.interact(local=globals(), banner=banner)
sys.exit()
elif ctx.invoked_subcommand is None:
print_help()
if install:
_install()
sys.exit()
if uninstall:
_uninstall()
sys.exit()
main()
@main.command()
def uuid4():
"""Generate a random UUID4."""
click.echo(uuid.uuid4())
def update_from_gitea():
"""Get the newest release from Gitea and install it."""
status = Status("Checking for new release...")
status.start()
response = httpx.get(
"https://git.joekaufeld.com/api/v1/repos/jkaufeld/[[ repo_name ]]/releases/latest"
)
if response.status_code != 200:
status.stop()
click.echo(
f"Something went wrong when talking to Gitea; got a"
f" {response.status_code} with the following content:\n"
f"{response.content}"
)
return
status.update("Checking for new release...")
release_data = response.json()
if release_data["tag_name"] == src.__version__:
status.stop()
click.echo(
"Server version is the same as current version; nothing to update."
)
return
status.update("Updating...")
url = release_data["assets"][0]["browser_download_url"]
with current_zipfile() as archive:
with open(archive.filename, "wb") as f, httpx.stream(
"GET", url, follow_redirects=True
) as r:
for line in r.iter_bytes():
f.write(line)
status.stop()
click.echo(f"Updated to {release_data['tag_name']}! 🎉")
def main() -> None:
"""Put main program functionality here."""
print("Nothing here...")
if __name__ == "__main__":
main()
entrypoint()