|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [master] |
| 6 | + pull_request: |
| 7 | + branches: [master] |
| 8 | + |
| 9 | +env: |
| 10 | + POETRY_VERSION: "2.3.0" |
| 11 | + POETRY_VIRTUALENVS_IN_PROJECT: true |
| 12 | + |
| 13 | +jobs: |
| 14 | + lint: |
| 15 | + name: Lint |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - name: Checkout code |
| 19 | + uses: actions/checkout@v4 |
| 20 | + |
| 21 | + - name: Set up Python |
| 22 | + uses: actions/setup-python@v5 |
| 23 | + with: |
| 24 | + python-version: "3.14" |
| 25 | + |
| 26 | + - name: Load cached Poetry installation |
| 27 | + id: cached-poetry |
| 28 | + uses: actions/cache@v4 |
| 29 | + with: |
| 30 | + path: ~/.local |
| 31 | + key: poetry-${{ env.POETRY_VERSION }}-${{ runner.os }} |
| 32 | + |
| 33 | + - name: Install Poetry |
| 34 | + if: steps.cached-poetry.outputs.cache-hit != 'true' |
| 35 | + uses: snok/install-poetry@v1 |
| 36 | + with: |
| 37 | + version: ${{ env.POETRY_VERSION }} |
| 38 | + virtualenvs-create: true |
| 39 | + virtualenvs-in-project: true |
| 40 | + |
| 41 | + - name: Load cached venv |
| 42 | + id: cached-venv |
| 43 | + uses: actions/cache@v4 |
| 44 | + with: |
| 45 | + path: .venv |
| 46 | + key: venv-lint-${{ runner.os }}-py3.14-${{ hashFiles('poetry.lock') }} |
| 47 | + restore-keys: | |
| 48 | + venv-lint-${{ runner.os }}-py3.14- |
| 49 | +
|
| 50 | + - name: Install dependencies |
| 51 | + if: steps.cached-venv.outputs.cache-hit != 'true' |
| 52 | + run: poetry install --only dev --no-interaction |
| 53 | + |
| 54 | + - name: Run Ruff linter |
| 55 | + run: poetry run ruff check . |
| 56 | + |
| 57 | + - name: Run Ruff formatter check |
| 58 | + run: poetry run ruff format --check . |
| 59 | + |
| 60 | + test: |
| 61 | + name: Test |
| 62 | + runs-on: ubuntu-latest |
| 63 | + steps: |
| 64 | + - name: Checkout code |
| 65 | + uses: actions/checkout@v4 |
| 66 | + |
| 67 | + - name: Set up Python 3.14 |
| 68 | + uses: actions/setup-python@v5 |
| 69 | + with: |
| 70 | + python-version: "3.14" |
| 71 | + |
| 72 | + - name: Load cached Poetry installation |
| 73 | + id: cached-poetry |
| 74 | + uses: actions/cache@v4 |
| 75 | + with: |
| 76 | + path: ~/.local |
| 77 | + key: poetry-${{ env.POETRY_VERSION }}-${{ runner.os }} |
| 78 | + |
| 79 | + - name: Install Poetry |
| 80 | + if: steps.cached-poetry.outputs.cache-hit != 'true' |
| 81 | + uses: snok/install-poetry@v1 |
| 82 | + with: |
| 83 | + version: ${{ env.POETRY_VERSION }} |
| 84 | + virtualenvs-create: true |
| 85 | + virtualenvs-in-project: true |
| 86 | + |
| 87 | + - name: Load cached venv |
| 88 | + id: cached-venv |
| 89 | + uses: actions/cache@v4 |
| 90 | + with: |
| 91 | + path: .venv |
| 92 | + key: venv-test-${{ runner.os }}-py3.14-${{ hashFiles('poetry.lock') }} |
| 93 | + restore-keys: | |
| 94 | + venv-test-${{ runner.os }}-py3.14- |
| 95 | +
|
| 96 | + - name: Install dependencies |
| 97 | + if: steps.cached-venv.outputs.cache-hit != 'true' |
| 98 | + run: poetry install --no-interaction |
| 99 | + |
| 100 | + - name: Run tests with coverage |
| 101 | + run: | |
| 102 | + poetry run pytest \ |
| 103 | + --cov=pybot \ |
| 104 | + --cov-report=xml \ |
| 105 | + --cov-report=term-missing \ |
| 106 | + -v \ |
| 107 | + --tb=short |
| 108 | + env: |
| 109 | + SLACK_TOKEN: "xoxb-test-token" |
| 110 | + SLACK_ADMIN_TOKEN: "xoxb-admin-test-token" |
| 111 | + AIRTABLE_API_KEY: "test-key" |
| 112 | + AIRTABLE_BASE_ID: "test-base" |
| 113 | + |
| 114 | + - name: Upload coverage to Codecov |
| 115 | + uses: codecov/codecov-action@v5 |
| 116 | + with: |
| 117 | + files: ./coverage.xml |
| 118 | + fail_ci_if_error: false |
| 119 | + verbose: true |
| 120 | + |
| 121 | + security: |
| 122 | + name: Security Scan |
| 123 | + runs-on: ubuntu-latest |
| 124 | + steps: |
| 125 | + - name: Checkout code |
| 126 | + uses: actions/checkout@v4 |
| 127 | + |
| 128 | + - name: Set up Python 3.14 |
| 129 | + uses: actions/setup-python@v5 |
| 130 | + with: |
| 131 | + python-version: "3.14" |
| 132 | + |
| 133 | + - name: Load cached Poetry installation |
| 134 | + id: cached-poetry |
| 135 | + uses: actions/cache@v4 |
| 136 | + with: |
| 137 | + path: ~/.local |
| 138 | + key: poetry-${{ env.POETRY_VERSION }}-${{ runner.os }} |
| 139 | + |
| 140 | + - name: Install Poetry |
| 141 | + if: steps.cached-poetry.outputs.cache-hit != 'true' |
| 142 | + uses: snok/install-poetry@v1 |
| 143 | + with: |
| 144 | + version: ${{ env.POETRY_VERSION }} |
| 145 | + virtualenvs-create: true |
| 146 | + virtualenvs-in-project: true |
| 147 | + |
| 148 | + - name: Load cached venv |
| 149 | + id: cached-venv |
| 150 | + uses: actions/cache@v4 |
| 151 | + with: |
| 152 | + path: .venv |
| 153 | + key: venv-security-${{ runner.os }}-py3.14-${{ hashFiles('poetry.lock') }} |
| 154 | + restore-keys: | |
| 155 | + venv-security-${{ runner.os }}-py3.14- |
| 156 | +
|
| 157 | + - name: Install dependencies |
| 158 | + if: steps.cached-venv.outputs.cache-hit != 'true' |
| 159 | + run: poetry install --no-interaction |
| 160 | + |
| 161 | + - name: Run Bandit security linter |
| 162 | + run: poetry run bandit -r pybot -x pybot/_vendor --skip B101 -f json -o bandit-report.json || true |
| 163 | + |
| 164 | + - name: Display Bandit results |
| 165 | + run: poetry run bandit -r pybot -x pybot/_vendor --skip B101 -f txt || true |
| 166 | + |
| 167 | + - name: Check for known vulnerabilities |
| 168 | + run: poetry run safety scan --output text || true |
| 169 | + continue-on-error: true |
| 170 | + |
| 171 | + # Final status check for branch protection |
| 172 | + ci-success: |
| 173 | + name: CI Success |
| 174 | + needs: [lint, test, security] |
| 175 | + runs-on: ubuntu-latest |
| 176 | + if: always() |
| 177 | + steps: |
| 178 | + - name: Check all jobs passed |
| 179 | + run: | |
| 180 | + if [[ "${{ needs.lint.result }}" != "success" ]]; then |
| 181 | + echo "Lint job failed" |
| 182 | + exit 1 |
| 183 | + fi |
| 184 | + if [[ "${{ needs.test.result }}" != "success" ]]; then |
| 185 | + echo "Test job failed" |
| 186 | + exit 1 |
| 187 | + fi |
| 188 | + # Security is informational, doesn't fail CI |
| 189 | + echo "All required jobs passed!" |
0 commit comments