|
| 1 | +# .github/workflows/dependabot-automation.yml |
| 2 | +# |
| 3 | +# Automates Dependabot PRs by: |
| 4 | +# 1. Updating poetry.lock to match new dependency versions in pyproject.toml |
| 5 | +# 2. Installing updated dependencies and running automated fixes (ruff format, type checks, tests) |
| 6 | +# 3. Committing any changes back to the Dependabot PR branch |
| 7 | +# 4. Waiting for CI checks (Python 3.10 and 3.x) to complete |
| 8 | +# 5. Auto-merging the PR if all checks pass |
| 9 | +# |
| 10 | +# Security: Only runs when github.actor == 'dependabot[bot]', which cannot be spoofed |
| 11 | +# by external users. This is a GitHub-guaranteed trusted identity. |
| 12 | +# |
| 13 | +name: Dependabot Automation |
| 14 | + |
| 15 | +on: |
| 16 | + pull_request: |
| 17 | + paths: |
| 18 | + - 'pyproject.toml' |
| 19 | + |
| 20 | +jobs: |
| 21 | + automate: |
| 22 | + if: github.actor == 'dependabot[bot]' |
| 23 | + runs-on: ubuntu-latest |
| 24 | + permissions: |
| 25 | + contents: write |
| 26 | + pull-requests: write |
| 27 | + steps: |
| 28 | + - uses: actions/checkout@v4 |
| 29 | + with: |
| 30 | + ref: ${{ github.head_ref }} |
| 31 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 32 | + |
| 33 | + - uses: actions/setup-python@v5 |
| 34 | + with: |
| 35 | + python-version: "3.x" |
| 36 | + |
| 37 | + - uses: abatilo/actions-poetry@v2 |
| 38 | + |
| 39 | + - name: Update poetry.lock |
| 40 | + run: poetry lock --no-update |
| 41 | + |
| 42 | + - name: Install dependencies |
| 43 | + run: poetry install |
| 44 | + |
| 45 | + - name: Run formatting and linting fixes |
| 46 | + run: poetry run poe check:fix |
| 47 | + |
| 48 | + - name: Commit changes |
| 49 | + run: | |
| 50 | + git config --global user.name 'github-actions[bot]' |
| 51 | + git config --global user.email 'github-actions[bot]@users.noreply.github.com' |
| 52 | + git add -A |
| 53 | + git diff --staged --quiet || git commit -m "chore: update poetry.lock and apply auto-fixes" |
| 54 | + git push |
| 55 | +
|
| 56 | + - name: Wait for CI to complete |
| 57 | + uses: lewagon/wait-on-check-action@v1.3.4 |
| 58 | + with: |
| 59 | + ref: ${{ github.head_ref }} |
| 60 | + check-name: 'checks' |
| 61 | + repo-token: ${{ secrets.GITHUB_TOKEN }} |
| 62 | + wait-interval: 10 |
| 63 | + |
| 64 | + - name: Auto-merge Dependabot PR |
| 65 | + run: gh pr merge --auto --squash "${{ github.event.pull_request.html_url }}" |
| 66 | + env: |
| 67 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments