diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..915ed25 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,41 @@ +name: CI + +on: + pull_request: + push: + branches: + - main + - master + +permissions: + contents: read + +jobs: + test: + name: Tests / Python ${{ matrix.python-version }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: + - "3.9" + - "3.10" + - "3.11" + - "3.12" + + steps: + - name: Check out repository + uses: actions/checkout@v6 + + - name: Set up Python + uses: actions/setup-python@v6 + with: + python-version: ${{ matrix.python-version }} + cache: pip + cache-dependency-path: pyproject.toml + + - name: Install package + run: python -m pip install -U pip && python -m pip install ".[dev]" + + - name: Run tests + run: python -m pytest -q diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..084d5ea --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,125 @@ +name: Publish + +on: + push: + tags: + - "v*.*.*" + workflow_dispatch: + +env: + PYPI_PROJECT_NAME: agent-ref + +permissions: + contents: read + +jobs: + build: + name: Build distribution + runs-on: ubuntu-latest + + steps: + - name: Check out repository + uses: actions/checkout@v6 + with: + persist-credentials: false + + - name: Set up Python + uses: actions/setup-python@v6 + with: + python-version: "3.11" + cache: pip + cache-dependency-path: pyproject.toml + + - name: Install build dependencies + run: python -m pip install -U pip build twine + + - name: Verify package name + run: | + python - <<'PY' + import os + import tomllib + + expected = os.environ["PYPI_PROJECT_NAME"] + with open("pyproject.toml", "rb") as file: + actual = tomllib.load(file)["project"]["name"] + + if actual != expected: + raise SystemExit( + f"pyproject.toml project.name is {actual!r}, expected {expected!r}" + ) + PY + + - name: Verify tag version + if: github.ref_type == 'tag' + run: | + python - <<'PY' + import os + import tomllib + + tag = os.environ["GITHUB_REF_NAME"] + with open("pyproject.toml", "rb") as file: + version = tomllib.load(file)["project"]["version"] + + expected = f"v{version}" + if tag != expected: + raise SystemExit( + f"tag {tag!r} does not match pyproject.toml version {version!r}; " + f"expected {expected!r}" + ) + PY + + - name: Run tests + run: python -m pip install ".[dev]" && python -m pytest -q + + - name: Build package + run: python -m build + + - name: Check package metadata + run: python -m twine check dist/* + + - name: Upload distributions + uses: actions/upload-artifact@v7 + with: + name: python-package-distributions + path: dist/ + + publish-to-pypi: + name: Publish to PyPI + needs: build + if: github.ref_type == 'tag' + runs-on: ubuntu-latest + environment: + name: pypi + url: https://pypi.org/project/agent-ref/ + permissions: + id-token: write + + steps: + - name: Download distributions + uses: actions/download-artifact@v7 + with: + name: python-package-distributions + path: dist/ + + - name: Publish package + uses: pypa/gh-action-pypi-publish@release/v1 + + create-github-release: + name: Create GitHub release + needs: publish-to-pypi + if: github.ref_type == 'tag' + runs-on: ubuntu-latest + permissions: + contents: write + + steps: + - name: Download distributions + uses: actions/download-artifact@v7 + with: + name: python-package-distributions + path: dist/ + + - name: Create release + env: + GH_TOKEN: ${{ github.token }} + run: gh release create "${GITHUB_REF_NAME}" dist/* --generate-notes