CI - Update 'pre-commit' hooks #46
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
| name: CI - Update 'pre-commit' hooks | |
| on: | |
| schedule: | |
| # At 8:30 (summer time) every Wednesday (6:30 UTC) | |
| # Dependabot runs once a week (every Monday) (pip) | |
| # and every day (GH Actions) between 7:00 and 7:30 (5:00-5:30 UTC) | |
| - cron: "30 6 * * 3" | |
| workflow_dispatch: | |
| jobs: | |
| # Do not use SINTEF/ci-cd as it cannot run pre-commit autoupdate on sub-folder | |
| # pre-commit configurations. | |
| create-collected-pr: | |
| name: Single dependabot PR | |
| if: github.repository_owner == 'EMMC-ASBL' | |
| runs-on: ubuntu-latest | |
| env: | |
| GIT_USER_NAME: "TEAM 4.0[bot]" | |
| GIT_USER_EMAIL: "Team4.0@SINTEF.no" | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| with: | |
| ref: master | |
| - name: Set up Python 3.10 | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: "3.10" | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install -U pip | |
| pip install -U setuptools wheel | |
| pip install -r requirements.txt | |
| - name: Set up git user info | |
| run: | | |
| git config --global user.name "${{ env.GIT_USER_NAME }}" | |
| git config --global user.email "${{ env.GIT_USER_EMAIL }}" | |
| - name: Auto-update `pre-commit` hooks | |
| id: update_pre_commit | |
| run: | | |
| pre-commit autoupdate -c \{\{\ cookiecutter.project_slug\ \}\}/.pre-commit-config.yaml | |
| pre-commit autoupdate | |
| if [ -n "$(git status --porcelain .pre-commit-config.yaml \{\{\ cookiecutter.project_slug\ \}\}/.pre-commit-config.yaml)" ]; then | |
| # Set environment variable notifying next steps that the hooks changed | |
| echo "Pre-commit hooks have been updated !" | |
| echo "updated_pre_commit_hooks=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "No pre-commit hooks have been updated." | |
| echo "updated_pre_commit_hooks=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Possibly run `pre-commit` with updated hooks | |
| if: steps.update_pre_commit.outputs.updated_pre_commit_hooks == 'true' | |
| continue-on-error: true # Still create the PR if this step fails | |
| run: pre-commit run --all-files | |
| - name: Possibly commit changes and updates | |
| if: steps.update_pre_commit.outputs.updated_pre_commit_hooks == 'true' | |
| run: git commit -am "Update \`pre-commit\` hooks" | |
| - name: Fetch PR body | |
| id: pr_body | |
| uses: chuhlomin/render-template@v1.10 | |
| with: | |
| template: .github/utils/single_dependency_pr_body.txt | |
| - name: Create PR | |
| id: cpr | |
| uses: peter-evans/create-pull-request@v8 | |
| with: | |
| token: ${{ secrets.RELEASE_PAT }} | |
| committer: "${{ env.GIT_USER_NAME }} <${{ env.GIT_USER_EMAIL }}>" | |
| author: "${{ env.GIT_USER_NAME }} <${{ env.GIT_USER_EMAIL }}>" | |
| branch: ci/update-pre-commit | |
| delete-branch: true | |
| title: "[Auto-generated] Update dependencies" | |
| body: ${{ steps.pr_body.outputs.result }} | |
| labels: CI/CD,skip-changelog | |
| - name: Information | |
| run: 'echo "${{ steps.cpr.outputs.pull-request-operation }} PR #${{ steps.cpr.outputs.pull-request-number }}: ${{ steps.cpr.outputs.pull-request-url }}"' |