Sub topic 9
Keeping actions up to date with Dependabot
This chapter assumes you can read a workflow file and know how uses references an action with owner/repo@ref. It also assumes you have seen the trade-offs between tags and commit SHAs from the previous chapter on versioning.
Why pinned actions go stale
Pinning an action to a version makes your builds repeatable. It also freezes you in place. A workflow that uses actions/checkout@v3 keeps running that version, even after the maintainers ship fixes for bugs and security problems.
Doing this by hand does not scale. You would need to watch every action's releases, read the changelogs, and edit each workflow file. Dependabot automates that work. It checks the actions your workflows use and opens a pull request when a newer version exists.
Turning on version updates
Dependabot version updates are configured by a file named .github/dependabot.yml on your default branch. This example watches the GitHub Actions ecosystem once a week:
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"The three keys that matter here are:
package-ecosystemselects what to scan. The valuegithub-actionstells Dependabot to read workflow files.directoryis where to look. Forgithub-actions,"/"makes Dependabot scan the workflow files in.github/workflows. Composite action definitions are read from the repository root unless you list their directories.schedule.intervalis how often to check. Accepted values includedaily,weekly, andmonthly.
Commit the file to your default branch. Dependabot then opens its first pull requests on the next scheduled run.
What a Dependabot pull request changes
Suppose a workflow contains this step:
- uses: actions/checkout@v3When a newer major version is released, Dependabot opens a pull request that changes the reference to the new tag. The pull request description lists release notes and commit history, which helps you review the change.
Dependabot also works with pinned SHAs. If you pin to a full-length commit SHA and keep the tag in a trailing comment, Dependabot updates both the SHA and the comment:
- uses: actions/checkout@<full-length-commit-sha> # v4This is the main reason to combine the two practices. SHA pinning protects you from a tag being moved to different code. Dependabot removes the usual cost of SHA pinning, which is that nobody wants to look up new hashes by hand.
Reviewing updates safely
An automated pull request is still a change to code that runs in your pipeline. Treat it like any dependency bump.
- Read the release notes in the pull request description. Look for breaking changes, such as renamed inputs or a new minimum Node.js runtime.
- Check that CI passes on the pull request branch. Your existing workflows exercise the new action version.
- For a major version bump, compare the action's inputs against how you use them. A removed input fails the step or is silently ignored.
- Merge only after review, even for patch updates.
Reducing noise helps reviewers stay careful. You can group updates into one pull request with a groups block:
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
groups:
actions:
patterns:
- "*"With this configuration, all action updates in a run arrive in a single pull request named for the group. The trade-off is that one bad update blocks the whole batch, so a failing action can hold back unrelated ones.
Common problems
| Symptom | Likely cause |
|---|---|
| No pull requests appear | `dependabot.yml` is not on the default branch, or the file has a YAML error. |
| Actions are not detected | The `uses` references are in a directory Dependabot is not scanning. |
| Pull requests fail to run workflows | Workflows triggered by Dependabot get restricted secrets and a read-only token by default. |
| Too many pull requests | Increase the interval or add a `groups` block. |
Exercise
Your workflow pins an action with a full-length commit SHA and a trailing comment # v4. Why is Dependabot a good fit for this setup, and which dependabot.yml key tells it to scan workflow files?
Show answer
SHA pinning keeps builds immutable but makes upgrades tedious, because you must look up each new hash. Dependabot finds the newer release, updates both the SHA and the version comment, and opens a pull request for review. The key is package-ecosystem: "github-actions".
Exercise
You enable Dependabot with a weekly schedule and a groups block that matches all actions. One update in the group breaks CI. What is the cost of this configuration, and how could you avoid it?
Show answer
A single pull request contains every update, so one failure blocks the others from merging. You can narrow the patterns to related actions, remove the groups block so each action gets its own pull request, or close the grouped pull request and let Dependabot propose the updates again.