Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions .github/workflows/dependabot-auto-merge.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Dependabot auto-merge

# Turns on auto-merge (squash) hourly and on manual runs for open, non-draft
# Dependabot pull requests that do not have it yet, in every managed repository
# in repos.jsonnet whose auto_merge is not false. The merge then waits for the
# repository's required checks.
#
# Uses AUTOMATION_TOKEN rather than GITHUB_TOKEN. Merges made with GITHUB_TOKEN
# trigger no workflows; AUTOMATION_TOKEN merges do, so the merge is deployed. A
# managed repository needs no auto-merge workflow of its own and no
# AUTOMATION_TOKEN in its Dependabot secrets.
#
# If turning on auto-merge fails on one pull request, the error is reported,
# the rest still run and the job fails at the end.

on:
schedule:
- cron: "23 * * * *"
workflow_dispatch:

permissions:
contents: read

concurrency:
group: dependabot-auto-merge

jobs:
auto-merge:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: bazel-contrib/setup-bazel@f34d6a05eae3c24acab7fa54587492daeaeffdab # 0.19.2
with:
bazelisk-cache: true
disk-cache: ${{ github.workflow }}
repository-cache: true
- name: Repositories
run: |
bazel build --lockfile_mode=error //:repos
jq -r '.managed | to_entries[] | select(.value.auto_merge != false) | .key' bazel-bin/repos.json > "$RUNNER_TEMP/repos"
cat "$RUNNER_TEMP/repos"
- name: Turn on auto-merge
env:
GH_TOKEN: ${{ secrets.AUTOMATION_TOKEN }}
OWNER: ${{ github.repository_owner }}
run: |
failed=0
while read -r name; do
repo="$OWNER/$name"
prs=$(gh pr list -R "$repo" --author app/dependabot --state open --json number,autoMergeRequest,isDraft \
--jq '.[] | select(.autoMergeRequest == null and (.isDraft | not)) | .number')
for pr in $prs; do
echo "$repo#$pr"
gh pr merge "$pr" -R "$repo" --auto --squash || { echo "::error::could not turn on auto-merge for $repo#$pr"; failed=1; }
done
done < "$RUNNER_TEMP/repos"
exit "$failed"
9 changes: 5 additions & 4 deletions .github/workflows/scheduled-bazel-updates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ name: Scheduled Bazel updates

# Runs bazel-updates.yml daily and on manual runs for every managed repository
# in repos.jsonnet with build: bazel, passing each repository's bazel_updates
# fields. A Bazel repository in the list needs no workflow of its own.
# and auto_merge fields. A Bazel repository in the list needs no workflow of
# its own.

on:
schedule:
Expand Down Expand Up @@ -33,14 +34,14 @@ jobs:
run: |
bazel build --lockfile_mode=error //:repos
# One matrix entry per Bazel repository, with defaults for omitted
# bazel_updates fields. Check auto_merge against null rather than
# using //, which would also replace an explicit false.
# fields. Check auto_merge against null rather than using //, which
# would also replace an explicit false.
matrix=$(jq -c --arg owner "$OWNER" '{include: [
.managed | to_entries[] | select(.value.build == "bazel") | {
repository: "\($owner)/\(.key)",
skip_modules: ((.value.bazel_updates.skip_modules // []) | join(" ")),
bazelversion_files: ((.value.bazel_updates.bazelversion_files // [".bazelversion"]) | join(" ")),
auto_merge: (.value.bazel_updates.auto_merge | if . == null then true else . end)
auto_merge: (.value.auto_merge | if . == null then true else . end)
}
]}' bazel-bin/repos.json)
echo "$matrix" | jq .
Expand Down
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ in `github/` or `repos.jsonnet` to keep it, or run the Settings workflow on
[`scheduled-bazel-updates.yaml`](.github/workflows/scheduled-bazel-updates.yaml)
runs [`bazel-updates.yml`](.github/workflows/bazel-updates.yml) daily and on
manual runs for every managed repository in `repos.jsonnet` with
`build: bazel`, passing that repository's `bazel_updates` fields. Adding a
Bazel repository to `repos.jsonnet` is enough; it needs no workflow of its own.
`build: bazel`, passing that repository's `bazel_updates` and `auto_merge`
fields. Adding a Bazel repository to `repos.jsonnet` is enough; it needs no
workflow of its own.

`bazel-updates.yml` makes the updates that Dependabot cannot. Dependabot's
`bazel` updater evaluates `MODULE.bazel` without the files that module
Expand Down Expand Up @@ -106,3 +107,23 @@ Another repository can still call
commit SHA with the release tag as a comment (`@<commit sha> # v1.1.0`) so
Dependabot's `github-actions` updater updates both on new releases. Releases
are tagged with full semantic versions so Dependabot can compare them.

## Dependabot auto-merge

[`dependabot-auto-merge.yaml`](.github/workflows/dependabot-auto-merge.yaml)
runs hourly and on manual runs for every managed repository in `repos.jsonnet`
whose `auto_merge` field is not `false`. It turns on auto-merge (squash) for
each open, non-draft Dependabot pull request that does not have it yet; the
merge then waits for the repository's required checks. If turning on auto-merge
fails on one pull request, the error is reported, the rest still run and the
job fails at the end.

Managed repositories need no auto-merge workflow of their own and no
`AUTOMATION_TOKEN` in their Dependabot secrets. Set `auto_merge: false` in
`repos.jsonnet` to keep a repository's Dependabot and Bazel update pull
requests manual.

The workflow uses the `AUTOMATION_TOKEN` secret, which needs read and write
access to **Pull requests** and **Contents** on each repository. Merges made
with `GITHUB_TOKEN` trigger no workflows; `AUTOMATION_TOKEN` merges do, so the
merge is deployed.
12 changes: 10 additions & 2 deletions repos.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ local fork = 'Fork kept for upstream pull requests.';
},

'git-witness': {
// Without required checks, auto-merge would merge Dependabot pull
// requests at once, untested. Stays manual until it has a check that
// tests the cosign action.
auto_merge: false,
build: 'none',
// Its only workflow responds to issues, so nothing runs on pull requests.
required_checks: [],
Expand All @@ -53,6 +57,12 @@ local fork = 'Fork kept for upstream pull requests.';
},

'github-infra': {
// The Settings workflow does not plan Dependabot pull requests so
// ADMIN_TOKEN never reaches them; an auto-merged provider update would
// apply without a plan. Stays manual until issue #21 gives them a
// read-only plan. As a side effect, this repository's Bazel updates also
// wait for a person.
auto_merge: false,
description: 'Shared configuration for the benbirt GitHub account: the repository list, managed repository settings and reusable GitHub Actions workflows.',
build: 'bazel',
required_checks: ['lint'],
Expand Down Expand Up @@ -89,8 +99,6 @@ local fork = 'Fork kept for upstream pull requests.';
'e2e/*/.bazelversion',
'tests/integration/*/.bazelversion',
],
// Update pull requests are merged manually because this is a library.
auto_merge: false,
},
},

Expand Down
10 changes: 5 additions & 5 deletions schema/repos.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
"items": { "type": "string", "minLength": 1 },
"uniqueItems": true
},
"auto_merge": {
"description": "Whether to turn on auto-merge (squash) for pull requests from Dependabot and the Bazel updates workflow.",
"type": "boolean",
"default": true
},
"direct_pushes": {
"description": "Whether commits may be pushed directly to the default branch without a pull request, for repositories whose own workflows commit there.",
"type": "boolean",
Expand Down Expand Up @@ -101,11 +106,6 @@
"items": { "type": "string", "minLength": 1 },
"minItems": 1,
"uniqueItems": true
},
"auto_merge": {
"description": "Whether to enable squash auto-merge on opened pull requests.",
"type": "boolean",
"default": true
}
}
}
Expand Down