How to reuse code with symfony 5 bundles? Part 7. Release cycle, installation and update

Let's talk about how to stop copy-paste between projects and transfer the code to a re-usable symfony 5 plug-in bundle. A series of articles summarizing my experience with bundles will lead in practice from creating a minimal bundle and refactoring a demo application to tests and the bundle release cycle.


In previous articles of the series, we took the reusable code into a full bundle, configured and tested it. In the final article, we’ll talk about the bundle’s life cycle: from installation to the release cycle.


In this article:


  • README.md
  • Installation: via composer, Flex recipes, console commands
  • Release cycle, release of new versions
  • Semantic Versioning
  • Committing Changes to CHANGELOG.md

Series Content

If you do not consistently complete the tutorial, then download the application from the repository and switch to the 6-testing branch .


Instructions for installing and starting the project in a file README.md. You will find the final version of the code for this article in the 7-support branch .


Disclaimer


«»,   ,   . ,  .



, composer:


composer require bravik/calendar-bundle

:


  1. vendors
  2. composer- Symfony Flex, config/bundles.php.

. , - CalendarBundle:


  • - . , config/packages/ - . ?
  • , Doctrine. , , . ?
  • — , . , , . . : composer Symfony , , npm , package.json . .

, ?


README.md


. , : README.md .


, , . .


, . , .


Best Practices for Reusable Bundles


Symfony Flex


Symfony , . , - , ENV-, .gitignore- .


composer Symfony Flex. - , . , , - . .


, . , , , .gitignore, ENV-, .

Symfony Flex? open-source Flex , .


, . : Symfony Contribution- Symfony. Contrib , , .


, . :


Symfony Flex Private Repositories — Fabien Potencier, 2017
Symfony 4 Using Private Recipes with Flex — Sebastian Sellmeier, 2018
Symfony Flex Private Recipes: , — , 2017


, :


  1. 1.5-2
  2. Flex Server , 249 EUR .
  3. Flex Server packagist, .
  4. Flex Server MIT BSD
  5. , . 1.5 .



Symfony Flex Symfony open-source Symfony-, .


CLI- Symfony


, README.md


: .


mybundle/src/Command/InstallCommand.php:


<?php

namespace bravik\CalendarBundle\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Filesystem\Filesystem;

class InstallCommand extends Command
{
    protected static $defaultName = 'bravik:calendar:install';

    /** @var Filesystem */
    private $filesystem;

    private $projectDir;

    public function __construct(Filesystem $filesystem, string $projectDir)
    {
        parent::__construct();

        $this->filesystem = $filesystem;
        $this->projectDir = $projectDir;
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $output->writeln('Installing bravik/CalendarBundle...');

        $this->initConfig($output);

        //    
        // ...

        return 0;
    }

    private function initConfig(OutputInterface $output): void
    {
        // Create default config if not exists
        $bundleConfigFilename = $this->projectDir
            . DIRECTORY_SEPARATOR . 'config'
            . DIRECTORY_SEPARATOR . 'packages'
            . DIRECTORY_SEPARATOR . 'calendar.yaml'
        ;
        if ($this->filesystem->exists($bundleConfigFilename)) {
            $output->writeln('Config file already exists');

            return;
        }

        //      
        $config = <<<YAML
calendar:
  enable_soft_delete: true
YAML;
        $this->filesystem->appendToFile($bundleConfigFilename, $config);

        $output->writeln('Config created: "config/packages/calendar.yaml"');

    }
}

, , , .


. , . .


, Symfony, shell-script.



, . , .


, CHANGELOG.md. , :



, , . , , .


:


<major>.<minor>.<patch>

— .


:


  • , , .
  • , , .
  • -, , .


Composer , , - .


CalendarBundle.


?


composer.json:


{
    "name": "bravik/calendar-bundle",
    "version": "0.1.0",
    ...
}

, Composer git-. , . :


git tag v0.1.0

composer.json — composer .


?


composer.json - :


"require": {
    "bravik/calendar-bundle": "^0.1.0",
    ...
},

^ composer , :


  • > 1.0.0 2.0.0.
  •   1.0.0   « », -.

> 0.1.0 < 0.2.0.


?


bundles/CalendarBundle/composer.json :


{
    "version": "0.1.1",
}

:


composer outdated


. — , — . , .


:


{
    "version": "0.2.1",
}


Composer . , . composer , require composer.json -.


?


composer update

.


, Composer


CHANGELOG.md


, , . . . CHANGELOG.md


?


, . , . , — , .


(  «  » 0.X.X) . , . CHANGELOG.md — , . !


CHANGElOG.md, .


:


# CHANGELOG
      

[BC] -   breaking changes

[BugFix] -   

## Unreleased
     
 * CAL-5 [BC]  
 * CAL-5    

## [0.2.0] (2020-04-06)
 * CAL-5 [BC]     
    -       `calendar_bundle.exporter`
 * CAL-6 [BC]     
    -   ,  ,        X  Y.        SQL  "XXX"
 * CAL-7   

## [0.1.1] (2020-03-30)
* CAL-4 [BugFix]      

## [0.1.0] (2020-02-15)
* CAL-1   
* CAL-2   
* CAL-3   
* [BugFix] Editor should initialize blocks only when they change

CHANGELOG.md symfony/framework-bundle. Symfony : . UPGRADE.md Symfony 4 Symfony 5.



Doctrine .


. , . — .


- : - .


SQL , , ?


.


, , .



      ,   .    —  .


7-support.



1.
2.
3. : , , JS
4.
5.
6. ,
7. ,


All Articles