|
| 1 | +# File: .github/workflows/upgrade-dependencies.yml |
| 2 | +name: Upgrade dependencies |
| 3 | + |
| 4 | +# taken and adapted from https://www.oddbird.net/2022/06/01/dependabot-single-pull-request/#upgrade-python-dependencies |
| 5 | + |
| 6 | +on: |
| 7 | + workflow_dispatch: # Allow running on-demand |
| 8 | + schedule: |
| 9 | + # Runs every Monday at 5:00 UTC |
| 10 | + - cron: '0 5 * * 1' |
| 11 | + |
| 12 | +jobs: |
| 13 | + upgrade: |
| 14 | + name: Upgrade & Open Pull Request |
| 15 | + runs-on: ubuntu-latest |
| 16 | + env: |
| 17 | + # This branch will receive updates each time the workflow runs |
| 18 | + # It doesn't matter if it's deleted when merged, it'll be re-created |
| 19 | + BRANCH_NAME: auto-dependency-upgrades |
| 20 | + steps: |
| 21 | + - uses: actions/checkout@v3 |
| 22 | + |
| 23 | + # START PYTHON DEPENDENCIES |
| 24 | + - uses: actions/setup-python@v3 |
| 25 | + with: |
| 26 | + python-version: "3.10" |
| 27 | + # cache: pip |
| 28 | + - name: Upgrade Python dependencies |
| 29 | + # ADD YOUR CUSTOM DEPENDENCY UPGRADE COMMANDS BELOW |
| 30 | + run: | |
| 31 | + python -m pip install -r requirements_dev.txt |
| 32 | + #pip-compile --upgrade -o requirements/prod.txt requirements/prod.in |
| 33 | + #pip-compile --upgrade -o requirements/dev.txt requirements/dev.in |
| 34 | + make update-requirements |
| 35 | + python -m pip install -r requirements_dev.txt |
| 36 | + make update-requirements |
| 37 | + # END PYTHON DEPENDENCIES |
| 38 | + |
| 39 | + - name: Detect changes |
| 40 | + id: changes |
| 41 | + run: |
| 42 | + # This output boolean tells us if the dependencies have actually changed |
| 43 | + echo "count=$(git status --porcelain=v1 2>/dev/null | wc -l)" >> $GITHUB_OUTPUT |
| 44 | + - name: Commit & push changes |
| 45 | + # Only push if changes exist |
| 46 | + if: steps.changes.outputs.count > 0 |
| 47 | + env: |
| 48 | + GITHUB_TOKEN: ${{ secrets.AUTOMATE_ISSUES }} |
| 49 | + run: | |
| 50 | + awk -F. -v OFS=. '{$NF += 1 ; print}' VERSION > tmp_VERSION.txt # Update version count |
| 51 | + cat tmp_VERSION.txt > VERSION # Update version count |
| 52 | + rm tmp_VERSION.txt # Update version count |
| 53 | + git config user.name github-actions |
| 54 | + git config user.email github-actions@github.com |
| 55 | + git add . |
| 56 | + git commit -m "Automated dependency upgrades" |
| 57 | + git push -f origin ${{ github.ref_name }}:$BRANCH_NAME |
| 58 | + - name: Open pull request if needed |
| 59 | + if: steps.changes.outputs.count > 0 |
| 60 | + env: |
| 61 | + GITHUB_TOKEN: ${{ secrets.AUTOMATE_ISSUES }} |
| 62 | + # Only open a PR if the branch is not attached to an existing one |
| 63 | + run: | |
| 64 | + PR=$(gh pr list --head $BRANCH_NAME --json number -q '.[0].number') |
| 65 | + if [ -z $PR ]; then |
| 66 | + gh pr create \ |
| 67 | + --head $BRANCH_NAME \ |
| 68 | + --title "Automated dependency upgrades" \ |
| 69 | + --body "Full log: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" |
| 70 | + else |
| 71 | + echo "Pull request already exists, won't create a new one." |
| 72 | + fi |
0 commit comments