Skip to content

Commit 8d8433d

Browse files
CongkeChenraychen911
authored andcommitted
add release workflow
1 parent 636bc93 commit 8d8433d

1 file changed

Lines changed: 89 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: Auto Release when Tag
2+
on:
3+
push:
4+
tags:
5+
- 'v*'
6+
- 'test/v*'
7+
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.ref }}
10+
cancel-in-progress: false
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
release:
17+
runs-on: [self-hosted, trpc-agent-python-ci]
18+
timeout-minutes: 30
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0
24+
25+
- name: Install release dependencies
26+
run: |
27+
python -m pip install --upgrade pip
28+
pip install -r requirements-test.txt
29+
pip install build twine flake8 yapf
30+
31+
- name: Validate tag version
32+
run: |
33+
TAG_VERSION="${GITHUB_REF_NAME#test/v}"
34+
TAG_VERSION="${TAG_VERSION#v}"
35+
PACKAGE_VERSION=$(python -c "from trpc_agent_sdk.version import __version__; print(__version__)")
36+
if [ "$TAG_VERSION" != "$PACKAGE_VERSION" ]; then
37+
echo "::error::Tag version '$TAG_VERSION' does not match package version '$PACKAGE_VERSION'."
38+
exit 1
39+
fi
40+
41+
- name: Get changed Python files
42+
id: changed
43+
run: |
44+
FILES=$(git diff --name-only --diff-filter=ACM HEAD~1...HEAD -- '*.py' | grep '^trpc_agent_sdk/' || true)
45+
if [ -z "$FILES" ]; then
46+
echo "has_files=false" >> "$GITHUB_OUTPUT"
47+
else
48+
echo "has_files=true" >> "$GITHUB_OUTPUT"
49+
echo "$FILES" > "$RUNNER_TEMP/changed_py_files.txt"
50+
echo "Changed Python files:"
51+
echo "$FILES"
52+
fi
53+
54+
- name: Check formatting with YAPF
55+
if: steps.changed.outputs.has_files == 'true'
56+
run: |
57+
FILES=$(cat "$RUNNER_TEMP/changed_py_files.txt" | tr '\n' ' ')
58+
diff_output=$(yapf --diff $FILES) || true
59+
if [ -n "$diff_output" ]; then
60+
echo "$diff_output"
61+
echo "::error::Code formatting check failed for changed files. Run 'yapf -i <file>' to fix."
62+
exit 1
63+
fi
64+
65+
- name: Lint with flake8
66+
if: steps.changed.outputs.has_files == 'true'
67+
run: |
68+
FILES=$(cat "$RUNNER_TEMP/changed_py_files.txt" | tr '\n' ' ')
69+
flake8 $FILES
70+
71+
- name: Run tests with coverage
72+
run: |
73+
pytest --cov=trpc_agent_sdk --cov-report=xml --cov-report=term --cov-fail-under=80 tests/
74+
75+
- name: Build package
76+
run: |
77+
python -m build
78+
79+
- name: Check package
80+
run: |
81+
python -m twine check dist/*
82+
83+
- name: Publish to PyPI
84+
if: startsWith(github.ref, 'refs/tags/v')
85+
run: |
86+
python -m twine upload dist/*
87+
env:
88+
TWINE_USERNAME: __token__
89+
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}

0 commit comments

Comments
 (0)