-
Notifications
You must be signed in to change notification settings - Fork 27
88 lines (71 loc) · 2.5 KB
/
requirments-sync.yml
File metadata and controls
88 lines (71 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# Netlify requires requirements.txt (humans do not)
name: Sync requirements.txt with pyproject.toml
on:
pull_request:
paths: ['poetry.lock']
types: [opened, synchronize, reopened]
permissions:
contents: write
jobs:
detect-requirements-delta:
runs-on: ubuntu-latest
outputs:
has_change: ${{ steps.detect.outputs.has_change }}
# Skip if the last commit was from the bot (prevent infinite loops)
if: github.event.head_commit.author.name != 'github-actions[bot]'
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref || github.ref_name }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version-file: 'pyproject.toml'
- name: Install Poetry
run: pip install poetry
- name: Install Dependencies via Poetry
run: poetry install --only main --no-root
- name: Detect whether requirements.txt has change
id: detect
run: |
output=$(make requirements.txt 2>&1)
echo "$output"
# Check whether Make output suggests file is up to date
if echo "$output" | grep -qi "up to date\|up-to-date\|already up to date"; then
echo "has_change=false" >> $GITHUB_OUTPUT
echo "::notice::requirements.txt seems up to date"
else
echo "has_change=true" >> $GITHUB_OUTPUT
fi
commit-requirements-delta:
runs-on: ubuntu-latest
needs: detect-requirements-delta
if: needs.detect-requirements-delta.outputs.has_change == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref || github.ref_name }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version-file: 'pyproject.toml'
- name: Install Poetry
run: pip install poetry
- name: Generate requirements.txt
run: make requirements.txt
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Commit requirements.txt if changed
run: |
git add -f requirements.txt
if git diff --staged --quiet; then
echo "No changes to requirements.txt"
else
git commit -m "chore: auto-update requirements.txt [bot]"
git push
fi