garden-io / garden

Automation for Kubernetes development and testing. Spin up production-like environments for development, testing, and CI on demand. Use the same configuration and workflows at every step of the process. Speed up your builds and test runs via shared result caching
https://garden.io
Mozilla Public License 2.0
3.39k stars 274 forks source link

[FEATURE]: Remote sources: Fallback to default branch if specified branch does not exist #3920

Open stefreak opened 1 year ago

stefreak commented 1 year ago

Feature Request

A user with multiple repositories for different services requested a feature to fallback to a default branch in remote sources.

This might be useful in cases you need to change multiple repositories at once sometimes.

Background / Motivation

Take this configuration as an example:

kind: Project
name: remote-sources
sources:
  - name: web-services
    repositoryUrl: https://github.com/garden-io/garden-example-remote-sources-web-services.git#${git.branch}
  - name: db-services
    repositoryUrl: https://github.com/garden-io/garden-example-remote-sources-db-services.git#${git.branch}

Let's say I am in main, then this works fine. This configuration would enable a user switching to the branch feat/big-new-feature, run garden deploy and garden test with all the changes in all the different repositories / services.

But let's say the user switches to fix/small-bug – this branch might only require a change in one repository. With the configuration above, the user would need to create this branch in all the other repositories as well.

What should the user be able to do?

A user friendly solution to this problem would be to allow specifying a fallback-branch, in case the specified branch does not exist.

For example:

kind: Project
name: remote-sources
sources:
  - name: web-services
    repositoryUrl: https://github.com/garden-io/garden-example-remote-sources-web-services.git#${git.branch}
    fallbackBranch: main
  - name: db-services
    repositoryUrl: https://github.com/garden-io/garden-example-remote-sources-db-services.git#${git.branch}
    fallbackBranch: main

Why do they want to do this? What problem does it solve?

This makes it easier in some cases if developers need to make changes to multiple microservices at once, and every service lives in their own repository. This would enable the developer to test all the changes together in one development or preview environment.

There are workarounds, for example users could use garden link, for example like so:

#!/bin/bash
rm -rf garden-example-remote-sources-web-services

# Clone the pizza branch, and if it does not exist clone the default branch.
git clone git@github.com:garden-io/garden-example-remote-sources-web-services.git --branch pizza || git clone git@github.com:garden-io/garden-example-remote-sources-web-services.git

garden link source web-services garden-example-remote-sources-web-services

But maintaining these custom scripts can be a hassle, especially when dealing with a large number of remote sources.

Suggested Implementation(s)

If cloning the repository fails due to missing branch or object, use the default branch instead.

How important is this feature for you/your team?

🌹 It’s a nice to have, but nice things are nice 🙂

stefreak commented 1 year ago

See also #3998 for another, more generic, way to make this possible