Creating dependencies between PRs in multi-repo Projects in GitHub

IlyesAj
4 min readSep 12, 2023

--

Background

Over the last decade, the monorepo approach was considered the optimal method for managing Git projects. It offers simplicity for Developers, Owners, and Ops teams to manage everything in the same place. A new era has come and emerging architectures like microservices and micro-frontend or new trending philosophies like Gitops are now pushing the limits of this approach.

Managing a monorepo can be very challenging particularly with multiple teams working on multiple branches/ folders each with its own set of testing cases, code styling, and approvers. The challenges become evident when attempting to merge work into the master branch, as conflicts arising from other commits can result in a substantial effort.

In our company, we decided to isolate every project into a repository. With this approach, we guarantee:

  • independency: A single change will affect only the project in scope, eliminating the risk of impacting the entire codebase.
  • Scalability: Working in a multi-repository approach avoids complex workflows and controls, simplifies the additions of new features, and facilitates the onboarding of new people.
  • isolation of issues/PRs(Pull Requests): Instead of adding tons of labels to define which owner, which project, and which feature, on PRs/issues you will rather be focusing on tagging based on functionality/type of issue/PR since multi-repo guarantees the first level of isolation

Multi-repo approach can also be challenging when it comes to projects/repos that depends on each other …

That’s where this blog can be helpful.

PR on a project depends on PR from another Project

Let’s get a real example of a dependency problem. Let’s imagine that you have a functionality that depends on an SDK that you developed, the main repo (repo A) will consume functions developped within SDK’s repo ( repo B) .

Dependencies between repo A and repo B
  • How you will guarantee that PR in Repo A will be blocked if PR in repo B is not merged yet ?
  • How do you link PR on repo A to PR repo B so that reviewer can understand dependencies ?
  • How you can guarantee that PR on repo B is merged before you merge in repo A ( in automated way of course)

PR Dependency Check Action

Greg Dennis one of the developpers of dependencies-action did a great work by creating GitHub Action that enforces PR dependencies directly within a PR’s opening comment.

the job willl automatically parses the first comment of a PR looking for the key phrases “Depends on” or “Blocked by” followed by a reference to an issue or a PR.

In order to integrate it within your repository, you can add the following workflow in the repository where the dependency will be declared (in my example it will be in repo A)

workflows needs to be added in a .yaml file within .github/workflows

on: [pull_request]

jobs:
check_dependencies:
runs-on: ubuntu-latest
name: Check Dependencies
steps:
- uses: gregsdennis/dependencies-action@1.3.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

This workflow will run on every push on any PR, and uses native `GITHUB_TOKEN` to check whether the PR/issue is open or not. If the action succeeds, the PR will be mergeable; otherwise, it fails and blocks the merge.

Going back to the initial example here is an example:

PR 1 on repo A:

Comments on PR1 repo A with reference to another repo

PR1 blocked because PR 8 on repo B is not merged/closed yet:

Dependency check fails

PR 1 is now mergeable since PR 8 on repo B is merged :

Dependency check success

Note that updating a comment on PR will not automatically trigger a new workflow run. The workflow will only be triggered when a new commit is done on the PR or you manually run it.

Custom GHE domains

For people using a Github entreprise server, the dependencies-actions can override github’s domain with custom one , using the following workflow:

on: [pull_request]

jobs:
check_dependencies:
runs-on: ubuntu-latest
name: Check Dependencies
steps:
- uses: gregsdennis/dependencies-action@1.3.0
with:
custom-domains: git.custom-domain.com
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Supported link styles

You can use one of the following styles in order to have the dependency set:

Final thoughts

Managing dependencies can be challenging, requiring careful attention to debugging and maintenance. In some use-cases, you don’t have a choice and that’s how the whole project/application is founded. With this solution, you can have implicit dependencies put in place to guarantee transparency but you always keep in mind that decoupling products/projects is always preferred!

--

--