ghostci/自动化

合规性 - 通过 GitHub Actions 为 PHP 提供的 CI/CD & QA 测试自动化。

v1.x-dev 2024-09-20 10:51 UTC

This package is auto-updated.

Last update: 2024-09-20 10:52:01 UTC


README

Automation Supported PHP Version Type Coverage Latest Version on Packagist Downloads

自动化 - CI/CD & QA 测试 通过 GitHub ActionsPHP 进行测试自动化。

注意

该项目尚未完成,仍在开发中。

待办事项

  • 检查 composer 脚本部分以查看是否存在命令,

    • 如果不存在,则报告错误/警告
    • 如果不存在,则跳过作业
  • 所有工具都应该有一个匹配的 composer 脚本名称,我现在已经硬编码了 composer 脚本,但应该可以配置(短横线命名法)

    • 命令将是 composer automation:composer-require-checker
      • composer automation:phpunit
        • 我喜欢 automation: 前缀,这样如果有一个 phpunit 脚本,
        • 它不会与 automation:phpunit 脚本冲突
  • 我将导入发布自动化到这个项目中

  • 我们将导入 composer.jsoncomposer.lock 验证到这个项目中

    • 我们将使用 composer.json 文件中的扩展字段来确定要安装哪些 PHP 扩展
    • 将扩展列表作为参数传递给 docker 镜像/workflow via shivammathur/setup-php@v2(看起来这部分已经完成,但我们需要测试。)
    • 我做了大部分工作... 但我需要测试它。
    • 我们已经有了从这两个 composer 文件中提取信息所需的一切

[!INFO]

耶!我们做到了!我们有一个工作原型! 🎉

-- 我们需要从 GitHub secrets 中导入 gpg 密钥 GPG_KEYGPG_FINGERPRINT --- 以使用 gpg 签名标记发布 --- 使用 gpg 签名签名二进制文件 --- 使用 gpg 签名签名 git 提交(如果所有测试都通过,则自动更新 composer.json)

  • 我们需要添加一个命令将这些命令添加到用户的 composer.json 文件中,对于他们 composer.json 文件中支持的每个工具。
  • 如果不存在,我们将将其添加到 scripts 部分。
  • 如果存在,继续。
{
    "scripts": {
        "automation:composer-require-checker": [
            "composer-require-checker check --config-file=composer-require-checker.json"
        ],
        "automation:phpunit": [
              "@phpunit --configuration=phpunit.xml --coverage-clover=coverage.xml"
        ]
    }
}

工作流程

# .github/workflows/automation.yml
name: Automation

on:
  pull_request:
  push:
    branches:
      - "main"
      - "[0-9]+.[0-9]+.x" # 1.2.x
      - "v[0-9]+" # v1
  schedule:
    - cron: "0 * * * *" # Runs hourly
  workflow_dispatch: # Manually Trigger workflow

jobs:
  automation:
    uses: ghostwriter/automation/.github/workflows/automation.yml@v1
    secrets:
      CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
      GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
      INFECTION_DASHBOARD_API_KEY: ${{ secrets.INFECTION_DASHBOARD_API_KEY }}

安装

您可以通过 composer 安装此包

composer require ghostwriter/automation --dev
Automation - Automatically configure and execute multiple CI/CD & QA Tests via GitHub Actions. 1.x-dev

Usage:
  command [options] [arguments]

Options:
  -h, --help            Display help for the given command. When no command is given display help for the list command
  -q, --quiet           Do not output any message
  -V, --version         Display this application version
      --ansi|--no-ansi  Force (or disable --no-ansi) ANSI output
  -n, --no-interaction  Do not ask any interactive question
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
  help        Display help for a command
  list        List commands
  matrix      Generates a job matrix for Github Actions.
  workflow    Creates a "automation.yml" workflow file.

用法

生成 automation.php 配置文件(如果不存在),并确定 GitHub Actions 的工作矩阵。

vendor/bin/automation matrix

为您的项目生成 .github/workflows/automation.yml 工作流程文件。

vendor/bin/automation workflow

Docker

# Install from the command line:

docker pull ghcr.io/ghostwriter/automation:v1

# Usage from the command line:

docker run -v $(PWD):/app -w=/app ghcr.io/ghostwriter/automation workflow
docker run -v $(PWD):/app -w=/app ghcr.io/ghostwriter/automation matrix

# Use as base image in Dockerfile:

FROM ghcr.io/ghostwriter/automation:v1

支持的工具?

<?php

declare(strict_types=1);

use Ghostwriter\Automation\Automation;
use Ghostwriter\Automation\Enum\ComposerStrategy;
use Ghostwriter\Automation\Enum\OperatingSystem;
use Ghostwriter\Automation\Enum\PhpVersion;
use Ghostwriter\Automation\Enum\Tool;
use Ghostwriter\Automation\Tool\Infection;
use Ghostwriter\Automation\Tool\PHPUnit;
use Ghostwriter\Automation\Tool\Psalm;

return Automation::new()
    ->composerStrategies(...ComposerStrategy::cases()) // ComposerStrategy::LATEST, ComposerStrategy::LOCKED, ComposerStrategy::LOWEST
    ->operatingSystems(...OperatingSystem::cases()) // OperatingSystem::UBUNTU, OperatingSystem::MACOS, OperatingSystem::WINDOWS
    ->phpVersions(...PhpVersion::cases()) // PhpVersion::PHP_54 - PhpVersion::PHP_84
    ->tools(...Tool::cases()) // Tool::Infection, Tool::PHPUnit, Tool::Psalm
    ->skip(OperatingSystem::WINDOWS) // Skip one or more: Composer Strategy, Operating System, PHP Version, or Tool 
;

测试

composer test

变更日志

有关最近更改的更多信息,请参阅 CHANGELOG.md

安全

如果您发现任何与安全相关的问题,请通过电子邮件 nathanael.esayeas@protonmail.com 而不是使用问题跟踪器。

赞助商

[成为 GitHub 赞助商]

鸣谢

许可

The BSD-3-Clause. 请参阅 许可文件 以获取更多信息。