Start free

Keep Laravel packages current with Dependabot

Let Dependabot open a pull request for every Composer and npm update, let GitHub Actions test it, merge the safe ones by themselves and deploy on push.

In this post
  1. Can a bot keep a Laravel app's packages current?
  2. Who updates what
  3. Tell Dependabot what to watch
  4. Test every update
  5. Merge the safe ones by themselves
  6. And then it goes live
  7. What is left for you

Brewless keeps everything under your Laravel app current by itself: PHP, the system libraries and the web server get every fix, production last. What it leaves alone is your own code, and that includes composer.lock and package-lock.json. That is where a maintenance contract usually still earns its money: someone runs composer update once a month and checks that nothing broke.

GitHub can do most of that for you. This post sets up Dependabot to open the pull requests, GitHub Actions to test them, and Brewless Deploy on push to put the merge live.

Can a bot keep a Laravel app's packages current?

Yes. Dependabot, which is built into GitHub and free, opens a pull request for every Composer and npm update it finds, and one at once for every security advisory with a fix. A GitHub Actions workflow runs your tests on each of them, and the patch and minor updates that pass can be merged without you. What is left for a person is the major upgrade, a few times a year.

Who updates what

Layer Updated by
Linux, PHP and its extensions, FrankenPHP, Caddy Brewless, by itself (how)
Composer packages, Laravel included You, or Dependabot with your tests
npm packages You, or Dependabot with your tests
Your own code You

Tell Dependabot what to watch

One file in the repository is enough:

.github/dependabot.yml
version: 2
updates:
  - package-ecosystem: composer
    directory: /
    schedule:
      interval: weekly
    groups:
      composer-minor-and-patch:
        update-types: [minor, patch]
    ignore:
      - dependency-name: laravel/framework
        update-types: [version-update:semver-major]

  - package-ecosystem: npm
    directory: /
    schedule:
      interval: weekly
    groups:
      npm-minor-and-patch:
        update-types: [minor, patch]

  - package-ecosystem: github-actions
    directory: /
    schedule:
      interval: monthly

The groups put all minor and patch updates of one week in one pull request instead of twenty. A major version of any other package still gets a pull request of its own, so you see it apart.

Then switch on Dependabot alerts and Dependabot security updates in the repository's security settings. Those do not wait for the weekly schedule: when an advisory with a fix appears for a package in your lock file, the pull request comes the same day.

Note

Workflows that run for a Dependabot pull request get a read-only token and none of your Actions secrets. That is on purpose: the code in that pull request comes from outside. Keep your tests free of secrets, or store the few they need under Dependabot secrets.

Test every update

A pull request from a bot is only as safe as the checks it has to pass. Run your test suite and composer audit on every pull request:

.github/workflows/tests.yml
name: Tests

on:
  pull_request:
  push:
    branches: [main]

jobs:
  tests:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: shivammathur/setup-php@v2
        with:
          php-version: '8.4'
      - uses: actions/setup-node@v4
        with:
          node-version: 22
      - run: composer install --no-interaction --prefer-dist
      - run: npm ci
      - run: npm run build
      - run: cp .env.example .env && php artisan key:generate
      - run: php artisan test
      - run: composer audit
      - run: npm audit --audit-level=high

composer audit fails the job when a package in the lock file has a known advisory, so an update that leaves one behind shows red.

Then make the check required. Under Settings, Branches (or Rules), protect main and require the tests job to pass before a merge.

Merge the safe ones by themselves

Turn on Allow auto-merge under Settings, General. A second workflow asks GitHub to merge every Dependabot pull request that is not a major update, as soon as the required checks are green:

.github/workflows/dependabot-merge.yml
name: Merge Dependabot updates

on: pull_request

permissions:
  contents: write
  pull-requests: write

jobs:
  merge:
    if: github.actor == 'dependabot[bot]'
    runs-on: ubuntu-latest
    steps:
      - id: metadata
        uses: dependabot/fetch-metadata@v2
      - if: steps.metadata.outputs.update-type != 'version-update:semver-major'
        run: gh pr merge --auto --squash "$PR_URL"
        env:
          PR_URL: ${{ github.event.pull_request.html_url }}
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

--auto does not merge now: it tells GitHub to merge once the tests pass. A red update stays open, with the failing test in front of you.

And then it goes live

Here a detail of GitHub matters. A merge made with a workflow's GITHUB_TOKEN starts no new workflow run, to keep workflows from triggering each other in a loop. A deploy workflow that listens to pushes on main therefore stays quiet after an automatic merge.

Deploy on push does not depend on that. It listens to GitHub's webhook, which is sent for every push, whoever made it. The merge reaches main, the webhook arrives, a job in your own Scaleway project fetches the commit with a read-only deploy key, and the release goes live like any deploy: release commands first, and the release before it stays live when something fails. See Deploy Laravel on every push.

Tip

Deploy from your own workflow with a pipeline token instead? Then let the merge workflow use a token of a GitHub App or a fine-grained personal access token rather than GITHUB_TOKEN, so its merge starts your deploy workflow.

What is left for you

  • Major upgrades, Laravel's above all. Read the upgrade guide, let a coding agent do the work with you, and merge it on purpose.
  • A red update. The pull request stays open with the failing test. Most often a package changed something your code relied on.
  • A new PHP version. Patch releases within your version arrive by themselves on Brewless; moving to the next version is a line in brewless.yml and a deploy. See New PHP versions by themselves.

That is the part a maintenance contract would charge for every month. With the three files above, most weeks it is a pull request you never have to open.

Frequently asked questions

Does Brewless update my Composer and npm packages?

No. Brewless patches what runs under your app, such as PHP, the Debian libraries and the web server. Your Composer and npm packages are part of your code and stay as your lock files say; Dependabot on GitHub can keep them current for you.

How do I let Dependabot update a Laravel app?

Add a file .github/dependabot.yml with an entry for the composer ecosystem and one for npm, each with a schedule such as weekly. Dependabot then opens a pull request for every update, and the repository's security settings let it open one at once for an advisory with a fix.

Can Dependabot pull requests be merged automatically?

Yes. Turn on auto-merge in the repository, require your test workflow to pass on the main branch, and let a small workflow call gh pr merge --auto for patch and minor updates. GitHub merges each one once its checks are green.

Why does my deploy workflow not run after an automatic merge?

A merge made with the GITHUB_TOKEN of a workflow starts no new workflow run, so a deploy workflow that listens to pushes on main stays quiet. Brewless Deploy on push listens to GitHub's webhook instead, which is sent for that push too.

Should Dependabot upgrade Laravel to a new major version?

Not by itself. A major version can change behaviour that your tests do not cover. Ignore major updates of laravel/framework in dependabot.yml and do that upgrade on purpose, with a coding agent or a developer.

All posts Read this post as markdown

Try it on your own app

Brewless deploys your Laravel app to Scaleway and bunny.net, in your own accounts. Start free with one application, production included.