-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make CI Configuration Branch-Agnostic and Reusable #31
Comments
Here are detailed solutions to resolve the issue, each addressing a specific aspect of branch flexibility and reusability: Solution 1: Specify CI-Triggering Branch as a Variable Approach: Define the branch as a variable in the env or inputs section of the CI configuration. The branch name can then be used dynamically throughout the workflow. Example:
Pros:
Cons:
Solution 2: Support Multiple Branch Names Approach: Allow an array of branch names, and use the first one that matches the current repository setup. This can be implemented using GitHub Actions’ conditional logic. Example:
Pros:
Cons:
Solution 3: Detect the Default Branch Dynamically Approach: Use GitHub’s REST API to retrieve the repository’s default branch at runtime. This can be done via a step early in the workflow that sets the default branch as an environment variable. Example:
Pros:
Cons:
Solution 4: Combine Approaches Approach: Blend the previous solutions for maximum flexibility: Example:
Pros:
Cons:
Implementation Recommendations
For immediate needs, implement Solution 1 or Solution 2 to allow basic customization with minimal changes. These solutions provide flexibility and scalability, making the CI reusable across various repositories while reducing the need for manual configuration updates. |
Summary
The current CI configuration (see actions and example CI hardcodes the
master
branch in several places, such as:and
This approach makes the CI non-reusable across projects where the default branch may be named differently (e.g., main, dev, etc.). To address this, we propose a solution that allows branch specification to be more flexible, enabling reusability and adaptability for different repository configurations.
Problem Statement
Hardcoding the branch name as master introduces the following limitations:
1. Incompatibility with projects using different default branch names, such as main or dev.
2. Difficulty in maintaining and reusing CI across multiple repositories without customization.
3. Inability to adapt to changes in the default branch of a repository over time.
Proposed Solutions
To address these limitations, we propose implementing a flexible system for specifying branches. This system can be a combination of the following solutions:
Allow the branch to be defined in the env section or as an input variable, making it easy to change across different repositories. Example:
Enable specifying an array of branch names, where the CI uses the first one found. This approach would allow fallbacks. Example:
Detect the repository’s default branch dynamically during the CI run and use that as the trigger. This would make the CI even more robust. For example, a reserved variable like $default_branch could represent the repository’s default branch, and the CI would resolve it at runtime.
Allow users to define branches in a hierarchical manner, e.g., supporting a mix of explicit branch names and the dynamic $default_branch. Example:
Implementation Considerations
Benefits
Next Steps
Let us know your thoughts and preferences on the proposed solutions!
This issue template lays out the problem clearly, proposes multiple solutions, and highlights the benefits.
The text was updated successfully, but these errors were encountered: