-
Notifications
You must be signed in to change notification settings - Fork 7
88 lines (74 loc) · 2.73 KB
/
weekly-poetry-bot.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: Weekly Poetry Update
on:
schedule:
- cron: '0 0 * * 0' # Runs every Sunday at midnight
workflow_dispatch: # Allows manual triggering of the workflow
jobs:
update-dependencies:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
export PATH="$HOME/.local/bin:$PATH"
- name: Set date variable
id: date
run: echo "DATE=$(date +%Y%m%d%H%M)" >> $GITHUB_ENV
- name: Create new branch
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git checkout -b update-dependencies-${{ env.DATE }}
- name: Install dependencies
run: poetry install
- name: Update dependencies
run: poetry update | tee poetry-update.log
- name: Commit changes
run: |
git add poetry.lock
if git diff-index --quiet HEAD; then
echo "No changes detected, creating an empty commit."
git commit --allow-empty -m "chore(deps): :arrows_counterclockwise: no updates for ${{ env.DATE }}"
else
echo "Changes detected, creating a commit with update log."
if [ -f poetry-update.log ]; then
update_log=$(cat poetry-update.log)
else
update_log="No update log available."
fi
git commit -m "$(echo -e "chore(deps): :arrows_counterclockwise: update dependencies ${{ env.DATE }}\n\n$update_log")"
fi
- name: Push changes
run: |
gh auth setup-git
git push -f origin update-dependencies-${{ env.DATE }}
env:
GITHUB_TOKEN: ${{ secrets.WEEKLY_UPDATE }}
- name: Create Pull Request via gh
run: |
gh pr create --title "chore(deps): :arrows_counterclockwise: update dependencies ${{ env.DATE }}" \
--body "This is an auto-generated pull request to update dependencies in `poetry.lock`." \
--base main \
--head update-dependencies-${{ env.DATE }}
env:
GITHUB_TOKEN: ${{ secrets.WEEKLY_UPDATE }}
- name: Add Label to Pull Request
run: |
pr_number=$(gh pr view --json number --jq '.number')
gh pr edit $pr_number --add-label "weekly-update"
env:
GITHUB_TOKEN: ${{ secrets.WEEKLY_UPDATE }}
- name: Merge Pull Request via gh
run: |
gh pr merge update-dependencies-${{ env.DATE }} --merge --auto
env:
GITHUB_TOKEN: ${{ secrets.WEEKLY_UPDATE }}