diff --git a/.github/workflows/test-and-publish.yml b/.github/workflows/test-and-publish.yml index 48c73f1f..6518b7c4 100644 --- a/.github/workflows/test-and-publish.yml +++ b/.github/workflows/test-and-publish.yml @@ -33,6 +33,7 @@ jobs: tests: name: Tests (Python ${{ matrix.python-version }}) runs-on: ubuntu-latest + environment: ci-live strategy: fail-fast: false matrix: @@ -91,6 +92,7 @@ jobs: examples: name: Examples (Python ${{ matrix.python-version }}) runs-on: ubuntu-latest + environment: ci-live strategy: fail-fast: false matrix: @@ -116,26 +118,22 @@ jobs: PDFREST_API_KEY: ${{ secrets.PDFREST_API_KEY }} publish: - name: Publish to CodeArtifact + name: Publish to PyPI needs: - docs-check - tests - examples - if: github.event_name == 'release' + if: github.event_name == 'release' && github.event.action == 'published' runs-on: ubuntu-latest + environment: production permissions: id-token: write contents: read - packages: write env: UV_PROJECT_ENVIRONMENT: .venv-release + UV_TRUSTED_PUBLISHING: always steps: - uses: actions/checkout@v4 - - name: Assume AWS role for repository CI - uses: aws-actions/configure-aws-credentials@v4 - with: - role-to-assume: arn:aws:iam::304774597385:role/cit-oidc-role-${{ github.event.repository.name }}-ci - aws-region: us-east-2 - name: Install uv uses: astral-sh/setup-uv@v6 with: @@ -149,11 +147,9 @@ jobs: path: | ${{ env.UV_PROJECT_ENVIRONMENT }} key: ${{ runner.os }}-uv-release-${{ hashFiles('pyproject.toml') }} - - name: Install keyring - run: uv tool install keyring --with keyrings.codeartifact - name: Synchronize project dependencies run: uv sync --group dev - name: Build distribution artifacts run: uv build --python 3.11 - - name: Publish package to CodeArtifact - run: uv publish --publish-url=https://datalogics-304774597385.d.codeartifact.us-east-2.amazonaws.com/pypi/cit-pypi/ --username __token__ + - name: Publish package to PyPI (Trusted Publishing) + run: uv publish diff --git a/pyproject.toml b/pyproject.toml index b14d546e..af57e62a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "pdfrest" -version = "0.1.0" +version = "1.0.0" description = "Python client library for interacting with the PDFRest API" readme = "README.md" authors = [ diff --git a/tests/live/conftest.py b/tests/live/conftest.py new file mode 100644 index 00000000..70009fc2 --- /dev/null +++ b/tests/live/conftest.py @@ -0,0 +1,58 @@ +from __future__ import annotations + +import os +from typing import Any + +import pytest + +from pdfrest import AsyncPdfRestClient, PdfRestClient + +DEFAULT_LIVE_WSN = "dl-internal-python-ci" + + +def _with_live_wsn_header(kwargs: dict[str, Any], wsn: str) -> dict[str, Any]: + new_kwargs = dict(kwargs) + headers = dict(new_kwargs.get("headers") or {}) + headers["wsn"] = wsn + new_kwargs["headers"] = headers + return new_kwargs + + +@pytest.fixture(scope="session") +def pdfrest_live_wsn() -> str: + return os.getenv("PDFREST_LIVE_WSN", DEFAULT_LIVE_WSN) + + +@pytest.fixture(autouse=True) +def inject_live_test_wsn_header( + monkeypatch: pytest.MonkeyPatch, + pdfrest_live_wsn: str, +) -> None: + original_sync_init = PdfRestClient.__init__ + original_async_init = AsyncPdfRestClient.__init__ + + def sync_init_with_live_header( + self: PdfRestClient, + *args: Any, + **kwargs: Any, + ) -> None: + original_sync_init( + self, + *args, + **_with_live_wsn_header(kwargs, pdfrest_live_wsn), + ) + + def async_init_with_live_header( + self: AsyncPdfRestClient, + *args: Any, + **kwargs: Any, + ) -> None: + original_async_init( + self, + *args, + **_with_live_wsn_header(kwargs, pdfrest_live_wsn), + ) + + monkeypatch.setattr(PdfRestClient, "__init__", sync_init_with_live_header) + monkeypatch.setattr(AsyncPdfRestClient, "__init__", async_init_with_live_header) + return diff --git a/uv.lock b/uv.lock index 83176688..4e6372b3 100644 --- a/uv.lock +++ b/uv.lock @@ -961,7 +961,7 @@ wheels = [ [[package]] name = "pdfrest" -version = "0.1.0" +version = "1.0.0" source = { editable = "." } dependencies = [ { name = "exceptiongroup" },