Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

include github workflow #162

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/code-style.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: PHP-CS-Fixer

on:
push:
branches: [ master, main ]
pull_request:
branches: [ master, main ]

permissions:
contents: read

jobs:
code-style:
if: github.event.pull_request.draft == false

runs-on: ubuntu-latest
permissions:
contents: write # for Git to git apply

steps:
- uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
extensions: gd, intl, pdo_mysql
coverage: none # disable xdebug, pcov

# install dependencies from composer.json
- name: Install test dependencies
env:
COMPOSER: composer.json
run: composer install --prefer-dist --no-progress

# run php-cs-fixer
- name: Run PHP CS Fixer
run: composer cs-fix

# commit and push fixed files
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Apply php-cs-fixer changes
83 changes: 83 additions & 0 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: PHPUnit

on:
push:
branches: [ master, main ]
pull_request:
branches: [ master, main ]

permissions:
contents: read

jobs:
phpunit:

runs-on: ubuntu-latest
permissions:
contents: write # for Git to git apply

steps:
- uses: actions/checkout@v3

# setup PHP v8, install some extensions
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
extensions: gd, intl, pdo_mysql, xml
coverage: none # disable xdebug, pcov

# download the latest REDAXO release and unzip it
# credits https://blog.markvincze.com/download-artifacts-from-a-latest-github-release-in-sh-and-powershell/
- name: Download latest REDAXO release
run: |
LATEST_RELEASE=$(curl -L -s -H 'Accept: application/json' https://github.com/redaxo/redaxo/releases/latest)
REDAXO_VERSION=$(echo $LATEST_RELEASE | sed -e 's/.*"tag_name":"\([^"]*\)".*/\1/')
echo "Downloaded REDAXO $REDAXO_VERSION"
curl -Ls -o redaxo.zip https://github.com/redaxo/redaxo/releases/download/$REDAXO_VERSION/redaxo_$REDAXO_VERSION.zip
unzip -oq redaxo.zip -d redaxo_cms
rm redaxo.zip

# start mysql service, create a database called redaxo5, apply config patch
- name: Init database
run: |
sudo /etc/init.d/mysql start
mysql -uroot -h127.0.0.1 -proot -e 'create database redaxo5;'

# run REDAXO setup with the following parameters
# Language: de
# DB password: root
# Create DB: no
# Admin username: admin
# Admin password: adminpassword
# Error E-mail: test@redaxo.invalid
- name: Setup REDAXO
run: |
php redaxo_cms/redaxo/bin/console setup:run -n --lang=de_de --agree-license --db-host=127.0.0.1 --db-name=redaxo5 --db-password=root --db-createdb=no --db-setup=normal --admin-username=admin --admin-password=adminpassword --error-email=test@redaxo.invalid --ansi
php redaxo_cms/redaxo/bin/console config:set --type boolean debug.enabled true
php redaxo_cms/redaxo/bin/console config:set --type boolean debug.throw_always_exception true

# copy Addon files, ignore some directories...
# install the addon
# if the addon name does not match the repository name, ${{ github.event.repository.name }} must be replaced with the addon name
# if additional addons are needed, they can be installed via the console commands
# see: https://www.redaxo.org/doku/main/basis-addons#console
- name: Copy and install Addons
run: |
rsync -av --exclude='./vendor' --exclude='.github' --exclude='.git' --exclude='redaxo_cms' './' 'redaxo_cms/redaxo/src/addons/${{ github.event.repository.name }}'
redaxo_cms/redaxo/bin/console package:install '${{ github.event.repository.name }}'

# install dependencies from composer.json
- name: Install test dependencies
working-directory: redaxo_cms/redaxo/src/addons/${{ github.event.repository.name }}
env:
COMPOSER: composer.json
run: composer install --prefer-dist --no-progress

- name: Setup Problem Matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

# run unit tests, see composer.json
- name: Run phpunit
working-directory: redaxo_cms/redaxo/src/addons/${{ github.event.repository.name }}
run: composer unit-test
31 changes: 19 additions & 12 deletions .github/workflows/publish-to-redaxo.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
name: Publish release

on:
release:
types:
- published
release:
types:
- published

jobs:
redaxo_publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: FriendsOfREDAXO/installer-action@v1
with:
myredaxo-username: ${{ secrets.MYREDAXO_USERNAME }}
myredaxo-api-key: ${{ secrets.MYREDAXO_API_KEY }}
description: ${{ github.event.release.body }}
redaxo_publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: shivammathur/setup-php@v2
with:
php-version: "8.2"
- uses: ramsey/composer-install@v2
with:
composer-options: "--no-dev"
- uses: FriendsOfREDAXO/installer-action@v1
with:
myredaxo-username: ${{ secrets.MYREDAXO_USERNAME }}
myredaxo-api-key: ${{ secrets.MYREDAXO_API_KEY }}
description: ${{ github.event.release.body }}

84 changes: 84 additions & 0 deletions .github/workflows/rexstan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: rexstan

on:
push:
branches: [ master, main ]
pull_request:
branches: [ master, main ]
types: [opened, synchronize, reopened, ready_for_review]

permissions:
contents: read

jobs:
rexstan:
env:
ADDON_KEY: ${{ github.event.repository.name }}

runs-on: ubuntu-latest
permissions:
contents: write # for Git to git apply

steps:
- uses: actions/checkout@v3

# setup PHP v8, install some extensions
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
extensions: gd, intl, pdo_mysql, xml
coverage: none # disable xdebug, pcov

# download the latest REDAXO release and unzip it
# credits https://blog.markvincze.com/download-artifacts-from-a-latest-github-release-in-sh-and-powershell/
- name: Download latest REDAXO release
run: |
LATEST_RELEASE=$(curl -L -s -H 'Accept: application/json' https://github.com/redaxo/redaxo/releases/latest)
REDAXO_VERSION=$(echo $LATEST_RELEASE | sed -e 's/.*"tag_name":"\([^"]*\)".*/\1/')
echo "Downloaded REDAXO $REDAXO_VERSION"
curl -Ls -o redaxo.zip https://github.com/redaxo/redaxo/releases/download/$REDAXO_VERSION/redaxo_$REDAXO_VERSION.zip
unzip -oq redaxo.zip -d redaxo_cms
rm redaxo.zip

# start mysql service, create a database called redaxo5, apply config patch
- name: Init database
run: |
sudo /etc/init.d/mysql start
mysql -uroot -h127.0.0.1 -proot -e 'create database redaxo5;'

# run REDAXO setup with the following parameters
# Language: de
# DB password: root
# Create DB: no
# Admin username: admin
# Admin password: adminpassword
# Error E-mail: test@redaxo.invalid
- name: Setup REDAXO
run: |
php redaxo_cms/redaxo/bin/console setup:run -n --lang=de_de --agree-license --db-host=127.0.0.1 --db-name=redaxo5 --db-password=root --db-createdb=no --db-setup=normal --admin-username=admin --admin-password=adminpassword --error-email=test@redaxo.invalid --ansi
php redaxo_cms/redaxo/bin/console config:set --type boolean debug.enabled true
php redaxo_cms/redaxo/bin/console config:set --type boolean debug.throw_always_exception true

# copy Addon files, ignore some directories...
# install the addon
# if the addon name does not match the repository name, ${{ github.event.repository.name }} must be replaced with the addon name
# install latest rexstan
# if additional addons are needed, they can be installed via the console commands
# see: https://www.redaxo.org/doku/main/basis-addons#console
- name: Copy and install Addons
run: |
rsync -av --exclude='./vendor' --exclude='.github' --exclude='.git' --exclude='redaxo_cms' './' 'redaxo_cms/redaxo/src/addons/${{ github.event.repository.name }}'
redaxo_cms/redaxo/bin/console install:download 'rexstan' '1.*'
redaxo_cms/redaxo/bin/console package:install 'rexstan'
redaxo_cms/redaxo/bin/console package:install '${{ github.event.repository.name }}'

# execute rexstan.php to create the needed user-config.neon
- name: Execute .tools/rexstan.php
run: php -f redaxo/src/addons/${{ github.event.repository.name }}/.tools/rexstan.php
working-directory: redaxo_cms

# run rexstan
- id: rexstan
name: Run rexstan
run: redaxo_cms/redaxo/bin/console rexstan:analyze
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.DS_Store

/.idea/
.vscode

/vendor/

.php-cs-fixer.cache
.phpunit.result.cache
/.phpunit.cache/

12 changes: 12 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

$finder = (new PhpCsFixer\Finder())
->in(__DIR__)
->exclude('vendor')
;

return (new Redaxo\PhpCsFixerConfig\Config())
->setFinder($finder)
;
13 changes: 13 additions & 0 deletions .tools/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

unset($REX);
$REX['REDAXO'] = true;
$REX['HTDOCS_PATH'] = '../../../../';
$REX['BACKEND_FOLDER'] = 'redaxo';
$REX['LOAD_PAGE'] = false;

require __DIR__.'../../../../core/boot.php';
require __DIR__.'../../../../core/packages.php';

// use original error handlers of the tools
rex_error_handler::unregister();
40 changes: 40 additions & 0 deletions .tools/rexstan.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/**
* boot redaxo and load packages
* necessary to use \rexstan\RexStanUserConfig::save()
*/
unset($REX);
$REX['REDAXO'] = true;
$REX['HTDOCS_PATH'] = './';
$REX['BACKEND_FOLDER'] = 'redaxo';
$REX['LOAD_PAGE'] = false;

require './redaxo/src/core/boot.php';
require './redaxo/src/core/packages.php';

/**
* rexstan config
*/
$extensions = [
'../../../../redaxo/src/addons/rexstan/config/rex-superglobals.neon',
'../../../../redaxo/src/addons/rexstan/vendor/phpstan/phpstan/conf/bleedingEdge.neon',
'../../../../redaxo/src/addons/rexstan/vendor/phpstan/phpstan-strict-rules/rules.neon',
'../../../../redaxo/src/addons/rexstan/vendor/phpstan/phpstan-deprecation-rules/rules.neon',
'../../../../redaxo/src/addons/rexstan/config/phpstan-phpunit.neon',
'../../../../redaxo/src/addons/rexstan/config/phpstan-dba.neon',
// '../../../../redaxo/src/addons/rexstan/config/cognitive-complexity.neon',
// '../../../../redaxo/src/addons/rexstan/config/code-complexity.neon',
'../../../../redaxo/src/addons/rexstan/config/dead-code.neon'
];

// get addon key from environment variable
$addon = ['../../../../redaxo/src/addons/' . getenv('ADDON_KEY') . '/'];

/**
* save config
* @param int $level the level to use
* @param array $addon the addon to use
* @param array $extensions the extensions to use
* @param int $phpVersion the php version to use
*/
\rexstan\RexStanUserConfig::save(5, $addon, $extensions, 80203);
11 changes: 6 additions & 5 deletions boot.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@

// register extensions
// alfred post post
rex_extension::register('REX_FORM_SAVED', function (rex_extension_point $params) {
rex_extension::register('REX_FORM_SAVED', static function (rex_extension_point $params) {
/** @var rex_form|null $form */
$form = ($params->hasParam('form')) ? $params->getParam('form') : null;
if ($form instanceof mblock_rex_form)
return MBlockRexFormProcessor::postPostSaveAction($params->getSubject(), $form, $_POST); // execute post post
else
return $params->getSubject();
if ($form instanceof mblock_rex_form) {
return MBlockRexFormProcessor::postPostSaveAction($params->getSubject(), $form, $_POST);
} // execute post post

return $params->getSubject();
});

// assets
Expand Down
13 changes: 13 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"require-dev": {
"redaxo/php-cs-fixer-config": "^2.0",
"friendsofphp/php-cs-fixer": "^3.14",
"phpunit/phpunit": "^9.5"
},
"scripts": {
"cs-dry": "php-cs-fixer fix -v --ansi --dry-run --config=.php-cs-fixer.dist.php",
"cs-fix": "php-cs-fixer fix -v --ansi --config=.php-cs-fixer.dist.php",
"unit-test": "phpunit --testdox"
}

}
Loading
Loading