[init]: 初始化项目结构 #1
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: Python Code Linting (Safe Optimized) | |
| on: | |
| # 触发条件 1: 所有分支的 push 事件 | |
| push: | |
| branches-ignore: [] | |
| # 触发条件 2: 针对 dev 分支的 pull_request 事件 | |
| pull_request: | |
| branches: [ "dev" ] | |
| jobs: | |
| lint: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code (with full history) | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 2 # 必须获取前一次提交,才能比较变更 | |
| - name: Set up Python | |
| uses: actions/setup-python@v4 | |
| with: | |
| python-version: "3.10" | |
| - name: Install flake8 | |
| run: pip install flake8 | |
| - name: Get valid changed Python files | |
| id: changed-files | |
| run: | | |
| # 获取变更的.py文件列表,并过滤出实际存在的文件 | |
| FILES=$(git diff --name-only --diff-filter=d HEAD^ HEAD | grep '\.py$' | while read -r file; do | |
| [ -f "$file" ] && echo "$file" | |
| done) | |
| echo "Valid changed Python files:" | |
| echo "$FILES" | |
| echo "files=${FILES}" >> $GITHUB_OUTPUT | |
| - name: Run flake8 on changed files | |
| if: steps.changed-files.outputs.files != '' | |
| run: | | |
| echo "${{ steps.changed-files.outputs.files }}" | xargs -r flake8 | |
| - name: Skip if no valid Python files changed | |
| if: steps.changed-files.outputs.files == '' | |
| run: echo "✅ 没有有效的.py文件变更,跳过检查" |