|
9 | 9 | reject-drift: |
10 | 10 | runs-on: ubuntu-latest |
11 | 11 |
|
| 12 | + # Skip if the last commit was from the bot (prevent unnecessary check) |
| 13 | + if: github.event.head_commit.author.name != 'github-actions[bot]' |
| 14 | + |
12 | 15 | steps: |
13 | 16 | - name: Checkout code |
14 | 17 | uses: actions/checkout@v4 |
15 | 18 | with: |
16 | | - fetch-depth: 2 |
| 19 | + fetch-depth: 0 # full history |
17 | 20 |
|
18 | 21 | - name: Check if requirements.txt was modified unexpectedly |
19 | 22 | run: | |
20 | | - # Get author of last commit |
21 | | - AUTHOR=$(git log -1 --pretty=format:'%an') |
| 23 | + # For PRs, check against base branch |
| 24 | + # For pushes, check last commit |
| 25 | + if [ "${{ github.event_name }}" = "pull_request" ]; then |
| 26 | + BASE_REF="${{ github.event.pull_request.base.sha }}" |
| 27 | + COMPARE_RANGE="$BASE_REF...HEAD" |
| 28 | + else |
| 29 | + COMPARE_RANGE="HEAD~1..HEAD" |
| 30 | + fi |
22 | 31 |
|
23 | | - # Check if requirements.txt was modified in last commit |
24 | | - if git diff --name-only HEAD~1 HEAD | grep -q "^requirements.txt$"; then |
25 | | - if [ "$AUTHOR" != "github-actions[bot]" ]; then |
26 | | - echo "::error::You may NOT edit 'requirements.txt'" |
27 | | - echo "::warning::Undo your changes to requirements.txt, so robot can maintain it." |
28 | | - echo "::notice::To pin dependencies, use 'poetry add <package-name>'." |
29 | | - exit 1 |
30 | | - fi |
| 32 | + # If requirements.txt modified in that range |
| 33 | + if git diff --name-only $COMPARE_RANGE | grep -q "^requirements.txt$"; then |
| 34 | + echo "::error::You may NOT edit 'requirements.txt'" |
| 35 | + echo "::warning::Undo your changes to requirements.txt, so robot can maintain it." |
| 36 | + echo "::notice::To pin dependencies, use 'poetry add <package-name>'." |
| 37 | + exit 1 |
31 | 38 | fi |
32 | 39 |
|
33 | | - echo "`requirements.txt` unchanged" |
| 40 | + echo "'requirements.txt' unchanged (or only changed by bot)" |
0 commit comments