From 051bef57e43abe50880be35547fcab2e9b5c4b90 Mon Sep 17 00:00:00 2001 From: Ann Schulte Date: Sat, 28 Feb 2026 21:39:13 -0600 Subject: [PATCH] Standardize CI/CD workflows - Replace test.yml with ci.yml: separate lint job, matrix tests (3.8-3.12), version-check job - Rewrite publish.yml: add validate job that gates PyPI publish (tag/version match, lint, tests) --- .github/workflows/ci.yml | 83 +++++++++++++++++++++++++++++++++++ .github/workflows/publish.yml | 50 +++++++++++++++++---- .github/workflows/test.yml | 33 -------------- 3 files changed, 125 insertions(+), 41 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..86d43db --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,83 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.12' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -e ".[dev]" + + - name: Lint with ruff + run: ruff check . + + test: + name: Test (Python ${{ matrix.python-version }}) + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ['3.8', '3.9', '3.10', '3.11', '3.12'] + + steps: + - uses: actions/checkout@v4 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -e ".[dev]" + + - name: Run tests + run: pytest -v + + version-check: + name: Version sync + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.12' + + - name: Check version consistency + run: | + PYPROJECT_VERSION=$(python -c " + import re + with open('pyproject.toml') as f: + match = re.search(r'^version\s*=\s*\"(.+?)\"', f.read(), re.MULTILINE) + print(match.group(1)) + ") + INIT_VERSION=$(python -c " + import re + with open('plexus/__init__.py') as f: + match = re.search(r'^__version__\s*=\s*\"(.+?)\"', f.read(), re.MULTILINE) + print(match.group(1)) + ") + echo "pyproject.toml version: $PYPROJECT_VERSION" + echo "__init__.py version: $INIT_VERSION" + if [ "$PYPROJECT_VERSION" != "$INIT_VERSION" ]; then + echo "::error::Version mismatch! pyproject.toml=$PYPROJECT_VERSION, __init__.py=$INIT_VERSION" + exit 1 + fi + echo "Versions match: $PYPROJECT_VERSION" diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 8972f79..948dde5 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -3,17 +3,52 @@ name: Publish to PyPI on: release: types: [published] - workflow_dispatch: - inputs: - version: - description: 'Version to publish (leave empty for current)' - required: false jobs: + validate: + name: Validate release + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.12' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -e ".[dev]" + + - name: Check tag matches code version + run: | + TAG="${GITHUB_REF#refs/tags/v}" + CODE_VERSION=$(python -c " + import re + with open('pyproject.toml') as f: + match = re.search(r'^version\s*=\s*\"(.+?)\"', f.read(), re.MULTILINE) + print(match.group(1)) + ") + echo "Git tag version: $TAG" + echo "Code version: $CODE_VERSION" + if [ "$TAG" != "$CODE_VERSION" ]; then + echo "::error::Tag v$TAG does not match code version $CODE_VERSION" + exit 1 + fi + + - name: Lint + run: ruff check . + + - name: Run tests + run: pytest -v + publish: + name: Publish to PyPI + needs: validate runs-on: ubuntu-latest permissions: - id-token: write # Required for trusted publishing + id-token: write steps: - uses: actions/checkout@v4 @@ -21,7 +56,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v5 with: - python-version: '3.11' + python-version: '3.12' - name: Install build tools run: | @@ -36,4 +71,3 @@ jobs: - name: Publish to PyPI uses: pypa/gh-action-pypi-publish@release/v1 - # Uses trusted publishing - configure at pypi.org/manage/project/plexus-agent/settings/publishing/ diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index 571153a..0000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: Test - -on: - push: - branches: [main] - pull_request: - branches: [main] - -jobs: - test: - runs-on: ubuntu-latest - strategy: - matrix: - python-version: ['3.8', '3.9', '3.10', '3.11', '3.12'] - - steps: - - uses: actions/checkout@v4 - - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -e ".[dev]" - - - name: Lint with ruff - run: ruff check . - - - name: Run tests - run: pytest -v