Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions .github/workflows/publish-pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: Publish to PyPI

on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"

permissions:
contents: read

concurrency:
group: publish-pypi
cancel-in-progress: false

jobs:
authorize:
runs-on: ubuntu-latest
steps:
- name: Ensure tag pusher and run initiator have admin or maintain role
env:
GH_TOKEN: ${{ github.token }}
ACTOR: ${{ github.actor }}
TRIGGERING_ACTOR: ${{ github.triggering_actor }}
run: |
# 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
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.10
Comment thread
JAugusto42 marked this conversation as resolved.
Resolved
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:
needs: authorize
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:
Comment thread
JAugusto42 marked this conversation as resolved.
Resolved
- 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: 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__
TWINE_PASSWORD: ${{ secrets.SRE_PYPI_TOKEN }}
run: twine upload dist/*
10 changes: 10 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Loading