DEV Community

Frederic Lepied
Frederic Lepied

Posted on

Streamlining Testing Multi-Repository Changes with the Depends-On GitHub Action

Handling dependencies across multiple repositories can be a hurdle, especially when changes must be tested across interconnected Pull Requests (PRs). The Depends-On GitHub Action is here to ease that burden by enabling the installation and configuration of dependent PRs, ensuring they are seamlessly integrated into the subsequent steps of your workflow whenever the action is triggered.

Imagine working on a project where the codebase is distributed across various repositories. For instance, you might have a library in one repository and a program that utilizes this library in another. Let's say you have a new feature requiring library and program changes. The typical approach would involve creating PRs in both repositories and then waiting for the dependent PR to merge before the other can be tested and merged. This process can be time-consuming and error-prone.

Depends-On action is a game-changer in such scenarios. It enables you to declare dependencies between PRs across different repositories, ensuring that they are tested together, thus saving time and reducing the margin for error. This is particularly useful in microservices architectures or projects with shared libraries.

Here's a glimpse of how it operates: the action extracts all the declared dependencies from the description of the main PR using the syntax Depends-On: <PR url>. You can specify multiple dependencies by adding multiple Depends-On: lines in the description of the main PR.

Let's delve into a practical example using the Go language:

Go Lang Example

Suppose you have a Go project with a go.mod file defining its dependencies. You make a change in a library, and now you need to test this change in a program that depends on this library. Here's how you could use the Depends-On action:

  • Use the new function from a change in a project used in the go.mod.
  • Next, create a PR in the program repository, and in the PR description, add the line:
Depends-On: https://github.com/org/library/pull/123
Enter fullscreen mode Exit fullscreen mode
  • When the GitHub action workflow is triggered in the program repository, the Depends-On action will kick in. It reads the Depends-On: line from the PR description, identifies the dependent PR, and modifies the go.mod file in the program repository to use the library PR's branch instead of the main branch.
  • The action inserts a replace directive in the go.mod file pointing to the library PR's branch, allowing you to test the program with the new library changes before merging to the main branch.

This action needs to be placed after installing the Go lang toolchain in your GitHub workflow file:

name: Pull Request
on:
  pull_request:
    types: [opened, synchronize, reopened]
jobs:
  validate-tests:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Install the go toolchain
        uses: actions/setup-go@v4

      - name: Extract dependent Pull Requests
        uses: depends-on/depends-on-action@0.7.0
        with:
          token: ${{ secrets.GITHUB_TOKEN }}

      - name: Build
        run: go build

  check-all-dependencies-are-merged:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Extract dependent PR
        uses: depends-on/depends-on-action@0.7.0
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          check-unmerged-pr: true
Enter fullscreen mode Exit fullscreen mode

The Depends-On action simplifies managing dependencies and expedites the testing process across multiple repositories, making your development workflow more efficient and error-resistant. With just a few lines in your PR description, you can now ensure that all related changes are tested together, maintaining the integrity and reliability of your projects across all repositories.

Top comments (0)