-
Notifications
You must be signed in to change notification settings - Fork 0
68 lines (63 loc) · 2.66 KB
/
upgrade-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
# Built on https://www.oddbird.net/2022/06/01/dependabot-single-pull-request/
name: Upgrade dependencies
on:
workflow_dispatch: # Allow running on-demand
schedule:
# Runs every Monday at 8:00 UTC (4:00 Eastern)
- cron: '0 6 * * 1'
jobs:
upgrade:
name: Upgrade & Open Pull Request
runs-on: ubuntu-latest
env:
# This branch will receive updates each time the workflow runs
# It doesn't matter if it's deleted when merged, it'll be re-created
BRANCH_NAME: auto-dependency-upgrades
steps:
- uses: actions/checkout@v3
with:
# [Optional] Use a separate key to automatically execute checks on the resulting PR
# https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md#triggering-further-workflow-runs
ssh-key: ${{ secrets.DEPLOY_KEY }}
# START PYTHON DEPENDENCIES
- uses: actions/setup-python@v4
with:
python-version: "3.10"
cache: pip
- name: Upgrade Python dependencies
# ADD YOUR CUSTOM DEPENDENCY UPGRADE COMMANDS BELOW
run: |
pip install -U pip pip-tools
pip-compile --upgrade -o requirements.txt requirements.in
# END PYTHON DEPENDENCIES
- name: Detect changes
id: changes
run:
# This output boolean tells us if the dependencies have actually changed
# echo "::set-output name=count::$(git status --porcelain=v1 2>/dev/null | wc -l)"
# echo "::set-output name=count::$(git status --porcelain=v1 2>/dev/null | wc -l)"
echo "count=$(git status --porcelain=v1 2>/dev/null | wc -l)" >> $GITHUB_OUTPUT
- name: Commit & push changes
# Only push if changes exist
if: steps.changes.outputs.count > 0
run: |
git config user.name github-actions
git config user.email github-actions@github.com
git add .
git commit -m "Automated dependency upgrades"
git push -f origin ${{ github.ref_name }}:$BRANCH_NAME
- name: Open pull request if needed
if: steps.changes.outputs.count > 0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Only open a PR if the branch is not attached to an existing one
run: |
PR=$(gh pr list --head $BRANCH_NAME --json number -q '.[0].number')
if [ -z $PR ]; then
gh pr create \
--head $BRANCH_NAME \
--title "Automated dependency upgrades" \
--body "Full log: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
else
echo "Pull request already exists, won't create a new one."
fi