Merge pull request #165 from zhamao-robot/refactor-workflow

重构 Workflow
This commit is contained in:
sunxyw 2022-09-11 19:32:56 +08:00 committed by GitHub
commit 836d4dc1ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 173 additions and 154 deletions

42
.github/workflows/coding-style.yml vendored Normal file
View File

@ -0,0 +1,42 @@
name: Code Style
on:
push:
pull_request:
workflow_dispatch:
jobs:
pre_job:
runs-on: ubuntu-latest
outputs:
should_skip: ${{ steps.skip_check.outputs.should_skip }}
steps:
- id: skip_check
uses: fkirc/skip-duplicate-actions@v4
with:
concurrent_skipping: same_content_newer
skip_after_successful_duplicate: true
paths: '["src/**", "tests/**"]'
do_not_skip: '["workflow_dispatch", "schedule"]'
cs-fix:
needs: pre_job
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
name: Code Style
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup PHP
uses: sunxyw/workflows/setup-environment@main
with:
php-version: 8.0
php-extensions: swoole, posix, json
operating-system: ubuntu-latest
use-cache: true
- name: Code Style
uses: sunxyw/workflows/coding-style@main

View File

@ -22,27 +22,12 @@ jobs:
ref: ${{ github.base_ref }}
- name: Setup PHP
uses: "shivammathur/setup-php@v2"
uses: sunxyw/workflows/setup-environment@main
with:
php-version: '8.1'
extensions: swoole, posix, json
- name: Setup problem matchers for PHP
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install Composer Dependencies
run: "composer install --prefer-dist --no-progress --optimize-autoloader"
php-version: 8.0
php-extensions: swoole, posix, json
operating-system: ubuntu-latest
use-cache: true
- name: Generate API Docs
id: generate-api-docs

View File

@ -1,103 +0,0 @@
name: Integration and Style Test
on:
push:
branches:
- master
- '*-develop'
paths:
- '**/**.php'
pull_request:
branches:
- master
- '*-develop'
types:
- opened
- synchronize
- reopened
- ready_for_review
- review_requested
paths:
- '**/**.php'
jobs:
integration:
name: Integration Test (PHP ${{ matrix.php-versions }}) (OS ${{ matrix.operating-system }})
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: [ "ubuntu-latest", "macos-latest", "windows-latest" ]
php-versions: [ "7.4", "8.0", "8.1" ]
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup PHP
uses: "shivammathur/setup-php@v2"
with:
php-version: ${{ matrix.php-versions }}
extensions: swoole, posix, json, mbstring, pdo, sqlite3, pdo_sqlite
env:
SWOOLE_CONFIGURE_OPTS: --enable-openssl
- name: Setup problem matchers for PHP
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
- name: Validate composer.json
run: "composer validate --strict"
- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install Composer Dependencies
run: "composer install --prefer-dist --no-progress --optimize-autoloader"
- name: Run Static Analysis
run: "composer analyse"
- name: Run PHPUnit
run: "composer test"
cs-check:
name: PHP CS Fixer Check
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup PHP 8.1
uses: "shivammathur/setup-php@v2"
with:
php-version: "8.1"
extensions: swoole, posix, json
- name: Setup problem matchers for PHP
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
- name: Validate composer.json
run: "composer validate --strict"
- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install Composer Dependencies
run: "composer install --prefer-dist --no-progress --optimize-autoloader"
- name: Run PHP CS Fixer Check
run: "composer cs-fix -- --dry-run --diff"

42
.github/workflows/static-analysis.yml vendored Normal file
View File

@ -0,0 +1,42 @@
name: Static Analysis
on:
push:
pull_request:
workflow_dispatch:
jobs:
pre_job:
runs-on: ubuntu-latest
outputs:
should_skip: ${{ steps.skip_check.outputs.should_skip }}
steps:
- id: skip_check
uses: fkirc/skip-duplicate-actions@v4
with:
concurrent_skipping: same_content_newer
skip_after_successful_duplicate: true
paths: '["src/**", "tests/**"]'
do_not_skip: '["workflow_dispatch", "schedule"]'
analyse:
needs: pre_job
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
name: Static Analysis
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup PHP
uses: sunxyw/workflows/setup-environment@main
with:
php-version: 7.4
php-extensions: swoole, posix, json
operating-system: ubuntu-latest
use-cache: true
- name: Static Analysis
uses: sunxyw/workflows/static-analysis@main

54
.github/workflows/test.yml vendored Normal file
View File

@ -0,0 +1,54 @@
name: Test
on:
push:
branches:
- main
- develop
- '*-dev*'
pull_request:
types:
- opened
- reopened
- review_requested
workflow_dispatch:
jobs:
pre_job:
runs-on: ubuntu-latest
outputs:
should_skip: ${{ steps.skip_check.outputs.should_skip }}
steps:
- id: skip_check
uses: fkirc/skip-duplicate-actions@v4
with:
concurrent_skipping: same_content_newer
skip_after_successful_duplicate: true
paths: '["src/**", "tests/**", "bin/phpunit-zm"]'
do_not_skip: '["workflow_dispatch", "schedule"]'
test:
needs: pre_job
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
strategy:
matrix:
operating-system: [ ubuntu-latest, windows-latest, macos-latest ]
php-version: [ 7.4, 8.0, 8.1 ]
name: PHP ${{ matrix.php-version }} Test (${{ matrix.operating-system }})
runs-on: ${{ matrix.operating-system }}
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup PHP
uses: sunxyw/workflows/setup-environment@main
with:
php-version: ${{ matrix.php-version }}
php-extensions: swoole, posix, json
operating-system: ${{ matrix.operating-system }}
use-cache: true
- name: Test
uses: sunxyw/workflows/test@main

View File

@ -108,9 +108,9 @@ class BotCommand extends AnnotationBase implements Level
}
/**
* @return $this
* @throws InvalidArgumentException
* @throws ZMKnownException
* @return $this
*/
public function withArgument(
string $name,

View File

@ -102,7 +102,7 @@ class ZMConfig
foreach ($this->config_paths as $config_path) {
$files = scandir($config_path);
foreach ($files as $file) {
[, $ext, $load_type,] = $this->getFileMeta($file);
[, $ext, $load_type] = $this->getFileMeta($file);
// 略过不支持的文件
if (!in_array($ext, self::ALLOWED_FILE_EXTENSIONS, true)) {
continue;

View File

@ -16,9 +16,9 @@ class BoundMethod
*
* @param Container $container
* @param callable|string $callback
* @return mixed
* @throws EntryResolutionException|ReflectionException
* @throws InvalidArgumentException
* @return mixed
*/
public static function call(ContainerInterface $container, $callback, array $parameters = [], string $default_method = null)
{

View File

@ -41,8 +41,8 @@ class Container implements ContainerInterface
* @template T
* @param class-string<T> $abstract 类或接口名
* @param array $parameters 参数
* @throws EntryResolutionException
* @return Closure|mixed|T 实例
* @throws EntryResolutionException
*/
public function make(string $abstract, array $parameters = [])
{

View File

@ -247,8 +247,8 @@ trait ContainerTrait
* @template T
* @param class-string<T> $abstract 类或接口名
* @param array $parameters 参数
* @throws EntryResolutionException
* @return Closure|mixed|T 实例
* @throws EntryResolutionException
*/
public function make(string $abstract, array $parameters = [])
{
@ -317,8 +317,8 @@ trait ContainerTrait
* 实例化具体的类实例
*
* @param Closure|string $concrete 类名或对应的闭包
* @throws EntryResolutionException
* @return mixed
* @throws EntryResolutionException
*/
public function build($concrete)
{
@ -394,10 +394,9 @@ trait ContainerTrait
*
* @param string $id identifier of the entry to look for
*
* @return mixed entry
* @throws NotFoundExceptionInterface no entry was found for **this** identifier
* @throws ContainerExceptionInterface error while retrieving the entry
*
* @return mixed entry
*/
public function get(string $id)
{
@ -640,8 +639,8 @@ trait ContainerTrait
/**
* 解析基本类型
*
* @throws EntryResolutionException 如参数不存在默认值,则抛出异常
* @return mixed 对应类型的默认值
* @throws EntryResolutionException 如参数不存在默认值,则抛出异常
*/
protected function resolvePrimitive(ReflectionParameter $parameter)
{
@ -655,8 +654,8 @@ trait ContainerTrait
/**
* 解析类
*
* @throws EntryResolutionException 如果无法解析类,则抛出异常
* @return mixed
* @throws EntryResolutionException 如果无法解析类,则抛出异常
*/
protected function resolveClass(ReflectionParameter $parameter)
{

View File

@ -45,8 +45,8 @@ class Pipeline
* 接下来要调用的内容
*
* @param callable $callback 然后调用一个什么东西
* @throws InvalidArgumentException
* @return null|mixed 返回调用结果或null
* @throws InvalidArgumentException
*/
public function then(callable $callback)
{

View File

@ -65,8 +65,8 @@ class ProcessStateManager
* 用于框架内部获取多进程运行状态的函数
*
* @param mixed $id_or_name
* @throws ZMKnownException
* @return false|int|mixed
* @throws ZMKnownException
* @internal
*/
public static function getProcessState(int $type, $id_or_name = null)

View File

@ -18,8 +18,8 @@ class DBQueryBuilder extends QueryBuilder
}
/**
* @throws DbException
* @return DBStatementWrapper|int
* @throws DbException
*/
public function execute()
{

View File

@ -45,8 +45,8 @@ class DBStatementWrapper
/**
* wrapper method
*@throws DBException
* @return array|false|mixed
*@throws DBException
*/
public function fetchNumeric()
{
@ -59,8 +59,8 @@ class DBStatementWrapper
/**
* wrapper method
*@throws DBException
* @return array|false|mixed
*@throws DBException
*/
public function fetchAssociative()
{
@ -73,8 +73,8 @@ class DBStatementWrapper
/**
* wrapper method
*@throws DBException
* @return false|mixed
*@throws DBException
*/
public function fetchOne()
{
@ -217,8 +217,8 @@ class DBStatementWrapper
/**
* wrapper method
* @throws DBException
* @return int
* @throws DBException
*/
public function rowCount()
{

View File

@ -69,8 +69,8 @@ class DBWrapper
/**
* wrapper method
* @throws DBException
* @return array|false
* @throws DBException
*/
public function fetchAssociative(string $query, array $params = [], array $types = [])
{
@ -83,8 +83,8 @@ class DBWrapper
/**
* wrapper method
* @throws DBException
* @return array|false
* @throws DBException
*/
public function fetchNumeric(string $query, array $params = [], array $types = [])
{
@ -96,8 +96,8 @@ class DBWrapper
}
/**
* @throws DBException
* @return false|mixed
* @throws DBException
*/
public function fetchOne(string $query, array $params = [], array $types = [])
{
@ -199,8 +199,8 @@ class DBWrapper
* @param array<int, mixed>|array<string, mixed> $params Query parameters
* @param array<int, null|int|string|Type>|array<string, null|int|string|Type> $types Parameter types
*
* @throws DBException
* @return array<int,array<int,mixed>>
* @throws DBException
*/
public function fetchAllNumeric(string $query, array $params = [], array $types = []): array
{
@ -217,8 +217,8 @@ class DBWrapper
* @param array<int, mixed>|array<string, mixed> $params Query parameters
* @param array<int, null|int|string|Type>|array<string, null|int|string|Type> $types Parameter types
*
* @throws DBException
* @return array<int,array<string,mixed>>
* @throws DBException
*/
public function fetchAllAssociative(string $query, array $params = [], array $types = []): array
{
@ -252,8 +252,8 @@ class DBWrapper
* @param array<int, mixed>|array<string, mixed> $params Query parameters
* @param array<int, int|string>|array<string, int|string> $types Parameter types
*
* @throws DBException
* @return array<mixed,array<string,mixed>>
* @throws DBException
*/
public function fetchAllAssociativeIndexed(string $query, array $params = [], array $types = []): array
{
@ -270,8 +270,8 @@ class DBWrapper
* @param array<int, mixed>|array<string, mixed> $params Query parameters
* @param array<int, null|int|string|Type>|array<string, null|int|string|Type> $types Parameter types
*
* @throws DBException
* @return array<int,mixed>
* @throws DBException
*/
public function fetchFirstColumn(string $query, array $params = [], array $types = []): array
{
@ -288,8 +288,8 @@ class DBWrapper
* @param array<int, mixed>|array<string, mixed> $params Query parameters
* @param array<int, null|int|string|Type>|array<string, null|int|string|Type> $types Parameter types
*
* @throws DBException
* @return Traversable<int,array<int,mixed>>
* @throws DBException
*/
public function iterateNumeric(string $query, array $params = [], array $types = []): Traversable
{
@ -306,8 +306,8 @@ class DBWrapper
* @param array<int, mixed>|array<string, mixed> $params Query parameters
* @param array<int, null|int|string|Type>|array<string, null|int|string|Type> $types Parameter types
*
* @throws DBException
* @return Traversable<int,array<string,mixed>>
* @throws DBException
*/
public function iterateAssociative(string $query, array $params = [], array $types = []): Traversable
{
@ -324,8 +324,8 @@ class DBWrapper
* @param array<int, mixed>|array<string, mixed> $params Query parameters
* @param array<int, int|string>|array<string, int|string> $types Parameter types
*
* @throws DBException
* @return Traversable<mixed,mixed>
* @throws DBException
*/
public function iterateKeyValue(string $query, array $params = [], array $types = []): Traversable
{
@ -342,8 +342,8 @@ class DBWrapper
* @param array<int, mixed>|array<string, mixed> $params Query parameters
* @param array<int, int|string>|array<string, int|string> $types Parameter types
*
* @throws DBException
* @return Traversable<mixed,array<string,mixed>>
* @throws DBException
*/
public function iterateAssociativeIndexed(string $query, array $params = [], array $types = []): Traversable
{
@ -360,8 +360,8 @@ class DBWrapper
* @param array<int, mixed>|array<string, mixed> $params Query parameters
* @param array<int, null|int|string|Type>|array<string, null|int|string|Type> $types Parameter types
*
* @throws DBException
* @return Traversable<int,mixed>
* @throws DBException
*/
public function iterateColumn(string $query, array $params = [], array $types = []): Traversable
{
@ -414,8 +414,8 @@ class DBWrapper
* @param array<int, mixed>|array<string, mixed> $params Statement parameters
* @param array<int, null|int|string|Type>|array<string, null|int|string|Type> $types Parameter types
*
* @throws DBException
* @return int|string the number of affected rows
* @throws DBException
*/
public function executeStatement(string $sql, array $params = [], array $types = [])
{
@ -446,8 +446,8 @@ class DBWrapper
/**
* overwrite method to $this->connection->transactional()
* @throws DBException
* @return mixed
* @throws DBException
*/
public function transactional(Closure $func)
{