Skip to content

Commit

Permalink
Merge pull request #43 from getkirby/develop
Browse files Browse the repository at this point in the history
v2
  • Loading branch information
bastianallgeier authored Dec 7, 2022
2 parents 4c8cdd8 + 7de4454 commit bfcc236
Show file tree
Hide file tree
Showing 47 changed files with 2,681 additions and 1,935 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ insert_final_newline = true
[*.yml]
indent_style = space

[*.md]
[*.md,*.txt]
trim_trailing_whitespace = false
29 changes: 29 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Git
.gitattributes export-ignore
.github/ export-ignore
.gitignore export-ignore

# Source files

# Development files
.editorconfig export-ignore
.eslintrc.js export-ignore
.prettierrc.json export-ignore
composer.lock export-ignore
package-lock.json export-ignore
package.json export-ignore

# Screenshots
screenshot.png export-ignore

# Tests
.codecov.yml export-ignore
.composer-require-checker.json export-ignore
.composer-require-checker.json export-ignore
.php-cs-fixer.dist.php export-ignore
phpmd.xml.dist export-ignore
phpunit.xml.dist export-ignore
psalm.xml.dist export-ignore
etc/ export-ignore
stubs/ export-ignore
tests/ export-ignore
205 changes: 205 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
name: CI
on: [push, pull_request]

jobs:
tests:
name: PHP ${{ matrix.php }}

runs-on: ubuntu-latest
timeout-minutes: 5
strategy:
matrix:
php: ["8.0", "8.1"]
env:
extensions: mbstring, pcov
ini: pcov.directory=., "pcov.exclude=\"~(vendor|tests)~\""

steps:
- name: Checkout
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # pin@v3

- name: Setup PHP cache environment
id: ext-cache
uses: shivammathur/cache-extensions@fc01a9cdc93341e96c2078d848f2e96240d83c17 # pin@v1
with:
php-version: ${{ matrix.php }}
extensions: ${{ env.extensions }}
key: php-v1

- name: Cache PHP extensions
uses: actions/cache@c3f1317a9e7b1ef106c153ac8c0f00fed3ddbc0d # pin@v3
with:
path: ${{ steps.ext-cache.outputs.dir }}
key: ${{ steps.ext-cache.outputs.key }}
restore-keys: ${{ steps.ext-cache.outputs.key }}

- name: Setup PHP environment
uses: shivammathur/setup-php@3eda58347216592f618bb1dff277810b6698e4ca # pin@v2
with:
php-version: ${{ matrix.php }}
extensions: ${{ env.extensions }}
ini-values: ${{ env.ini }}
coverage: pcov
tools: phpunit:9.5.13, psalm:4.11.2

- name: Setup problem matchers
run: |
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: Get Composer cache directory
id: composerCache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@c3f1317a9e7b1ef106c153ac8c0f00fed3ddbc0d # pin@v3
with:
path: ${{ steps.composerCache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --prefer-dist

- name: Cache analysis data
id: finishPrepare
uses: actions/cache@c3f1317a9e7b1ef106c153ac8c0f00fed3ddbc0d # pin@v3
with:
path: ~/.cache/psalm
key: backend-analysis-${{ matrix.php }}-v2

- name: Run tests
if: always() && steps.finishPrepare.outcome == 'success'
run: phpunit --coverage-clover ${{ github.workspace }}/clover.xml

- name: Statically analyze using Psalm
if: always() && steps.finishPrepare.outcome == 'success'
run: psalm --output-format=github --php-version=${{ matrix.php }}

# - name: Upload coverage results to Codecov
# uses: codecov/codecov-action@66b3de25f6f91f65eb92c514d31d6b6f13d5ab18 # pin@v3
# with:
# file: ${{ github.workspace }}/clover.xml
# flags: backend
# env_vars: PHP
# env:
# PHP: ${{ matrix.php }}

analysis:
name: Analysis

runs-on: ubuntu-latest
timeout-minutes: 5
env:
php: "8.0"
extensions: mbstring

steps:
- name: Checkout
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # pin@v3

- name: Setup PHP cache environment
id: ext-cache
uses: shivammathur/cache-extensions@fc01a9cdc93341e96c2078d848f2e96240d83c17 # pin@v1
with:
php-version: ${{ env.php }}
extensions: ${{ env.extensions }}
key: php-v1

- name: Cache PHP extensions
uses: actions/cache@c3f1317a9e7b1ef106c153ac8c0f00fed3ddbc0d # pin@v3
with:
path: ${{ steps.ext-cache.outputs.dir }}
key: ${{ steps.ext-cache.outputs.key }}
restore-keys: ${{ steps.ext-cache.outputs.key }}

- name: Setup PHP environment
id: finishPrepare
uses: shivammathur/setup-php@3eda58347216592f618bb1dff277810b6698e4ca # pin@v2
with:
php-version: ${{ env.php }}
extensions: ${{ env.extensions }}
coverage: none
tools: |
composer:2.3.7, composer-normalize:2.28.0,
composer-unused:0.7.12, phpcpd:6.0.3, phpmd:2.12.0
- name: Validate composer.json/composer.lock
if: always() && steps.finishPrepare.outcome == 'success'
run: composer validate --strict --no-check-version --no-check-all

- name: Ensure that composer.json is normalized
if: always() && steps.finishPrepare.outcome == 'success'
run: composer-normalize --dry-run

- name: Get Composer cache directory
id: composerCache1
if: always() && steps.finishPrepare.outcome == 'success'
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
id: composerCache2
if: always() && steps.composerCache1.outcome == 'success'
uses: actions/cache@c3f1317a9e7b1ef106c153ac8c0f00fed3ddbc0d # pin@v3
with:
path: ${{ steps.composerCache1.outputs.dir }}
key: ${{ runner.os }}-composer-locked-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-locked-

- name: Install dependencies
id: composerInstall
if: always() && steps.composerCache2.outcome == 'success'
run: composer install --prefer-dist

- name: Check for unused Composer dependencies
if: always() && steps.composerInstall.outcome == 'success'
run: composer-unused --no-progress

- name: Check for duplicated code
if: always() && steps.composerInstall.outcome == 'success'
run: phpcpd --fuzzy --exclude tests --exclude vendor .

- name: Statically analyze using PHPMD
if: always() && steps.composerInstall.outcome == 'success'
run: phpmd . github phpmd.xml.dist --exclude 'tests/*,vendor/*'

coding-style:
name: Coding Style

runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- name: Checkout
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # pin@v3

- name: Setup PHP environment
uses: shivammathur/setup-php@3eda58347216592f618bb1dff277810b6698e4ca # pin@v2
with:
coverage: none
tools: php-cs-fixer:3.8.0

- name: Cache analysis data
id: finishPrepare
uses: actions/cache@c3f1317a9e7b1ef106c153ac8c0f00fed3ddbc0d # pin@v3
with:
path: ~/.php-cs-fixer
key: coding-style

- name: Check for PHP coding style violations
if: always() && steps.finishPrepare.outcome == 'success'
env:
PHP_CS_FIXER_IGNORE_ENV: 1
# Use the --dry-run flag in push builds to get a failed CI status
run: >
php-cs-fixer fix --diff
${{ github.event_name != 'pull_request' && '--dry-run' || '' }}
- name: Create code suggestions from the coding style changes (on PR only)
if: >
always() && steps.finishPrepare.outcome == 'success' &&
github.event_name == 'pull_request'
uses: reviewdog/action-suggester@ab82daa6ea9b84fe43db7747bb10fa087f34e1ab # pin@v1
with:
tool_name: PHP-CS-Fixer
fail_on_error: "true"
30 changes: 7 additions & 23 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,29 +1,13 @@
# OS files
.DS_Store

# npm modules
# Vendor files
/node_modules
/vendor

# files of Composer dependencies that are not needed for the plugin
/vendor/**/.*
/vendor/**/*.json
/vendor/**/*.txt
/vendor/**/*.md
/vendor/**/*.yml
/vendor/**/*.yaml
/vendor/**/*.xml
/vendor/**/*.dist
/vendor/**/readme.php
/vendor/**/LICENSE
/vendor/**/COPYING
/vendor/**/VERSION
/vendor/**/docs/*
/vendor/**/example/*
/vendor/**/examples/*
/vendor/**/test/*
/vendor/**/tests/*
/vendor/**/php4/*
/vendor/getkirby/composer-installer
/.php_cs.cache
/.phpunit.result.cache
# Cache and temporary files
/.cache
/.php-cs-fixer.cache
/.phpunit.result.cache
/tests/coverage
/tests/*/tmp
9 changes: 4 additions & 5 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<?php

$finder = PhpCsFixer\Finder::create()
->exclude('dependencies')
->exclude('panel/node_modules')
->exclude('node_modules')
->in(__DIR__);

$config = new PhpCsFixer\Config();
return $config
->setRules([
'@PSR12' => true,
'@PSR1' => true,
'@PSR2' => true,
'align_multiline_comment' => ['comment_type' => 'phpdocs_like'],
'array_indentation' => true,
'array_syntax' => ['syntax' => 'short'],
'cast_spaces' => ['space' => 'none'],
// 'class_keyword_remove' => true, // replaces static::class with 'static' (won't work)
'class_keyword_remove' => false,
'combine_consecutive_issets' => true,
'combine_consecutive_unsets' => true,
'combine_nested_dirname' => true,
Expand Down Expand Up @@ -44,7 +44,6 @@
'no_unused_imports' => true,
'no_useless_return' => true,
'ordered_imports' => ['sort_algorithm' => 'alpha'],
// 'phpdoc_add_missing_param_annotation' => ['only_untyped' => false], // adds params in the wrong order
'phpdoc_align' => ['align' => 'left'],
'phpdoc_indent' => true,
'phpdoc_scalar' => true,
Expand Down
56 changes: 45 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"name": "getkirby/kql",
"description": "Kirby Query Language",
"license": "MIT",
"version": "1.2.0",
"type": "kirby-plugin",
"version": "2.0.0",
"keywords": [
"kirby",
"cms",
Expand All @@ -11,29 +12,62 @@
"query",
"headless"
],
"homepage": "https://getkirby.com",
"type": "kirby-plugin",
"authors": [
{
"name": "Bastian Allgeier",
"email": "[email protected]"
},
{
"name": "Nico Hoffmann",
"email": "[email protected]"
}
],
"homepage": "https://getkirby.com",
"support": {
"email": "[email protected]",
"issues": "https://github.com/getkirby/kql/issues",
"forum": "https://forum.getkirby.com",
"source": "https://github.com/getkirby/kql"
},
"require": {
"php": ">=8.0.0 <8.3.0",
"getkirby/cms": ">=3.8.2",
"getkirby/composer-installer": "^1.2.1"
},
"config": {
"optimize-autoloader": true,
"allow-plugins": {
"getkirby/composer-installer": false
}
},
"autoload": {
"psr-4": {
"Kirby\\": "src/"
"Kirby\\": [
"tests/"
]
}
},
"config": {
"allow-plugins": {
"getkirby/composer-installer": true
},
"optimize-autoloader": true
},
"extra": {
"installer-name": "kql",
"kirby-cms-path": false
},
"scripts": {
"fix": "php-cs-fixer fix"
"analyze": [
"@analyze:composer",
"@analyze:psalm",
"@analyze:phpcpd",
"@analyze:phpmd"
],
"analyze:composer": "composer validate --strict --no-check-version --no-check-all",
"analyze:phpcpd": "phpcpd --fuzzy --exclude tests --exclude vendor .",
"analyze:phpmd": "phpmd . ansi phpmd.xml.dist --exclude 'dependencies/*,tests/*,vendor/*'",
"analyze:psalm": "psalm",
"ci": [
"@fix",
"@analyze",
"@test"
],
"fix": "php-cs-fixer fix",
"test": "phpunit --stderr --coverage-html=tests/coverage"
}
}
Loading

0 comments on commit bfcc236

Please sign in to comment.