|
| 1 | +name: CI |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - main |
| 6 | + pull_request: |
| 7 | + branches: |
| 8 | + - main |
| 9 | + schedule: |
| 10 | + - cron: '0 17 * * *' |
| 11 | + workflow_dispatch: |
| 12 | + |
| 13 | +concurrency: |
| 14 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 15 | + cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} |
| 16 | + |
| 17 | +permissions: |
| 18 | + contents: read |
| 19 | + pull-requests: read |
| 20 | + |
| 21 | +jobs: |
| 22 | + lint: |
| 23 | + runs-on: [self-hosted, trpc-agent-python-ci] |
| 24 | + timeout-minutes: 15 |
| 25 | + steps: |
| 26 | + - name: Checkout |
| 27 | + uses: actions/checkout@v4 |
| 28 | + with: |
| 29 | + fetch-depth: 0 |
| 30 | + |
| 31 | + - name: Get changed Python files |
| 32 | + id: changed |
| 33 | + run: | |
| 34 | + if [ "${{ github.event_name }}" = "pull_request" ]; then |
| 35 | + FILES=$(git diff --name-only --diff-filter=ACM origin/${{ github.base_ref }}...HEAD -- '*.py' | grep '^trpc_agent_sdk/' || true) |
| 36 | + else |
| 37 | + FILES=$(git diff --name-only --diff-filter=ACM HEAD~1...HEAD -- '*.py' | grep '^trpc_agent_sdk/' || true) |
| 38 | + fi |
| 39 | + if [ -z "$FILES" ]; then |
| 40 | + echo "has_files=false" >> "$GITHUB_OUTPUT" |
| 41 | + else |
| 42 | + echo "has_files=true" >> "$GITHUB_OUTPUT" |
| 43 | + echo "$FILES" > "$RUNNER_TEMP/changed_py_files.txt" |
| 44 | + echo "Changed Python files:" |
| 45 | + echo "$FILES" |
| 46 | + fi |
| 47 | +
|
| 48 | + - name: Check formatting with YAPF |
| 49 | + if: steps.changed.outputs.has_files == 'true' |
| 50 | + run: | |
| 51 | + FILES=$(cat "$RUNNER_TEMP/changed_py_files.txt" | tr '\n' ' ') |
| 52 | + diff_output=$(yapf --diff $FILES) || true |
| 53 | + if [ -n "$diff_output" ]; then |
| 54 | + echo "$diff_output" |
| 55 | + echo "::error::Code formatting check failed for changed files. Run 'yapf -i <file>' to fix." |
| 56 | + exit 1 |
| 57 | + fi |
| 58 | +
|
| 59 | + - name: Lint with flake8 |
| 60 | + if: steps.changed.outputs.has_files == 'true' |
| 61 | + run: | |
| 62 | + FILES=$(cat "$RUNNER_TEMP/changed_py_files.txt" | tr '\n' ' ') |
| 63 | + flake8 $FILES |
| 64 | +
|
| 65 | + test: |
| 66 | + runs-on: [self-hosted, trpc-agent-python-ci] |
| 67 | + timeout-minutes: 20 |
| 68 | + steps: |
| 69 | + - name: Checkout |
| 70 | + uses: actions/checkout@v4 |
| 71 | + |
| 72 | + - name: Install package and dependencies |
| 73 | + run: | |
| 74 | + pip install -r requirements-test.txt |
| 75 | +
|
| 76 | + - name: Run tests with coverage |
| 77 | + # run: pytest --cov=trpc_agent_sdk --cov-report=xml --cov-report=term tests/ |
| 78 | + run: pytest --cov=trpc_agent_sdk --cov-report=xml --cov-report=term --cov-fail-under=80 tests/ |
| 79 | + |
| 80 | + - name: Upload coverage reports to Codecov |
| 81 | + uses: codecov/codecov-action@v4 |
| 82 | + env: |
| 83 | + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} |
| 84 | + with: |
| 85 | + file: coverage.xml |
| 86 | + |
| 87 | + build: |
| 88 | + runs-on: [self-hosted, trpc-agent-python-ci] |
| 89 | + timeout-minutes: 15 |
| 90 | + steps: |
| 91 | + - name: Checkout |
| 92 | + uses: actions/checkout@v4 |
| 93 | + |
| 94 | + - name: Build package |
| 95 | + run: | |
| 96 | + pip install build |
| 97 | + python -m build |
| 98 | +
|
| 99 | + - name: Verify package |
| 100 | + run: | |
| 101 | + pip install dist/*.whl |
| 102 | + python -c "import trpc_agent_sdk; print('Import OK')" |
0 commit comments