update or new release pattern

This commit is contained in:
Joe Kaufeld 2025-02-27 11:50:17 -05:00
parent 428005dbed
commit 438d7a56f2
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/checkout@v2
- uses: https://github.com/actions/setup-python@v4 - uses: https://github.com/actions/setup-python@v4
with: with:
python-version: '3.11.x' python-version: '3.12.x'
- name: Install Env - name: Install Env
# this should be all we need because shiv will download the deps itself # this should be all we need because shiv will download the deps itself
run: | run: |
@ -27,7 +27,8 @@ jobs:
echo ${{ env.VERSION }} echo ${{ env.VERSION }}
- name: Build the sucker - name: Build the sucker
run: | 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 make build
- name: Create release! - name: Create release!
run: | run: |

View file

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

View file

@ -4,7 +4,7 @@
Use this template by installing `copier` and running: Use this template by installing `copier` and running:
```shell ```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: After that, you can set up the system with:

View file

@ -11,8 +11,9 @@ httpx = "^0.23.0"
click = "^8.1.3" click = "^8.1.3"
rich = "^12.5.1" rich = "^12.5.1"
art = "^5.9" art = "^5.9"
python-dotenv = "^1.0.1"
[tool.poetry.dev-dependencies] [poetry.group.dev.dependencies]
poetry = "^1.1.14" poetry = "^1.1.14"
black = "^22.6.0" black = "^22.6.0"
@ -21,4 +22,4 @@ requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api" build-backend = "poetry.core.masonry.api"
[tool.poetry.plugins."console_scripts"] [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 code
import io import io
import random
import string
import sys import sys
import uuid
import art import art
import click import click
import httpx from rich import console as rich_console, pretty, traceback
from rich import console as rich_console, pretty
from rich.status import Status
from rich.traceback import install
from shiv.bootstrap import current_zipfile
import src import src
from src.utils import _install, _uninstall, update_from_gitea
def print_help(): class RichCommand(click.Group):
ctx = click.get_current_context()
click.echo(ctx.get_help())
ctx.exit()
class RichGroup(click.Group):
def format_usage(self, ctx, formatter): def format_usage(self, ctx, formatter):
sio = io.StringIO() sio = io.StringIO()
console = rich_console.Console(file=sio, force_terminal=True) console = rich_console.Console(file=sio, force_terminal=True)
@ -32,8 +20,8 @@ class RichGroup(click.Group):
formatter.write(sio.getvalue()) formatter.write(sio.getvalue())
@click.group( @click.command(
cls=RichGroup, cls=RichCommand,
context_settings=dict(help_option_names=["-h", "--help", "--halp"]), context_settings=dict(help_option_names=["-h", "--help", "--halp"]),
) )
@click.pass_context @click.pass_context
@ -50,7 +38,21 @@ class RichGroup(click.Group):
default=False, default=False,
help="Launch a REPL for testing.", 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. Launch [[ project_name ]] or drop into a command line REPL.
""" """
@ -61,57 +63,23 @@ def main(ctx, update, shell):
banner = art.text2art("[[ module_name ]]") banner = art.text2art("[[ module_name ]]")
pretty.install() # type: ignore pretty.install() # type: ignore
install() # traceback handler traceback.install() # traceback handler
code.interact(local=globals(), banner=banner) code.interact(local=globals(), banner=banner)
sys.exit() sys.exit()
elif ctx.invoked_subcommand is None: if install:
print_help() _install()
sys.exit()
if uninstall:
_uninstall()
sys.exit()
main()
@main.command() def main() -> None:
def uuid4(): """Put main program functionality here."""
"""Generate a random UUID4.""" print("Nothing here...")
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']}! 🎉")
if __name__ == "__main__": if __name__ == "__main__":
main() entrypoint()