|
| 1 | +name: CI - Test and Validate |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - develop |
| 8 | + - 'release/**' |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: read |
| 12 | + |
| 13 | +concurrency: |
| 14 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 15 | + cancel-in-progress: true |
| 16 | + |
| 17 | +jobs: |
| 18 | + docs-only: |
| 19 | + name: docs-only |
| 20 | + runs-on: ubuntu-latest |
| 21 | + outputs: |
| 22 | + docs_only: ${{ steps.detect.outputs.docs_only }} |
| 23 | + steps: |
| 24 | + - name: Checkout code |
| 25 | + uses: actions/checkout@v4 |
| 26 | + |
| 27 | + - name: Fetch base branch for diff |
| 28 | + if: github.event_name == 'pull_request' |
| 29 | + run: git fetch origin ${{ github.base_ref }} --depth=1 |
| 30 | + |
| 31 | + - name: Detect docs-only changes |
| 32 | + id: detect |
| 33 | + run: | |
| 34 | + if [ "${{ github.event_name }}" != "pull_request" ]; then |
| 35 | + echo "docs_only=false" >> "$GITHUB_OUTPUT" |
| 36 | + exit 0 |
| 37 | + fi |
| 38 | +
|
| 39 | + files=$(git diff --name-only "origin/${{ github.base_ref }}"...HEAD) |
| 40 | + if [ -z "$files" ]; then |
| 41 | + echo "docs_only=false" >> "$GITHUB_OUTPUT" |
| 42 | + exit 0 |
| 43 | + fi |
| 44 | +
|
| 45 | + docs_only=true |
| 46 | + for file in $files; do |
| 47 | + if [[ "$file" == docs/* ]] || [[ "$file" == "README.md" ]] || [[ "$file" == "CHANGELOG.md" ]]; then |
| 48 | + continue |
| 49 | + fi |
| 50 | + docs_only=false |
| 51 | + break |
| 52 | + done |
| 53 | +
|
| 54 | + echo "docs_only=$docs_only" >> "$GITHUB_OUTPUT" |
| 55 | +
|
| 56 | + dependency-audit: |
| 57 | + name: dependency-audit |
| 58 | + runs-on: ubuntu-latest |
| 59 | + steps: |
| 60 | + - name: Checkout code |
| 61 | + uses: actions/checkout@v4 |
| 62 | + |
| 63 | + - name: Set up Python 3.14 |
| 64 | + uses: actions/setup-python@v5 |
| 65 | + with: |
| 66 | + python-version: "3.14" |
| 67 | + |
| 68 | + - name: Cache Poetry installation |
| 69 | + uses: actions/cache@v4 |
| 70 | + with: |
| 71 | + path: | |
| 72 | + ~/.local/share/pypoetry |
| 73 | + ~/.local/bin/poetry |
| 74 | + key: poetry-install-${{ runner.os }}-3.14 |
| 75 | + |
| 76 | + - name: Install Poetry |
| 77 | + run: | |
| 78 | + if ! command -v poetry &> /dev/null; then |
| 79 | + curl -sSL https://install.python-poetry.org | python3 - |
| 80 | + echo "$HOME/.local/bin" >> $GITHUB_PATH |
| 81 | + fi |
| 82 | + poetry --version |
| 83 | +
|
| 84 | + - name: Cache dependencies |
| 85 | + uses: actions/cache@v4 |
| 86 | + with: |
| 87 | + path: ~/.cache/pypoetry/virtualenvs |
| 88 | + key: poetry-${{ runner.os }}-py3.14-${{ hashFiles('poetry.lock') }} |
| 89 | + restore-keys: | |
| 90 | + poetry-${{ runner.os }}-py3.14- |
| 91 | +
|
| 92 | + - name: Install dependencies |
| 93 | + run: poetry install --no-interaction |
| 94 | + |
| 95 | + - name: Run pip-audit (fail on any vulnerability) |
| 96 | + run: poetry run pip-audit -r requirements.txt -r requirements-dev.txt |
| 97 | + |
| 98 | + test-and-validate: |
| 99 | + name: test-and-validate |
| 100 | + runs-on: ubuntu-latest |
| 101 | + needs: docs-only |
| 102 | + if: needs.docs-only.outputs.docs_only != 'true' |
| 103 | + strategy: |
| 104 | + matrix: |
| 105 | + python-version: ["3.14"] |
| 106 | + |
| 107 | + steps: |
| 108 | + - name: Checkout code |
| 109 | + uses: actions/checkout@v4 |
| 110 | + |
| 111 | + - name: Fetch base branch for version checks |
| 112 | + if: github.event_name == 'pull_request' |
| 113 | + run: git fetch origin ${{ github.base_ref }} --depth=1 |
| 114 | + |
| 115 | + - name: Set up Python ${{ matrix.python-version }} |
| 116 | + uses: actions/setup-python@v5 |
| 117 | + with: |
| 118 | + python-version: ${{ matrix.python-version }} |
| 119 | + |
| 120 | + - name: Validate version string policy |
| 121 | + run: python3 scripts/dev/validate_version.py |
| 122 | + |
| 123 | + - name: Cache Poetry installation |
| 124 | + uses: actions/cache@v4 |
| 125 | + with: |
| 126 | + path: | |
| 127 | + ~/.local/share/pypoetry |
| 128 | + ~/.local/bin/poetry |
| 129 | + key: poetry-install-${{ runner.os }}-${{ matrix.python-version }} |
| 130 | + |
| 131 | + - name: Install Poetry |
| 132 | + run: | |
| 133 | + if ! command -v poetry &> /dev/null; then |
| 134 | + curl -sSL https://install.python-poetry.org | python3 - |
| 135 | + echo "$HOME/.local/bin" >> $GITHUB_PATH |
| 136 | + fi |
| 137 | + poetry --version |
| 138 | +
|
| 139 | + - name: Validate dependency specifications |
| 140 | + run: python3 scripts/dev/validate_dependency_specs.py |
| 141 | + |
| 142 | + - name: Verify poetry.lock sync |
| 143 | + run: poetry check --lock |
| 144 | + |
| 145 | + - name: Cache dependencies |
| 146 | + uses: actions/cache@v4 |
| 147 | + with: |
| 148 | + path: ~/.cache/pypoetry/virtualenvs |
| 149 | + key: poetry-${{ runner.os }}-py${{ matrix.python-version }}-${{ hashFiles('poetry.lock') }} |
| 150 | + restore-keys: | |
| 151 | + poetry-${{ runner.os }}-py${{ matrix.python-version }}- |
| 152 | +
|
| 153 | + - name: Install dependencies |
| 154 | + run: poetry install --no-interaction |
| 155 | + |
| 156 | + - name: Run ruff check |
| 157 | + run: poetry run ruff check |
| 158 | + |
| 159 | + - name: Run mypy |
| 160 | + run: poetry run mypy src/ |
| 161 | + |
| 162 | + - name: Run tests with coverage |
| 163 | + run: | |
| 164 | + poetry run pytest \ |
| 165 | + --cov=pymqrest \ |
| 166 | + --cov-report=term-missing \ |
| 167 | + --cov-branch \ |
| 168 | + --cov-fail-under=100 |
0 commit comments