From 6407b86726c4b536c4aac39537373a8979d9ad79 Mon Sep 17 00:00:00 2001 From: Lancetnik Date: Fri, 27 Nov 2026 15:22:00 +0300 Subject: [PATCH 1/2] ci: limit Dependabot auto-merge to dev-tool patches --- .github/dependabot.yml | 3 +++ .github/workflows/automerge.yml | 45 +++++++++++++++++++++++++++++++++ .github/workflows/test.yml | 12 +++++---- 3 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/automerge.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 9483cee..3bcacac 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -20,6 +20,9 @@ updates: schedule: interval: "weekly" groups: + dev-tools-patch: + patterns: ["ruff", "mypy"] + update-types: ["patch"] pip: patterns: - "*" diff --git a/.github/workflows/automerge.yml b/.github/workflows/automerge.yml new file mode 100644 index 0000000..9e73ec5 --- /dev/null +++ b/.github/workflows/automerge.yml @@ -0,0 +1,45 @@ +name: Dependabot auto-merge + +# Use base-branch code only. Never check out or execute the PR in this job. +on: + pull_request_target: + branches: [develop] + types: [opened, reopened, synchronize, ready_for_review] + +permissions: {} + +jobs: + automerge: + if: >- + github.event.pull_request.user.login == 'dependabot[bot]' && + github.event.pull_request.head.repo.full_name == github.repository && + !github.event.pull_request.draft && github.event.pull_request.commits == 1 && + startsWith(github.event.pull_request.head.ref, 'dependabot/pip/dev-tools-patch-') && + vars.DEPENDABOT_AUTOMERGE == 'true' + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + steps: + - uses: dependabot/fetch-metadata@25dd0e34f4fe68f24cc83900b1fe3fe149efef98 # v3 + id: metadata + - name: Enable auto-merge for verified dev-tool patches + env: + GH_TOKEN: ${{ github.token }} + PR: ${{ github.event.pull_request.number }} + HEAD_SHA: ${{ github.event.pull_request.head.sha }} + UPDATES: ${{ steps.metadata.outputs.updated-dependencies-json }} + run: | + if ! jq -e 'type == "array" and length > 0 and all(.[]; + .packageEcosystem == "pip" and .dependencyGroup == "dev-tools-patch" and + .dependencyType == "direct:development" and .updateType == "version-update:semver-patch" and + (.dependencyName | IN("ruff", "mypy")))' <<< "${UPDATES:-[]}" > /dev/null; then + echo 'Not an allowlisted patch group; leaving this PR for review.' + exit 0 + fi + files=$(gh api --paginate "repos/$GITHUB_REPOSITORY/pulls/$PR/files" --jq '.[].filename') + if ! grep -q . <<< "$files" || grep -qvEx 'pyproject\.toml' <<< "$files"; then + echo 'Unexpected changed files; leaving this PR for review.' + exit 0 + fi + gh pr merge "$PR" --repo "$GITHUB_REPOSITORY" --auto --squash --match-head-commit "$HEAD_SHA" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7e29efb..4dfa61f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -61,12 +61,12 @@ jobs: - name: Test run: bash scripts/test.sh env: - COVERAGE_FILE: coverage/.coverage.${{ runner.os }}-py${{ matrix.python-version }}-${{ matrix.pydantic-version }} - CONTEXT: ${{ runner.os }}-py${{ matrix.python-version }}-${{ matrix.pydantic-version }} + COVERAGE_FILE: coverage/.coverage.${{ runner.os }}-py${{ matrix.python-version }} + CONTEXT: ${{ runner.os }}-py${{ matrix.python-version }} - name: Store coverage files uses: actions/upload-artifact@v7 with: - name: .coverage.${{ runner.os }}-py${{ matrix.python-version }}-${{ matrix.pydantic-version }} + name: .coverage.${{ runner.os }}-py${{ matrix.python-version }} path: coverage if-no-files-found: error include-hidden-files: true @@ -109,10 +109,12 @@ jobs: include-hidden-files: true # https://github.com/marketplace/actions/alls-green#why - check: # This job does nothing and is only used for the branch protection - if: github.event.pull_request.draft == false + check: # Aggregate required status for branch protection, including failed prerequisites. + if: always() && github.event.pull_request.draft == false needs: + - static_analysis + - test - coverage-combine runs-on: ubuntu-latest From 574a462d280054c2acc236e1e18631c0aadaea81 Mon Sep 17 00:00:00 2001 From: Lancetnik Date: Fri, 27 Nov 2026 15:37:33 +0300 Subject: [PATCH 2/2] ci: auto-merge Dependabot updates after required checks --- .github/dependabot.yml | 7 ++++--- .github/workflows/automerge.yml | 35 ++++++++++++--------------------- 2 files changed, 17 insertions(+), 25 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 3bcacac..bcc69ff 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -8,6 +8,8 @@ updates: # GitHub Actions - package-ecosystem: "github-actions" directory: "/" + cooldown: + default-days: 7 schedule: interval: "weekly" groups: @@ -17,12 +19,11 @@ updates: # Python - package-ecosystem: "pip" # See documentation for possible values directory: "/" # Location of package manifests + cooldown: + default-days: 7 schedule: interval: "weekly" groups: - dev-tools-patch: - patterns: ["ruff", "mypy"] - update-types: ["patch"] pip: patterns: - "*" diff --git a/.github/workflows/automerge.yml b/.github/workflows/automerge.yml index 9e73ec5..034f0e3 100644 --- a/.github/workflows/automerge.yml +++ b/.github/workflows/automerge.yml @@ -1,8 +1,8 @@ name: Dependabot auto-merge -# Use base-branch code only. Never check out or execute the PR in this job. +# API calls only. Do not check out the PR or run code or artifacts from it. on: - pull_request_target: + pull_request_target: # zizmor: ignore[dangerous-triggers] -- no PR code runs with write access. branches: [develop] types: [opened, reopened, synchronize, ready_for_review] @@ -13,33 +13,24 @@ jobs: if: >- github.event.pull_request.user.login == 'dependabot[bot]' && github.event.pull_request.head.repo.full_name == github.repository && - !github.event.pull_request.draft && github.event.pull_request.commits == 1 && - startsWith(github.event.pull_request.head.ref, 'dependabot/pip/dev-tools-patch-') && + !github.event.pull_request.draft && vars.DEPENDABOT_AUTOMERGE == 'true' runs-on: ubuntu-latest permissions: contents: write pull-requests: write + env: + GH_TOKEN: ${{ github.token }} + PR: ${{ github.event.pull_request.number }} + HEAD_SHA: ${{ github.event.pull_request.head.sha }} steps: - - uses: dependabot/fetch-metadata@25dd0e34f4fe68f24cc83900b1fe3fe149efef98 # v3 - id: metadata - - name: Enable auto-merge for verified dev-tool patches - env: - GH_TOKEN: ${{ github.token }} - PR: ${{ github.event.pull_request.number }} - HEAD_SHA: ${{ github.event.pull_request.head.sha }} - UPDATES: ${{ steps.metadata.outputs.updated-dependencies-json }} + - name: Enable auto-merge for signed Dependabot commits run: | - if ! jq -e 'type == "array" and length > 0 and all(.[]; - .packageEcosystem == "pip" and .dependencyGroup == "dev-tools-patch" and - .dependencyType == "direct:development" and .updateType == "version-update:semver-patch" and - (.dependencyName | IN("ruff", "mypy")))' <<< "${UPDATES:-[]}" > /dev/null; then - echo 'Not an allowlisted patch group; leaving this PR for review.' - exit 0 - fi - files=$(gh api --paginate "repos/$GITHUB_REPOSITORY/pulls/$PR/files" --jq '.[].filename') - if ! grep -q . <<< "$files" || grep -qvEx 'pyproject\.toml' <<< "$files"; then - echo 'Unexpected changed files; leaving this PR for review.' + commits=$(gh api --paginate --slurp "repos/$GITHUB_REPOSITORY/pulls/$PR/commits?per_page=100") + if ! jq -e --arg head "$HEAD_SHA" 'flatten | length > 0 and last.sha == $head and + all(.[]; .author.login == "dependabot[bot]" and .commit.verification.verified == true)' \ + <<< "$commits" > /dev/null; then + echo 'Not a verified Dependabot head; leaving this PR for manual review.' exit 0 fi gh pr merge "$PR" --repo "$GITHUB_REPOSITORY" --auto --squash --match-head-commit "$HEAD_SHA"