4

I'm trying to figure out the workflow Symfony uses to create separate packages for each Symfony Component (and Bridge or Bundle) while still including them all in the main Symfony Framework.

The framework as well as each component have their own composer.json files:

Symfony
├── Component
|   ├── Component1
|   |   ├── ...
|   |   └── composer.json
|   ├── Component2
|   |   ├── ...
|   |   └── composer.json
|   └── ...
└── ...

I'd like to create a project in a similar fashion. How does Symfony use Git subtrees to track the framework and the components in this way so they can be installed individually or all together with composer? Does the framework maintain a separate repository for each package? Is this process automated? It seems like a lot of work to manually update all the component packages.

Cy Rossignol
  • 16,216
  • 4
  • 57
  • 83

2 Answers2

8

Each component and bundle in Symfony has it's own repository on Github. They are only used for packagist and therefor they are read only. All work take place in the main repository.

After each commit, all changes will be pushed to the read only repositories. The script is not public as i know, but you can read a bit on how fabien implement it here

I use also a subtree split to distribute my packages to the sub repositories within a jenkin task.

Here is a small guide to add a subtree split to your main repository and how to distribute it back to its repositories. Example is transfered to your directory structure example and the owner of the repositories is Acme.

Create component

    #execute in subtree repository
    $ git init
    $ git commit -a -m "init"
    $ git remote add origin git@github.com:Acme/Component1.git
    $ git push -u origin master

Add component to main repository

    #execute in main repository
    $ git remote add -f Component1 git@github.com:Acme/Component1.git
    $ git subtree add --prefix Symfony/Component/Component1 --squash Component1/master
    $ git subtree push --prefix=Symfony/Component/Component1 Component1 master

Push after changes in main repository

    #execute in main repository on a webhook in e.g. jenkins
    $ git remote add -f Component1 git@github.com:Acme/Component1.git #only if you haven't add it before
    $ git subtree push --prefix=Symfony/Component/Component1 Component1 master

Hope that may help to to set up your infrastructure.

gseidel
  • 321
  • 2
  • 9
  • I am able to split the repo using git sub tree and also created composer.json inside the main and sub repo. Now what next ? How composer will sync the code from sub repo to main repo ? Should I push changes of specific component into main repo or to newly created sub repo ? Please explain! @gseidel – appsntech Jan 26 '17 at 07:41
  • Hello @appsntech. My example just show how to push changes from the main repo to the sub repo. This is unidirectional and the most common way. You should do ALL your changes on the main repo and NEVER to the sub repo. After you do some changes in the main repo, than you push that changes to the sub repo (See Example "Push after changes in main repository"). You only need composer, if you want to use your component in an other project. So if you have a main repo A that contains component B. And your Project C needs component B. You use composer for it. – gseidel Jan 28 '17 at 23:48
  • Thanks. I got our point. But In my case the main repository already contains many folders inside it. So I just need to split it every folders to a sub repository and continue modification in main repository. I believe your above example applicable in the case of creating components from beginning. Can you show me some example steps to be followed or help me with this please? Thanks in advance. – appsntech Jan 30 '17 at 10:08
  • Ok. But I have another problem. My main repo could be: ``` - example - unit1 - unit2 - docs - unit1 - unit2 - src - unit1 - unit2 - tests - unit1 - unit2 ``` Question is: How can I create submodules as follow (unit1 subrepo): ``` - example - docs - src - tests ``` – Marek G. Dec 03 '21 at 20:17
  • I have been still searching and [found this answer](https://stackoverflow.com/questions/25574407/git-subtree-split-two-directories#answer-58253979). I haven't tested it yet but I think that it is. – Marek G. Dec 03 '21 at 21:06
1

I don't know the exact procedure Symfony follows.

But in practice there are a lot of possible different paths that can be followed.

The simplest one seems to be the use of a bash script like the one provided here.

Or maybe you want to set up a more complex flow, like the one set up for the Zend Framework.

Another solution is to use PHP itself and Composer, like described here.

It really depends on your necessities.

But the links I've provided should be a good starting point to better understand how to set up a good workflow.

Aerendir
  • 6,152
  • 9
  • 55
  • 108