Skip to content

Commit 310a40b

Browse files
committed
refactor: simpplify reqs-validate
1 parent 789a9b4 commit 310a40b

1 file changed

Lines changed: 19 additions & 12 deletions

File tree

.github/workflows/reqs-validate.yml

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,32 @@ jobs:
99
reject-drift:
1010
runs-on: ubuntu-latest
1111

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+
1215
steps:
1316
- name: Checkout code
1417
uses: actions/checkout@v4
1518
with:
16-
fetch-depth: 2
19+
fetch-depth: 0 # full history
1720

1821
- name: Check if requirements.txt was modified unexpectedly
1922
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
2231
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
3138
fi
3239
33-
echo "`requirements.txt` unchanged"
40+
echo "'requirements.txt' unchanged (or only changed by bot)"

0 commit comments

Comments
 (0)