|
| 1 | +name: dependabot jobs |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, reopened, synchronize] |
| 6 | + |
| 7 | +permissions: |
| 8 | + pull-requests: write |
| 9 | + contents: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + pre-commit: |
| 13 | + if: github.actor == 'dependabot[bot]' |
| 14 | + runs-on: ubuntu-24.04 |
| 15 | + steps: |
| 16 | + # checks out the repo |
| 17 | + - uses: actions/checkout@v5 |
| 18 | + with: |
| 19 | + # fetch tags for versioning details |
| 20 | + fetch-depth: 0 |
| 21 | + # Check out the branch that Dependabot’s PR is coming from |
| 22 | + ref: ${{ github.event.pull_request.head.ref }} |
| 23 | + repository: ${{ github.event.pull_request.head.repo.full_name }} |
| 24 | + persist-credentials: true |
| 25 | + - name: Fetch tags |
| 26 | + run: git fetch --all --tags |
| 27 | + - name: Python setup |
| 28 | + uses: actions/setup-python@v6 |
| 29 | + with: |
| 30 | + python-version: "3.11" |
| 31 | + - name: Setup for poetry |
| 32 | + run: | |
| 33 | + python -m pip install poetry |
| 34 | + poetry self add "poetry-dynamic-versioning[plugin]" |
| 35 | + - name: Install environment |
| 36 | + run: poetry install --no-interaction --no-ansi |
| 37 | + # run pre-commit |
| 38 | + - uses: pre-commit/action@v3.0.1 |
| 39 | + id: pre_commit |
| 40 | + continue-on-error: true |
| 41 | + - name: Check for changes |
| 42 | + if: ${{ steps.pre_commit.outcome == 'failure' }} |
| 43 | + id: check_changes |
| 44 | + run: | |
| 45 | + if [[ -n "$(git status --porcelain)" ]]; then |
| 46 | + echo "changes_detected=true" >> "$GITHUB_ENV" |
| 47 | + else |
| 48 | + echo "changes_detected=false" >> "$GITHUB_ENV" |
| 49 | + fi |
| 50 | + - name: Commit and push changes |
| 51 | + if: ${{ env.changes_detected == 'true' && |
| 52 | + steps.pre_commit.outcome == 'failure' }} |
| 53 | + run: | |
| 54 | + git config --global user.name "github-actions[bot]" |
| 55 | + git config --global user.email \ |
| 56 | + "github-actions[bot]@users.noreply.github.com" |
| 57 | + git add . |
| 58 | + git commit -m "chore: auto-apply pre-commit fixes" |
| 59 | + git push |
| 60 | + # raise error if there were no changes and pre-commit failed |
| 61 | + - name: Errors detected |
| 62 | + if: ${{ env.changes_detected == 'false' && |
| 63 | + steps.pre_commit.outcome == 'failure' }} |
| 64 | + run: | |
| 65 | + echo 'Pre-commit failed and was unable to make changes' |
| 66 | + exit 1 |
0 commit comments