|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main, master, develop ] |
| 6 | + pull_request: |
| 7 | + branches: [ main, master, develop ] |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +jobs: |
| 11 | + test: |
| 12 | + name: Test Python ${{ matrix.python-version }} |
| 13 | + runs-on: ubuntu-latest |
| 14 | + strategy: |
| 15 | + fail-fast: false |
| 16 | + matrix: |
| 17 | + python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] |
| 18 | + |
| 19 | + steps: |
| 20 | + - name: Checkout code |
| 21 | + uses: actions/checkout@v4 |
| 22 | + |
| 23 | + - name: Set up Python ${{ matrix.python-version }} |
| 24 | + uses: actions/setup-python@v5 |
| 25 | + with: |
| 26 | + python-version: ${{ matrix.python-version }} |
| 27 | + |
| 28 | + - name: Install Poetry |
| 29 | + uses: snok/install-poetry@v1 |
| 30 | + with: |
| 31 | + version: latest |
| 32 | + virtualenvs-create: true |
| 33 | + virtualenvs-in-project: true |
| 34 | + |
| 35 | + - name: Load cached venv |
| 36 | + id: cached-poetry-dependencies |
| 37 | + uses: actions/cache@v4 |
| 38 | + with: |
| 39 | + path: .venv |
| 40 | + key: venv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }} |
| 41 | + |
| 42 | + - name: Install dependencies |
| 43 | + if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' |
| 44 | + run: poetry install --no-interaction --no-root |
| 45 | + |
| 46 | + - name: Install project |
| 47 | + run: poetry install --no-interaction |
| 48 | + |
| 49 | + - name: Run black check |
| 50 | + run: poetry run black --check --line-length 100 simple_ado tests |
| 51 | + |
| 52 | + - name: Run pylint |
| 53 | + run: | |
| 54 | + poetry run pylint --rcfile=pylintrc simple_ado |
| 55 | + poetry run pylint --rcfile=pylintrc tests |
| 56 | + |
| 57 | + - name: Run mypy |
| 58 | + run: | |
| 59 | + poetry run mypy --ignore-missing-imports simple_ado/ |
| 60 | + poetry run mypy --ignore-missing-imports tests/ |
| 61 | + |
| 62 | + - name: Run unit tests |
| 63 | + run: poetry run pytest tests/unit/ --cov=simple_ado --cov-report=xml --cov-report=html --junitxml=junit/test-results.xml |
| 64 | + |
| 65 | + - name: Upload coverage to Codecov |
| 66 | + uses: codecov/codecov-action@v4 |
| 67 | + if: matrix.python-version == '3.12' |
| 68 | + with: |
| 69 | + file: ./coverage.xml |
| 70 | + fail_ci_if_error: false |
| 71 | + token: ${{ secrets.CODECOV_TOKEN }} |
| 72 | + |
| 73 | + - name: Upload test results |
| 74 | + uses: actions/upload-artifact@v4 |
| 75 | + if: always() |
| 76 | + with: |
| 77 | + name: test-results-${{ matrix.python-version }} |
| 78 | + path: junit/test-results.xml |
| 79 | + |
| 80 | + - name: Upload coverage HTML report |
| 81 | + uses: actions/upload-artifact@v4 |
| 82 | + if: always() |
| 83 | + with: |
| 84 | + name: coverage-html-${{ matrix.python-version }} |
| 85 | + path: htmlcov/ |
| 86 | + |
| 87 | + - name: Upload coverage to Codecov |
| 88 | + uses: codecov/codecov-action@v4 |
| 89 | + if: always() |
| 90 | + with: |
| 91 | + file: ./coverage.xml |
| 92 | + flags: unittests |
| 93 | + name: codecov-umbrella |
| 94 | + fail_ci_if_error: false |
| 95 | + |
| 96 | + deploy-coverage: |
| 97 | + name: Deploy Coverage to GitHub Pages |
| 98 | + needs: test |
| 99 | + if: github.ref == 'refs/heads/main' && github.event_name == 'push' |
| 100 | + runs-on: ubuntu-latest |
| 101 | + |
| 102 | + permissions: |
| 103 | + pages: write |
| 104 | + id-token: write |
| 105 | + |
| 106 | + environment: |
| 107 | + name: github-pages |
| 108 | + url: ${{ steps.deployment.outputs.page_url }} |
| 109 | + |
| 110 | + steps: |
| 111 | + - name: Download all coverage HTML reports |
| 112 | + uses: actions/download-artifact@v4 |
| 113 | + with: |
| 114 | + pattern: coverage-html-* |
| 115 | + path: coverage-artifacts |
| 116 | + |
| 117 | + - name: Select latest Python version coverage |
| 118 | + run: | |
| 119 | + # Find the coverage report from the highest Python version |
| 120 | + LATEST_DIR=$(ls -d coverage-artifacts/coverage-html-* | sort -V | tail -1) |
| 121 | + echo "Using coverage from: $LATEST_DIR" |
| 122 | + mv "$LATEST_DIR" htmlcov |
| 123 | + |
| 124 | + - name: Upload Pages artifact |
| 125 | + uses: actions/upload-pages-artifact@v3 |
| 126 | + with: |
| 127 | + path: htmlcov |
| 128 | + |
| 129 | + - name: Deploy to GitHub Pages |
| 130 | + id: deployment |
| 131 | + uses: actions/deploy-pages@v4 |
| 132 | + |
| 133 | + integration-tests: |
| 134 | + name: Integration Tests |
| 135 | + runs-on: ubuntu-latest |
| 136 | + # Only run if ADO credentials are available |
| 137 | + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' |
| 138 | + |
| 139 | + steps: |
| 140 | + - name: Checkout code |
| 141 | + uses: actions/checkout@v4 |
| 142 | + |
| 143 | + - name: Set up Python |
| 144 | + uses: actions/setup-python@v5 |
| 145 | + with: |
| 146 | + python-version: "3.12" |
| 147 | + |
| 148 | + - name: Install Poetry |
| 149 | + uses: snok/install-poetry@v1 |
| 150 | + with: |
| 151 | + version: latest |
| 152 | + virtualenvs-create: true |
| 153 | + virtualenvs-in-project: true |
| 154 | + |
| 155 | + - name: Install dependencies |
| 156 | + run: poetry install --no-interaction |
| 157 | + |
| 158 | + - name: Run integration tests |
| 159 | + run: poetry run pytest tests/ --integration --junitxml=junit/integration-results.xml |
| 160 | + env: |
| 161 | + SIMPLE_ADO_BASE_TOKEN: ${{ secrets.SIMPLE_ADO_BASE_TOKEN }} |
| 162 | + SIMPLE_ADO_TENANT: ${{ secrets.SIMPLE_ADO_TENANT }} |
| 163 | + SIMPLE_ADO_PROJECT_ID: ${{ secrets.SIMPLE_ADO_PROJECT_ID }} |
| 164 | + SIMPLE_ADO_REPO_ID: ${{ secrets.SIMPLE_ADO_REPO_ID }} |
| 165 | + |
| 166 | + - name: Upload integration test results |
| 167 | + uses: actions/upload-artifact@v4 |
| 168 | + if: always() |
| 169 | + with: |
| 170 | + name: integration-test-results |
| 171 | + path: junit/integration-results.xml |
0 commit comments