Org Discussion Router #19
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: Org Discussion Router | |
| on: | |
| # 组织 Discussion 创建事件(包含 discussion.body 作为分类输入) | |
| discussion: | |
| types: [created] | |
| # 组织 Discussion 新评论事件(comment.body 作为分类输入) | |
| discussion_comment: | |
| types: [created] | |
| # Worker relay 通道(部署后生效,作为备用路径) | |
| repository_dispatch: | |
| types: [org_msg_router] | |
| # 手动触发 / dry-run 灰度验证 | |
| workflow_dispatch: | |
| inputs: | |
| discussion_number: | |
| description: 'Discussion 编号' | |
| required: true | |
| type: string | |
| comment_body: | |
| description: '评论正文(可选,用于手动模拟)' | |
| required: false | |
| type: string | |
| comment_author: | |
| description: '评论作者(可选)' | |
| required: false | |
| type: string | |
| category_name: | |
| description: '分类名(可选)' | |
| required: false | |
| type: string | |
| dry_run: | |
| description: 'Dry-run 模式(只打印不写评论)' | |
| required: false | |
| default: 'false' | |
| type: choice | |
| options: | |
| - 'false' | |
| - 'true' | |
| jobs: | |
| route: | |
| # Bot 自身评论不触发,防止无限循环(已证 nevstop 非 Bot 类型,仅靠 marker 判断) | |
| if: | | |
| github.event_name != 'discussion_comment' || | |
| !contains(github.event.comment.body, '<!-- csm-qa-bot -->') | |
| runs-on: ubuntu-latest | |
| concurrency: | |
| group: org-router-${{ github.event.client_payload.discussion_number || github.event.discussion.number || github.event.inputs.discussion_number }} | |
| cancel-in-progress: false | |
| permissions: | |
| contents: read | |
| discussions: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.CSM_QA_GH_TOKEN }} | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.11' | |
| - name: Restore venv cache | |
| id: cache-venv | |
| uses: actions/cache/restore@v4 | |
| with: | |
| path: .venv | |
| key: ${{ runner.os }}-venv-py3.11-${{ hashFiles('requirements-bot.txt') }} | |
| - name: Install dependencies | |
| id: install-deps | |
| run: | | |
| set -euo pipefail | |
| if [ "${{ steps.cache-venv.outputs.cache-hit }}" = "true" ] && [ -x ".venv/bin/python" ]; then | |
| echo "venv cache hit; skipping install" | |
| else | |
| rm -rf .venv | |
| python -m pip install --disable-pip-version-check --quiet uv | |
| python -m uv venv .venv | |
| python -m uv pip install --python .venv/bin/python -r requirements-bot.txt | |
| fi | |
| echo "VIRTUAL_ENV=$PWD/.venv" >> "$GITHUB_ENV" | |
| echo "$PWD/.venv/bin" >> "$GITHUB_PATH" | |
| - name: Save venv cache | |
| if: always() && steps.install-deps.outcome == 'success' && steps.cache-venv.outputs.cache-hit != 'true' | |
| uses: actions/cache/save@v4 | |
| with: | |
| path: .venv | |
| key: ${{ steps.cache-venv.outputs.cache-primary-key }} | |
| - name: Run tests | |
| run: python -m pytest tests/test_router.py -v | |
| - name: Route & Process | |
| env: | |
| CSM_QA_GH_TOKEN: ${{ secrets.CSM_QA_GH_TOKEN }} | |
| LLM_API_KEY: ${{ secrets.LLM_API_KEY }} | |
| GITHUB_REPOSITORY: ${{ github.repository }} | |
| DISCUSSION_SOURCE_REPO: ${{ github.repository_owner }}/.github | |
| JOIN_FOLLOW_ORG: ${{ vars.JOIN_FOLLOW_ORG || 'NEVSTOP-LAB' }} | |
| JOIN_STAR_REPOS: ${{ vars.JOIN_STAR_REPOS || 'csm-core,API String,MassData,INIVariable' }} | |
| ROUTER_DISCUSSION_NUMBER: ${{ github.event.client_payload.discussion_number || github.event.discussion.number || github.event.inputs.discussion_number }} | |
| ROUTER_COMMENT_BODY: ${{ github.event.client_payload.comment_body || github.event.comment.body || github.event.discussion.body || github.event.inputs.comment_body || '' }} | |
| ROUTER_DISCUSSION_TITLE: ${{ github.event.discussion.title || '' }} | |
| ROUTER_COMMENT_AUTHOR: ${{ github.event.client_payload.comment_author || github.event.comment.user.login || github.event.discussion.user.login || github.event.inputs.comment_author || '' }} | |
| ROUTER_CATEGORY_NAME: ${{ github.event.client_payload.category_name || github.event.discussion.category.name || github.event.inputs.category_name || '' }} | |
| ROUTER_EVENT_TYPE: ${{ github.event.client_payload.event_type || github.event_name || '' }} | |
| run: | | |
| python scripts/router.py \ | |
| --discussion-number "${ROUTER_DISCUSSION_NUMBER}" \ | |
| --comment-body "${ROUTER_COMMENT_BODY}" \ | |
| --discussion-title "${ROUTER_DISCUSSION_TITLE}" \ | |
| --comment-author "${ROUTER_COMMENT_AUTHOR}" \ | |
| --category-name "${ROUTER_CATEGORY_NAME}" \ | |
| --event-type "${ROUTER_EVENT_TYPE}" \ | |
| ${{ github.event.inputs.dry_run == 'true' && '--dry-run' || '' }} |