mmz-srf/sbs

将构建过程拆分为多个步骤,只有在需要时才执行这些步骤

维护者

详细信息

github.com/mmz-srf/sbs

源代码

1.4.4 2021-02-23 10:08 UTC

This package is not auto-updated.

Last update: 2024-09-18 03:29:35 UTC


README

SBS 允许在 CI 环境中仅构建单仓仓库的部分。

例如,您有一个 React 应用程序和一个 PHP 后端位于同一个仓库中。当仓库进行构建时,将执行 PHP 单元测试,并且 React 应用程序也将被构建和测试。这总是在您向 master 分支推送内容时发生。

当只有 PHP 文件被修改时,构建 React 应用程序是不必要的。

SBS 允许定义何时需要执行特定的构建步骤,并且只执行需要的部分。

构建步骤在根目录下的 YAML 文件中定义。

sbs.yml

composer:
    title: Composer dependencies
    cmd: "composer install"
    files:
        - composer.lock
    output: vendor 

这定义了一个名为 composer 的构建步骤。它只在 composer.lock 文件被修改时执行。在这种情况下,将执行 composer install 命令。

何时构建构建步骤

SBS 根据在 sbs.yml 中的指定来决定是否需要构建构建步骤。SBS 可以根据以下内容进行决策:

  • 文件或目录的哈希(使用 files
  • Git 仓库中分支的最后一个提交的哈希(使用 commit

SBS 在构建之后将构建步骤的哈希存储在名为 sbs.built.json 的文件中,该文件位于构建步骤指定的 output 目录中。(例如,vendor/sbs.built.json)。这用于检查在下次运行中是否需要构建该构建步骤。

SBS 做以下操作

  • 读取所有构建步骤
  • 根据构建步骤配置创建构建步骤的哈希
  • 读取上次构建步骤的哈希(如果有)
  • 如果新哈希与上次构建的哈希不同,则运行命令
  • 为下次运行存储新哈希

配置参考

buildstep:
    title: the title which gets displayed on building, defaults to build step name
    cmd: the command to build this build step, required
    timeout: seconds the command has to execute before it timeouts, defaults to 3600
    working_dir: if the working directory of the command is not the project root, specify it here
    clear: if the output directly should be cleared before building, defaults to false
    output: where SBS writes the information which last state of the build step is built, required
    depends_on: name of other build step which hash gets included
    commit: tells SBS to look if there is a new commit hash on a certain repository
        repo: the link to the repository
        branch: the branch name
    files: list of files or directory                    

安装和使用

composer require mmz-srf/sbs --dev

创建初始 sbs.yml

vendor/bin/sbs init

构建构建步骤

vendor/bin/sbs

仅构建特定的一个步骤

vendor/bin/sbs build buildStepName

强制构建所有构建步骤

vendor/bin/sbs --force