bizkit/versioning-bundle

Symfony扩展包,提供多种版本控制策略来管理应用版本。

安装量: 46 477

依赖者: 0

建议者: 0

安全: 0

星标: 7

关注者: 2

分支: 2

公开问题: 0

类型:symfony-bundle

v1.1.0 2024-01-01 00:43 UTC

This package is auto-updated.

Last update: 2024-09-24 12:46:39 UTC


README

Build Status Latest Stable Version License Code Coverage

Symfony扩展包,提供多种版本控制策略来管理应用版本。

Showcase

功能

  • 将应用程序的版本和发布日期存储到符合YAML或XML格式的Symfony容器配置文件中
  • 自动导入包含参数的文件到Symfony的容器中
  • 支持多种版本控制策略和自定义策略
  • 包含一个控制台命令,使用配置的版本控制策略来增加版本号
  • 命令会自动提交版本文件,如果配置了VCS处理器,则可选地创建标签
  • 支持Git版本控制系统和自定义VCS处理器

要求

安装

  1. 使用Composer要求扩展包

    composer require bizkit/versioning-bundle
  2. config/packages/bizkit_versioning.yaml下创建扩展包配置文件。以下是一个参考配置文件

    bizkit_versioning:
    
        # The prefix added to the version parameters.
        parameter_prefix:     application # Example: my_app
    
        # The versioning strategy used.
        strategy:             incrementing
    
        # The name of the file containing the version information.
        filename:             version
    
        # The path to the file containing the version information.
        filepath:             '%kernel.project_dir%/config'
    
        # The format used for the version file.
        format:               yaml # One of "yaml"; "xml"
    
        # Configuration for the VCS integration,
        # set to false to disable the integration.
        vcs:
    
            # The handler used for the VCS integration,
            # set to null to disable the integration.
            handler:              git
    
            # The message to use for the VCS commit.
            commit_message:       null
    
            # The message to use for the VCS tag.
            tag_message:          null
    
            # The name used for the VCS commit information,
            # set to null to use the default VCS configuration.
            name:                 null
    
            # The email used for the VCS commit information,
            # set to null to use the default VCS configuration.
            email:                null
    
            # The path to the VCS executable,
            # set to null for autodiscovery.
            path_to_executable:   null
  3. config/bundles.php中启用扩展包,将其添加到数组中

    Bizkit\VersioningBundle\BizkitVersioningBundle::class => ['all' => true],

使用方法

该扩展包创建一个符合以下三个参数的符合规范的Symfony依赖注入容器配置文件:

  • application.version - 应用程序版本(格式取决于配置的版本控制策略)
  • application.version_hash - 版本的MD5摘要
  • application.release_date - 上次增加版本时的RFC 3339格式日期

注意:参数名称可能会根据parameter_prefix配置选项而变化。

它将自动将参数添加到Symfony的容器中,通过将文件注册为导入

有关参数的更多信息,请参阅Symfony的官方文档。以下示例展示了如何与Sentry的 Monolog处理器一起使用:

monolog:
    sentry:
        type: sentry
        dsn: '%sentry_dsn%'
        release: '%application.version%'

增加版本号

使用配置的策略增加版本号,请运行以下命令

bin/console bizkit:versioning:increment

如果您已配置VCS处理器,则该命令将自动提交版本文件,并可选地使用新版本创建标签。

版本控制策略

该扩展包包含以下版本策略

  1. incrementing - 定义版本为递增的数字
  2. semver - 使用语义化版本控制系统

自定义策略

要实现自定义策略,您需要创建一个实现StrategyInterface接口的服务。

namespace App;

use Bizkit\VersioningBundle\Strategy\StrategyInterface;

class MyStrategy implements StrategyInterface
{
    public function __invoke(StyleInterface $io, ?Version $version = null): Version
    {
        if (null === $version) {
            // return initial version
        }

        // return incremented version
    }
}

在配置中使用服务的FQCN

bizkit_versioning:
    strategy: App\MyStrategy

如果您未使用Symfony的自动配置功能或希望在配置中使用别名,请将服务标记为bizkit_versioning.strategy

App\MyStrategy:
    tags:
        - { name: 'bizkit_versioning.strategy', alias: 'my_strategy' }

bizkit_versioning:
    strategy: my_strategy

VCS处理器

此包包含对Git版本控制系统的处理程序。如果您想禁用VCS功能,请将vcs配置选项设置为false

bizkit_versioning:
    vcs: false

自定义VCS处理程序

要实现自定义VCS处理程序,您只需要创建一个实现了VCSHandlerInterface接口的服务。

namespace App;

use Bizkit\VersioningBundle\VCS\VCSHandlerInterface;

class MyVCSHandler implements VCSHandlerInterface
{
    public function commit(StyleInterface $io, Version $version): void
    {
        // commit the file
    }

    public function tag(StyleInterface $io, Version $version): void
    {
        // create a tag
    }
}

在配置中使用服务的FQCN

bizkit_versioning:
    vcs:
        handler: App\MyVCSHandler

如果您没有使用Symfony的自动配置功能或者想在配置中使用别名,请使用bizkit_versioning.vcs_handler标签标记服务。

App\MyVCSHandler:
    tags:
        - { name: 'bizkit_versioning.vcs_handler', alias: 'my_vcs' }

bizkit_versioning:
    vcs:
        handler: my_vcs

版本控制

此项目遵循语义化版本控制2.0.0

问题报告

使用问题跟踪器报告您可能遇到的问题。

许可证

有关许可证权利和限制(MIT),请参阅LICENSE文件。