Align release lint checks with CI #2
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Auto Release when Tag | |
| on: | |
| push: | |
| tags: | |
| - 'v*' | |
| - 'test/v*' | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: false | |
| permissions: | |
| contents: read | |
| jobs: | |
| release: | |
| runs-on: [self-hosted, trpc-agent-python-ci] | |
| timeout-minutes: 30 | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Install release dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements-test.txt | |
| pip install build twine flake8 yapf | |
| - name: Validate tag version | |
| run: | | |
| TAG_VERSION="${GITHUB_REF_NAME#test/v}" | |
| TAG_VERSION="${TAG_VERSION#v}" | |
| PACKAGE_VERSION=$(python -c "from trpc_agent_sdk.version import __version__; print(__version__)") | |
| if [ "$TAG_VERSION" != "$PACKAGE_VERSION" ]; then | |
| echo "::error::Tag version '$TAG_VERSION' does not match package version '$PACKAGE_VERSION'." | |
| exit 1 | |
| fi | |
| - name: Get changed Python files | |
| id: changed | |
| run: | | |
| FILES=$(git diff --name-only --diff-filter=ACM HEAD~1...HEAD -- '*.py' | grep '^trpc_agent_sdk/' || true) | |
| if [ -z "$FILES" ]; then | |
| echo "has_files=false" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "has_files=true" >> "$GITHUB_OUTPUT" | |
| echo "$FILES" > "$RUNNER_TEMP/changed_py_files.txt" | |
| echo "Changed Python files:" | |
| echo "$FILES" | |
| fi | |
| - name: Check formatting with YAPF | |
| if: steps.changed.outputs.has_files == 'true' | |
| run: | | |
| FILES=$(cat "$RUNNER_TEMP/changed_py_files.txt" | tr '\n' ' ') | |
| diff_output=$(yapf --diff $FILES) || true | |
| if [ -n "$diff_output" ]; then | |
| echo "$diff_output" | |
| echo "::error::Code formatting check failed for changed files. Run 'yapf -i <file>' to fix." | |
| exit 1 | |
| fi | |
| - name: Lint with flake8 | |
| if: steps.changed.outputs.has_files == 'true' | |
| run: | | |
| FILES=$(cat "$RUNNER_TEMP/changed_py_files.txt" | tr '\n' ' ') | |
| flake8 $FILES | |
| - name: Run tests with coverage | |
| run: | | |
| pytest --cov=trpc_agent_sdk --cov-report=xml --cov-report=term --cov-fail-under=80 tests/ | |
| - name: Build package | |
| run: | | |
| python -m build | |
| - name: Check package | |
| run: | | |
| twine check dist/* | |
| - name: Publish to PyPI | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| run: | | |
| twine upload dist/* | |
| env: | |
| TWINE_USERNAME: __token__ | |
| TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} |