From 01cb1456920f615ed4eb5e91eafd151e189dea56 Mon Sep 17 00:00:00 2001 From: Jose Augusto Date: Wed, 14 Oct 2026 12:47:29 -0300 Subject: [PATCH 1/5] ci: publish package to PyPI on release tags --- .github/workflows/publish-pypi.yml | 57 ++++++++++++++++++++++++++++++ CONTRIBUTING.md | 10 ++++++ pyproject.toml | 3 ++ 3 files changed, 70 insertions(+) create mode 100644 .github/workflows/publish-pypi.yml diff --git a/.github/workflows/publish-pypi.yml b/.github/workflows/publish-pypi.yml new file mode 100644 index 0000000..599b9af --- /dev/null +++ b/.github/workflows/publish-pypi.yml @@ -0,0 +1,57 @@ +name: Publish to PyPI + +on: + push: + tags: + - "v[0-9]+.[0-9]+.[0-9]+" + +jobs: + tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Python 3.10 + uses: actions/setup-python@v5 + with: + python-version: "3.10" + - name: Install package and test dependencies + run: pip install . pytest + - name: Run tests + run: pytest -q + + version-check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Ensure tag matches VERSION file + run: | + TAG="${GITHUB_REF_NAME#v}" + FILE_VERSION="$(tr -d '[:space:]' < src/conviso/VERSION)" + if [ "$TAG" != "$FILE_VERSION" ]; then + echo "Tag ($GITHUB_REF_NAME) does not match src/conviso/VERSION ($FILE_VERSION)." + exit 1 + fi + echo "Tag matches VERSION ($FILE_VERSION)." + + build-and-publish-pypi: + needs: + - tests + - version-check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Python 3.10 + uses: actions/setup-python@v5 + with: + python-version: "3.10" + - name: Install build tools + run: pip install build twine + - name: Build package + run: python -m build + - name: Check distribution + run: twine check dist/* + - name: Publish to PyPI + env: + TWINE_USERNAME: __token__ + TWINE_PASSWORD: ${{ secrets.SRE_PYPI_TOKEN }} + run: twine upload dist/* diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 65fdf62..bab6af9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -39,5 +39,15 @@ Thanks for your interest in contributing! Below is a quick guide to help you get - If adding commands or bulk flows, update README and samples if needed. - If touching bulk, ensure `--show-template` output stays consistent. +## Releases +- Versions follow [SemVer](https://semver.org) (`MAJOR.MINOR.PATCH`) and live in `src/conviso/VERSION`. +- Release tags use the `vX.Y.Z` format (e.g., `v0.5.1`) and must match `VERSION` without the `v`. +- Pushing a release tag runs the tests and publishes the package to PyPI: + ``` + git tag v0.5.1 + git push origin v0.5.1 + ``` +- Tags in any other format do not trigger a release. + ## Reporting issues - Provide command run, options used, expected vs. actual behavior, and any GraphQL errors returned. diff --git a/pyproject.toml b/pyproject.toml index 79bb12a..5ab23bb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -44,5 +44,8 @@ cvs = "conviso.app:app" [tool.setuptools.packages.find] where = ["src"] +[tool.setuptools.package-data] +conviso = ["VERSION", "*.json"] + [tool.setuptools.dynamic] version = { file = "src/conviso/VERSION" } From 0559e140ae9edc8df99c4e4f2bd5dcc90be04bf3 Mon Sep 17 00:00:00 2001 From: Jose Augusto Date: Wed, 14 Oct 2026 13:01:01 -0300 Subject: [PATCH 2/5] ci: gate PyPI publishing behind protected environment --- .github/workflows/publish-pypi.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/publish-pypi.yml b/.github/workflows/publish-pypi.yml index 599b9af..de44be1 100644 --- a/.github/workflows/publish-pypi.yml +++ b/.github/workflows/publish-pypi.yml @@ -5,6 +5,13 @@ on: tags: - "v[0-9]+.[0-9]+.[0-9]+" +permissions: + contents: read + +concurrency: + group: publish-pypi + cancel-in-progress: false + jobs: tests: runs-on: ubuntu-latest @@ -38,6 +45,9 @@ jobs: - tests - version-check runs-on: ubuntu-latest + environment: + name: pypi + url: https://pypi.org/project/conviso-cli/ steps: - uses: actions/checkout@v4 - name: Set up Python 3.10 From 2cb2779fbba24287d1f57f1ad1acaf234276607e Mon Sep 17 00:00:00 2001 From: Jose Augusto Date: Wed, 14 Oct 2026 13:03:51 -0300 Subject: [PATCH 3/5] ci: restrict PyPI releases to repository maintainers --- .github/workflows/publish-pypi.yml | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/.github/workflows/publish-pypi.yml b/.github/workflows/publish-pypi.yml index de44be1..065308b 100644 --- a/.github/workflows/publish-pypi.yml +++ b/.github/workflows/publish-pypi.yml @@ -13,7 +13,27 @@ concurrency: cancel-in-progress: false jobs: + authorize: + runs-on: ubuntu-latest + steps: + - name: Ensure actor has admin or maintain role on the repository + env: + GH_TOKEN: ${{ github.token }} + ACTOR: ${{ github.triggering_actor }} + run: | + ROLE="$(gh api "repos/${GITHUB_REPOSITORY}/collaborators/${ACTOR}/permission" --jq '.role_name' || echo none)" + case "$ROLE" in + admin|maintain) + echo "$ACTOR is allowed to release (role: $ROLE)." + ;; + *) + echo "$ACTOR is not allowed to release (role: $ROLE)." + exit 1 + ;; + esac + tests: + needs: authorize runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -27,6 +47,7 @@ jobs: run: pytest -q version-check: + needs: authorize runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -45,9 +66,6 @@ jobs: - tests - version-check runs-on: ubuntu-latest - environment: - name: pypi - url: https://pypi.org/project/conviso-cli/ steps: - uses: actions/checkout@v4 - name: Set up Python 3.10 From c9294c445ca13a175ebb41b598ae18d8d596d497 Mon Sep 17 00:00:00 2001 From: Jose Augusto Date: Wed, 14 Oct 2026 16:03:48 -0300 Subject: [PATCH 4/5] ci: authorize both tag pusher and re-run initiator --- .github/workflows/publish-pypi.yml | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/.github/workflows/publish-pypi.yml b/.github/workflows/publish-pypi.yml index 065308b..b499c93 100644 --- a/.github/workflows/publish-pypi.yml +++ b/.github/workflows/publish-pypi.yml @@ -16,21 +16,25 @@ jobs: authorize: runs-on: ubuntu-latest steps: - - name: Ensure actor has admin or maintain role on the repository + - name: Ensure tag pusher and run initiator have admin or maintain role env: GH_TOKEN: ${{ github.token }} - ACTOR: ${{ github.triggering_actor }} + ACTOR: ${{ github.actor }} + TRIGGERING_ACTOR: ${{ github.triggering_actor }} run: | - ROLE="$(gh api "repos/${GITHUB_REPOSITORY}/collaborators/${ACTOR}/permission" --jq '.role_name' || echo none)" - case "$ROLE" in - admin|maintain) - echo "$ACTOR is allowed to release (role: $ROLE)." - ;; - *) - echo "$ACTOR is not allowed to release (role: $ROLE)." - exit 1 - ;; - esac + # actor is who pushed the tag; triggering_actor is who started this run (differs on re-runs). + for USER in "$ACTOR" "$TRIGGERING_ACTOR"; do + ROLE="$(gh api "repos/${GITHUB_REPOSITORY}/collaborators/${USER}/permission" --jq '.role_name' || echo none)" + case "$ROLE" in + admin|maintain) + echo "$USER is allowed to release (role: $ROLE)." + ;; + *) + echo "$USER is not allowed to release (role: $ROLE)." + exit 1 + ;; + esac + done tests: needs: authorize From 6f07835e0c03b9d8e350189eebc41bcb6945ab52 Mon Sep 17 00:00:00 2001 From: Jose Augusto Date: Wed, 14 Oct 2026 16:40:54 -0300 Subject: [PATCH 5/5] ci: smoke test built wheel before publishing --- .github/workflows/publish-pypi.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.github/workflows/publish-pypi.yml b/.github/workflows/publish-pypi.yml index b499c93..6ea535f 100644 --- a/.github/workflows/publish-pypi.yml +++ b/.github/workflows/publish-pypi.yml @@ -82,6 +82,19 @@ jobs: run: python -m build - name: Check distribution run: twine check dist/* + - name: Smoke test built wheel + run: | + python -m venv /tmp/wheel-venv + /tmp/wheel-venv/bin/pip install dist/*.whl + cd /tmp + /tmp/wheel-venv/bin/conviso --version + /tmp/wheel-venv/bin/python -c " + from pathlib import Path + import conviso + pkg = Path(next(iter(conviso.__path__))) + for name in ('VERSION', 'security_gate_rules_schema.json'): + assert (pkg / name).is_file(), f'{name} missing from wheel' + " - name: Publish to PyPI env: TWINE_USERNAME: __token__