Upgrade dependencies #9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # File: .github/workflows/upgrade-dependencies.yml | |
| name: Upgrade dependencies | |
| # taken and adapted from https://www.oddbird.net/2022/06/01/dependabot-single-pull-request/#upgrade-python-dependencies | |
| on: | |
| workflow_dispatch: # Allow running on-demand | |
| schedule: | |
| # Runs every Monday at 5:00 UTC | |
| - cron: '0 5 * * 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 | |
| # START PYTHON DEPENDENCIES | |
| - uses: actions/setup-python@v3 | |
| with: | |
| python-version: "3.10" | |
| # cache: pip | |
| - name: Upgrade Python dependencies | |
| # ADD YOUR CUSTOM DEPENDENCY UPGRADE COMMANDS BELOW | |
| run: | | |
| python -m pip install -r requirements_dev.txt | |
| #pip-compile --upgrade -o requirements/prod.txt requirements/prod.in | |
| #pip-compile --upgrade -o requirements/dev.txt requirements/dev.in | |
| make update-requirements | |
| python -m pip install -r requirements_dev.txt | |
| make update-requirements | |
| # END PYTHON DEPENDENCIES | |
| - name: Detect changes | |
| id: changes | |
| run: | |
| # This output boolean tells us if the dependencies have actually changed | |
| 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 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.AUTOMATE_ISSUES }} | |
| run: | | |
| awk -F. -v OFS=. '{$NF += 1 ; print}' VERSION > tmp_VERSION.txt # Update version count | |
| cat tmp_VERSION.txt > VERSION # Update version count | |
| rm tmp_VERSION.txt # Update version count | |
| 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.AUTOMATE_ISSUES }} | |
| # 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 |