Dependabot and GitHub Actions
Tags: github, githubactions, dependabot
Published: 2023-02-16 16:10:44

---
title: Dependabot and GitHub Actions
published: true
description: Just because some people are bound to be even more out of date than me
tags: github, githubactions, dependabot
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hlnxm9h268zml0cc7cey.png
# Use a ratio of 100:42 for best results.
# published_at: 2023-02-16 15:32 +0000
---

If you're using GitHub Workflows to automate bits of your development process (test runs, deployment, stuff like that) then you're almost certainly using GitHub Actions as well. Actions are pre-build chunks of functionality that you can use in your workflows and which save you having to write a load of code yourself. I've never, for example, written a workflow definition that doesn't use [actions/checkout](https://github.com/marketplace/actions/checkout) to checkout the current repo on the container that is running that workflow. Part of my workflow definition will always look like this:

    steps:
      - name: Check out code
        uses: actions/checkout@v3

Or, at least, it will look a lot like that. The bit that might change is that `v3` on the end there. That is, of course, the version of the action that I'm using. And that will change when the author of the action releases a new version. Well, strictly speaking, it will change when I notice that there's a new version and bother to update the workflow definition.

Recently, I noticed that two of the actions I use frequently (including the checkout action which I use *everywhere*) had updated their version numbers and I hadn't known about the change. It took a few hours of work to update the version numbers in all of my workflow definitions.

And life isn't supposed to be that much work.

But there's a solution. And I discovered it thanks to [a discussion on Reddit](https://www.reddit.com/r/github/comments/1134qvp/github_actions_is_it_safe_to_use_master/).

If you're doing much work on GitHub (particularly in the Javascript/Node) area, then you'll have met [Dependabot](https://github.com/dependabot). It's a bot that scans GitHub repos for dependencies that are out of date and then (and here's the really clever bit!) it generates pull requests that update the repo to use the updated versions.

To be honest, I don't have many projects on GitHub that use the technologies that Dependabot targets by default. The few I have are web sites that use frameworks I've cloned from elsewhere - so I get the occasional PR that updates `packages.json` and I just apply them and forget about it.

But it seems that Dependabot can do far more than that. You just need to configure it properly in your repo. And one of the things it can do is to scan for out of date actions being used in your workflow definitions. You just need a file called `dependabot.yml` in your `.github` directory and the contents should look like this:

    # Set update schedule for GitHub Actions

    version: 2
    updates:

      - package-ecosystem: "github-actions"
        directory: "/"
        schedule:
          # Check for updates to GitHub Actions every week
          interval: "weekly"

Dependabot will then check your actions versions once a week and create PRs for any that are out of date. I know it works, because I added this to all of my repos this morning and it promptly created half a dozen PRs for repos where I had updated the versions but hadn't pushed the changes to GitHub. When I pushed the existing changes, Dependabot checked its PR against the new code, realised the PR was no longer needed and closed the PR. Which was nice :-)

It you're using GitHub Workflows (and I can't really think of any reason why you wouldn't be) then I recommend adding this file to your repos. Of course, GitHub has [documentation about this feature](https://docs.github.com/en/code-security/dependabot/working-with-dependabot/keeping-your-actions-up-to-date-with-dependabot).

Dependabot clearly has more uses than I thought it did. I'm going to have to investigate it further. I wonder if it can check CPAN dependencies.

Do you have any Dependabot tricks that I would find useful?