Skip to content

Commit

Permalink
🔨🔧 add invoke tasks to tox CI/CD setup for self-hosted publishing.
Browse files Browse the repository at this point in the history
Signed-off-by: rjdbcm <[email protected]>
  • Loading branch information
rjdbcm committed Aug 14, 2024
1 parent 68c5f71 commit e0550e2
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
1 change: 1 addition & 0 deletions ozi/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
source_files = [
'__init__.py',
'__main__.py',
'tasks.py',
]
foreach file : files(source_files)
fs.copyfile(file)
Expand Down
54 changes: 54 additions & 0 deletions ozi/tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from __future__ import annotations

import sys
from pathlib import Path

from invoke.context import Context
from invoke.tasks import call
from invoke.tasks import task


@task
def sign_log(c: Context, suite: str | None = None) -> None:
banned = './'
if not suite:
return print('No suite target provided', file=sys.stderr)
if any(i in suite for i in banned):
return print(f'Invalid sign target suite: {suite}', file=sys.stderr)
log = Path(f'.tox/{suite}/tmp/meson-logs/testlog-{suite}.txt') # noqa: S108
if log.exists():
c.run(f'sigstore sign --output-dir=sig {log}')
else:
print(f'Log not found for {suite}.', file=sys.stderr)


@task(pre=[call(sign_log, suite='dist'), call(sign_log, suite='test'), call(sign_log, suite='lint')]) # pyright: ignore
def release(c: Context, sdist: bool = False) -> None:
"""Create release wheels for the current interpreter.
:param c: invoke context
:type c: Context
:param sdist: create source distribution tarball, defaults to False
:type sdist: bool, optional
"""
draft = c.run('psr --noop version')
if draft and draft.exited != 0:
return print('No release drafted.', file=sys.stderr)
if sdist:
c.run('python -m build --sdist')
c.run('sigstore sign dist/*.tar.gz')
ext_wheel = c.run('cibuildwheel --output-dir dist .')
if ext_wheel and ext_wheel.exited != 0:
c.run('python -m build --wheel')
c.run('sigstore sign --output-dir=sig dist/*.whl')


@task(release)
def provenance(c: Context) -> None:
print('SLSA provenance currently unavailable in OZI self-hosted CI/CD', file=sys.stderr)

@task(provenance)
def publish(c: Context) -> None:
"""Publishes a release tag"""
c.run('psr publish')
c.run('twine upload dist/*')
10 changes: 10 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -416,4 +416,14 @@ deps =
commands =
{env_python} -m setuptools_scm {posargs}
[testenv:invoke]
no_package = true
deps =
-r requirements.in
invoke
commands_pre =
pipx install --python=python meson
meson setup {env_tmp_dir} -Ddist=enabled -Dtox-env-dir={env_dir}
commands_post =
{env_python} -m invoke --search-root={env_tmp_dir}/ozi {posargs}
"""

0 comments on commit e0550e2

Please sign in to comment.