symfony / flex

Composer plugin for Symfony
MIT License
4.15k stars 181 forks source link

Allow organize private recipes in subdirectories #1025

Closed anthony-launay closed 4 months ago

anthony-launay commented 4 months ago

Hello,

I would like to organize my private recipes in subdirectories. However, I have the impression that today it's only possible to organize them in flat files (https://symfony.com/doc/current/setup/flex_private_recipes.html#create-your-private-recipes)

Example :

index.json group1.first-bundle.1.0.json group1.first-bundle.2.0.json group1.second-bundle.1.0.json group2.thrid-bundle.1.0.json

However, I would like this organization like (symfony/recipes) :

index.json group1 (directory) -- first-bundle (directory) ---- 1.0 (directory) ------ manifest.json (file) ---- 2.0 (directory) ------ manifest.json (file) -- second-bundle (directory) ---- 1.0 (directory) ------ manifest.json (file) group2 -- thrid-bundle (directory) ---- 1.0 (directory) ------ manifest.json (file)

I use GitLab, the API requires encoding file_path : https://docs.gitlab.com/ee/api/repository_files.html#get-file-from-repository

That's why I specified this configuration for recipe_template : https://gitlab.myhost.fr/api/v4/projects/XXX/repository/files/{package}%2F{version}%2Fmanifest.json/raw?ref=main

Everything looks perfect, except that the URL generated by Flex is https://gitlab.myhost.fr/api/v4/projects/XXX/repository/files/group1/thrid-bundle%2F{version}%2Fmanifest.json/raw?ref=main

group1/thrid-bundle is not encoded, the API responds with a 404.

Do you think, in Download.php, it's possible to offer new parameter mamed package_encoded ?

 $urls[] = strtr($links['recipe_template'], [
    '{package_dotted}' => str_replace('/', '.', $package->getName()),
    '{package}' => $package->getName(),
    '{package_encoded}' => urlencode($package->getName()),
    '{version}' => $v,
 ]);

Thus, we could specify this configuration for recipe_template : https://gitlab.myhost.fr/api/v4/projects/XXX/repository/files/{package_encoded}%2F{version}%2Fmanifest.json/raw?ref=main

This would allow flexibility and an interesting evolution for the structuring of private recipes.

If this development is interesting, I would propose a pull request. If there is already a way to do this, I'm interested !

jakubtobiasz commented 4 months ago

Hi @anthony-launay, if you want to create a repository similarly to symfony/recipes you might take a look at the repository I've created for Sylius (https://github.com/Sylius/SyliusRecipes) :).

Basically, you need two branches (I called them main and flex/main). On the main branch we keep the files like you mentioned (structured with directories), then on push we have configured GitHub Workflows (check the .github directory) which "translates" the structured form from the main branch intro the "flat" one on the flex/main branch.

nicolas-grekas commented 4 months ago

@jakubtobiasz is right. The GHA scripts we use in symfony/flex are public and reusable, feel free to have a look.

anthony-launay commented 4 months ago

Hello @jakubtobiasz @nicolas-grekas,

The scripts in Recipes Checker are based on Github and do not allow the use of GitLab.

What to do in this case?

fabpot commented 4 months ago

Indeed, we don't support Gitlab and we don't need to. So, I suppose you can adapt these scripts.

jakubtobiasz commented 4 months ago

@anthony-launay