I’ve developed a Symfony bundle, and I am trying to create a recipe. Before submitting it to recipes-contrib
, I want to test it, so I followed the instructions for private recipes — not because I want a private recipe (that is, neither the bundle nor the recipe is "private" in the sense of a private GitHub project).
I have read, re-read, then read again the documentation for creating a recipe, and I feel like I’m missing a very important step. The documentation for a private repository only talks about the package.version.json file, e.g.
{
"manifests": {
"acme/private-bundle": {
"manifest": {
"bundles": {
"Acme\PrivateBundle\AcmePrivateBundle": [
"all"
]
},
"copy-from-recipe": {
"config/": "%CONFIG_DIR%"
}
},
"files": {
"config/packages/acme_private.yaml": {
"contents": [
"acme_private:",
" encode: true",
""
],
"executable": false
}
},
"ref": "7405f3af1312d1f9121afed4dddef636c6c7ff00"
}
}
}
This file appears to be the output of some command that reads the file in the format as expected for a contrib
recipe: a directory structure that has a config
directory for routes and packages, maybe a src
directory, etc.
Obviously, no one is typing in by hand line by line a YAML file (or PHP!) as a list of strings in the content
key.
It appears that the master
branch of recipes and recipes-contrib
contains the directory structure, and flex/main
branch contains the "compiled" JSON recipe file.
But in the private recipe instructions, there are no instructions as to how to get from the DX-friendly files to the JSON recipe.
TL;DR; How do I create a package.version.json
recipe from the package/version/ directory that contains manifest.json
, config
, etc.?
2
Answers
I had the same problem few hours ago and I finally get it.
Clues were given by the blog post https://symfony.com/blog/symfony-flex-is-going-serverless were we can see that a script and a tool exist.
I duplicated the Github Actions and adapted those files in one of my repositories: https://github.com/web-token/recipes
main
branch contains the compiled files, including theindex.json
: this is what you want to have to get it working.tree
branch is the one where developer friendly files live.The
tree
branch contains the Github Actions workflows that update themain
branch.Feel free to copy and adapt the folder https://github.com/web-token/recipes/tree/tree/.github with your parameters.
Note that the server URL to declare in the composer file will look like
https://api.github.com/repos/web-token/recipes/contents/index.json?ref=main
Yeah, I agree that the instructions are a big opaque there.
The missing step is performed by by
symfony-tools/recipe-checker
(link).The repo is (sadly) not available as a package on Packagist, so to install and run it locally you’d it you either modify your configuration to add a custom repository pointing there, or you clone/download without using composer.
E.g.
Now you have the script ready to use.
Assuming you downloaded it in your home directory, you could run:
The different arguments are (as gotten from
run generate:flex-endpoint --help
):So if you have a recipe repository for a package like
yivi/stub-bundle
, version 1.0, with the repository hosted at https://github.com/yivi/stub-bundle-recipeYou could simply
cd
into the package directory and run:This would generate locally the "compiled" recipe (or recipes, if you have multiple on that directory) and you’d end up with this in that directory:
index.json
yivi.stub-bundle.1.0.json
archived/
(dir)To "test" this locally, it would simply a matter to commit and push this repo, and on a project that will want to use the recipes hosted here update the
composer.json
extra.symfony
field to include:The nice answer by Spomky links to a GitHub action that could do this for you automatically on the receiving repo, cleanly separating in different branches the "source" recipes and the "compiled" recipes, but I think this example will more easily show how to perform the process step by step by yourself.