diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 572b0d7..9c3be31 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,9 +2,9 @@ name: CI on: pull_request: - branches: [main, dev/institutional-recovery] + branches: [main] push: - branches: [main, dev/institutional-recovery] + branches: [main] jobs: checks: diff --git a/.github/workflows/pypi.yml b/.github/workflows/pypi.yml new file mode 100644 index 0000000..79cc18b --- /dev/null +++ b/.github/workflows/pypi.yml @@ -0,0 +1,59 @@ +name: Publish to PyPI + +# Runs only when a GitHub Release is published (not on push or PR). +# Release flow: bump `version` in pyproject.toml and src/verdi/__init__.py, +# merge, then publish a release tagged v (e.g. v0.1.1). +on: + release: + types: [published] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: "3.11" + - name: Install + run: pip install -e ".[dev]" build twine + - name: Tag must match package version + run: | + tag="${GITHUB_REF_NAME#v}" + pkg=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml','rb'))['project']['version'])") + mod=$(python -c "import verdi; print(verdi.__version__)") + echo "tag=$tag pyproject=$pkg verdi.__version__=$mod" + if [ "$tag" != "$pkg" ] || [ "$tag" != "$mod" ]; then + echo "::error::Release tag v$tag does not match pyproject ($pkg) / __version__ ($mod)" + exit 1 + fi + - name: Ruff + run: ruff check . + - name: Tests + run: python -m pytest + - name: Build + run: python -m build + - name: Check distributions + run: twine check --strict dist/* + - uses: actions/upload-artifact@v4 + with: + name: dist + path: dist/ + + publish: + needs: build + runs-on: ubuntu-latest + # Trusted publishing (OIDC): no API token stored in GitHub. Requires a + # trusted publisher on PyPI for SimulaMet/Verdi, workflow pypi.yml, + # environment "pypi". + environment: + name: pypi + url: https://pypi.org/project/verdi-agents/ + permissions: + id-token: write + steps: + - uses: actions/download-artifact@v4 + with: + name: dist + path: dist/ + - uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/README.md b/README.md index 8092faa..be604a6 100644 --- a/README.md +++ b/README.md @@ -179,6 +179,16 @@ alongside the individual run reports. See the [researcher guide](docs/RESEARCHER --- +## Releasing + +1. Bump `version` in `pyproject.toml` and `__version__` in `src/verdi/__init__.py`, and merge. +2. Publish a GitHub Release tagged `v` (for example `v0.1.1`). + +The [Publish to PyPI](.github/workflows/pypi.yml) workflow runs only on a +published release. It checks the tag matches the version, runs lint and tests, +builds, and uploads `verdi-agents` through PyPI trusted publishing (no token +stored in GitHub). + ## Research principles We distinguish **declared** values, **private** behavioral preferences, and