PyPI Packaging & Release Publishing Guide¶
This guide details packaging architecture, build verification, and automated
GitHub Actions PyPI publishing for CIS Benchmarks Tools Suite
(cis-benchmarks-tools).
1. Packaging Architecture & Standards¶
- PyPA Standard: Setuptools build backend (
setuptools.build_meta) inpyproject.toml. - PSL ONLY: Strictly zero third-party dependencies (
dependencies = []). - Dynamic Versioning: Resolved from the root
VERSIONfile. Installed wheels fall back toimportlib.metadata.version("cis-benchmarks-tools"). - Data Bundling: 18 JSON rules (
rules/*.json) and 2 HTML templates (templates/*.html) package into wheels viapackages = ["rules", "templates"]and[tool.setuptools.package-data]. - Console Entrypoints:
audit-cis = "audit_cis:main"andaudit_cis = "audit_cis:main".
2. Local Distribution Build & Verification¶
Build distribution archives (sdist and wheel) locally:
Verify wheel data assets using Python Standard Library:
python -c "import glob, zipfile; z = zipfile.ZipFile(glob.glob('dist/*.whl')[0]); assert len([n for n in z.namelist() if n.startswith('rules/') and n.endswith('.json')]) == 18; assert len([n for n in z.namelist() if n.startswith('templates/') and n.endswith('.html')]) == 2; print('Wheel data assets verified successfully!')"
3. Preflight Distribution Validation (twine check)¶
Validate metadata rendering and distribution integrity before PyPI upload:
Verifies README.md CommonMark syntax, metadata schema, and archive integrity
with zero warnings.
4. Automated GitHub Actions Publishing Workflow¶
Automated publication is orchestrated by .github/workflows/pypi-publish.yml:
- Triggers: Exclusively
release: types: [published]andworkflow_dispatch(withrepositorychoice:pypiortestpypi, matchingjmrenouard/MicroLLM). Tag pushes (push: tags:) are excluded to prevent premature publishing. - Concurrency:
cancel-in-progress: falseensures active uploads are never aborted mid-transmission. - Preflight Twine Check: Executes
python -m twine check --strict dist/*right afterpython -m build. - Authentication Modes:
- PyPI Trusted Publishing (OIDC): Passwordless OpenID Connect token
minting via
id-token: writeandpypa/gh-action-pypi-publish@release/v1. - API Token: Uses
PYPI_API_TOKEN,PIPY_API_TOKEN,PYPI_TOKEN,TEST_PYPI_API_TOKEN, orTEST_PIPY_API_TOKENwithtwine upload --non-interactive --skip-existing dist/*. - Graceful Notice: Emits an informational notice if neither credential method is configured.
5. Release Publication Procedure¶
- Local Validation: Run
python scripts/pre_commit_checks.pyandpython -m unittest discover -s tests -v. - Publish GitHub Release:
- Workflow Execution: Monitor Actions → Publish to PyPI.
- PyPI Verification: Verify live installation via
pip install --upgrade cis-benchmarks-tools.
6. Docker Hub Container Packaging & Release Publishing¶
Multi-platform container published to Docker Hub at
jmrenouard/cis-benchmarks-tools.
Architecture & Standards¶
- Base Image:
python:3.12-slim. - Non-Root:
cisuser:cisgroup(UID/GID 10001). - PSL ONLY: Zero external dependencies.
- Assets: Bundles 18 CIS rule specs (
rules/*.json) and HTML templates (templates/*.html). - Volume:
/app/reports.
Local Container Build & Verification¶
docker build -t jmrenouard/cis-benchmarks-tools:latest .
docker run --rm jmrenouard/cis-benchmarks-tools --list-targets
docker run --rm -v $(pwd)/reports:/app/reports jmrenouard/cis-benchmarks-tools --target mariadb106 -o /app/reports/audit.html
Automated GitHub Actions Workflow¶
Orchestrated by .github/workflows/docker-publish.yml:
- Triggers:
release: types: [published]and manualworkflow_dispatch. - Platforms:
linux/amd64andlinux/arm64(Buildx/QEMU). - Tags:
latest,vX.Y.Z, andX.Y.Z(resolved dynamically fromgithub.event.release.tag_nameorVERSION). - OCI Metadata & Release Notes: Embeds
org.opencontainers.image.*andcom.cis-benchmarks-tools.release-noteslabels (major/MySQLTuner-perl&jmrenouard/MicroLLMconventions). - Secrets: Supports
DOCKERHUB_USERNAME(fallback:DOCKER_USER_LOGINorDOCKER_USERNAME) andDOCKERHUB_TOKEN(fallback:DOCKER_USER_PASSWORDorDOCKER_PASSWORD).
7. Versioned MkDocs Publishing (IONOS SFTP)¶
Versioned documentation publishes to
https://cis-benchmarks.lightpath.fr/
via MkDocs Material (mkdocs.yml, requirements-docs.txt).
- Builder & Hooks:
scripts/build_versioned_docs.pybuilds/main/(/dev/), release tags (/latest/,v2.9.0–v2.10.0),versions.json(mike), and.htaccessredirects withassert_no_private_files.scripts/mkdocs_hooks.pymounts virtual root docs and rewrites links. - Local Preview:
pip install -r requirements-docs.txt
python scripts/build_versioned_docs.py --output /tmp/cis-site-dist --main-ref WORKTREE
- CI & Deploy Workflows:
.github/workflows/docs-ci.ymlvalidates documentation structure, links, andmkdocs build --strict..github/workflows/docs-publish.ymlbuilds and uploads via SFTP (sftp_only: true, explicit.htaccessupload) onmain, published releases, orworkflow_dispatch. - Required IONOS Secrets:
IONOS_FTP_SERVER,IONOS_FTP_USERNAME,IONOS_FTP_PASSWORD,IONOS_FTP_PORT(22), andIONOS_REMOTE_PATH(cis-benchmarks.lightpath.fr).