-
Notifications
You must be signed in to change notification settings - Fork 1
88 lines (83 loc) · 2.94 KB
/
poetry-export_dependencies.yml
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
name: Poetry export requirements.txt
on:
push:
branches:
- 'main' # Trigger only on pull requests made to the main branch
paths:
- 'requirements.txt'
- 'pyproject.toml'
- 'poetry.lock'
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
poetry-export_dependencies:
strategy:
fail-fast: false
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.12
- name: Install poetry
uses: abatilo/actions-poetry@v4
with:
poetry-version: 'latest'
- name: Install the poetry-plugin-export
run: poetry self add poetry-plugin-export
- name: Update poetry lock file
run: poetry lock
- name: Export the project dependencies to requirements.txt
run: |
poetry export -f requirements.txt --output requirements.txt
- name: Get branch name
shell: bash
run: echo "BRANCH_NAME=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
- name: Fetch main branch
shell: bash
run: git fetch origin main
- name: Check for changes
id: check_changes
shell: bash
run: |
# Use git diff to check actual content changes with the remotte
if ! git diff origin/main --quiet -- requirements.txt poetry.lock; then
echo "changes=true" >> $GITHUB_OUTPUT
else
echo "changes=false" >> $GITHUB_OUTPUT
fi
- name: Configure Git
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
- name: Commit and push if changed
if: steps.check_changes.outputs.changes == 'true'
run: |
# Stage all changes before pulling
git add requirements.txt poetry.lock
# Check if there are staged changes
if git diff --cached --quiet; then
echo "No changes to commit."
else
git commit -m "chore: update requirements.txt and poetry.lock [skip ci]"
fi
# Pull with rebase to get latest changes
git pull --rebase origin ${{ env.BRANCH_NAME }}
# Push with retry logic
max_attempts=3
attempt=1
while [ $attempt -le $max_attempts ]; do
if git push origin ${{ env.BRANCH_NAME }}; then
break
else
if [ $attempt -eq $max_attempts ]; then
echo "Failed to push after $max_attempts attempts"
exit 1
fi
echo "Push failed, attempt $attempt of $max_attempts. Pulling and retrying..."
git pull --rebase origin ${{ env.BRANCH_NAME }}
attempt=$((attempt + 1))
fi
done
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}