Skip to content

Commit

Permalink
Merge branch 'wip/image-resizing' of github.com:octobercms/october in…
Browse files Browse the repository at this point in the history
…to wip/image-resizing
  • Loading branch information
LukeTowers committed Aug 14, 2020
2 parents 288918a + d52893d commit 75e6633
Show file tree
Hide file tree
Showing 13 changed files with 250 additions and 86 deletions.
14 changes: 6 additions & 8 deletions .github/workflows/code-quality-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@ on:
jobs:
codeQuality:
runs-on: ubuntu-latest
name: PHPCS
name: PHP
steps:
- name: Checkout changes
uses: actions/checkout@v1
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Install PHP and PHP Code Sniffer
uses: shivammathur/setup-php@v1
uses: shivammathur/setup-php@v2
with:
php-version: '7.3'
tools: phpcs
- name: Setup problem matcher for PHPCS
run: echo "::add-matcher::${{ github.workspace }}/.github/workflows/matchers/phpcs-matcher.json"
- name: Run code quality checks
run: |
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*" && git fetch
phpcs --colors -nq --report="checkstyle" --extensions="php" $(git diff --name-only --diff-filter=ACMR origin/${{ github.base_ref }} HEAD)
run: ./.github/workflows/utilities/phpcs-pr ${{ github.base_ref }}
12 changes: 6 additions & 6 deletions .github/workflows/code-quality-push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ on:
jobs:
codeQuality:
runs-on: ubuntu-latest
name: PHPCS
name: PHP
steps:
- name: Checkout changes
uses: actions/checkout@v1
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Install PHP and PHP Code Sniffer
uses: shivammathur/setup-php@v1
uses: shivammathur/setup-php@v2
with:
php-version: '7.3'
tools: phpcs
- name: Setup problem matcher for PHPCS
run: echo "::add-matcher::${{ github.workspace }}/.github/workflows/matchers/phpcs-matcher.json"
- name: Run code quality checks
run: phpcs --colors -nq --report="checkstyle" --extensions="php" $(git show --name-only --pretty="" --diff-filter=ACMR ${{ github.sha }})
run: ./.github/workflows/utilities/phpcs-push ${{ github.sha }}
23 changes: 0 additions & 23 deletions .github/workflows/matchers/phpcs-matcher.json

This file was deleted.

77 changes: 57 additions & 20 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,51 +13,88 @@ jobs:
name: JavaScript
steps:
- name: Checkout changes
uses: actions/checkout@v1
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Install Node
uses: actions/setup-node@v1
with:
node-version: 8
node-version: 12

- name: Install Node dependencies
run: npm install

- name: Run tests
run: npm run test
phpUnitTests:
runs-on: ubuntu-latest
strategy:
max-parallel: 6
matrix:
phpVersions: ['7.2', '7.3', '7.4']
operatingSystem: [ubuntu-latest, windows-latest]
phpVersion: ['7.2', '7.3', '7.4']
fail-fast: false
name: Unit Tests / PHP ${{ matrix.phpVersions }}
runs-on: ${{ matrix.operatingSystem }}
name: ${{ matrix.operatingSystem }} / PHP ${{ matrix.phpVersion }}
env:
extensions: curl, fileinfo, gd, mbstring, openssl, pdo, pdo_sqlite, sqlite3, xml
key: october-cms-cache-v1
steps:
- name: Checkout changes
uses: actions/checkout@v1
uses: actions/checkout@v2

- name: Setup extension cache
id: extcache
uses: shivammathur/cache-extensions@v1
with:
php-version: ${{ matrix.phpVersion }}
extensions: ${{ env.extensions }}
key: ${{ env.key }}

- name: Cache extensions
uses: actions/cache@v2
with:
path: ${{ steps.extcache.outputs.dir }}
key: ${{ steps.extcache.outputs.key }}
restore-keys: ${{ steps.extcache.outputs.key }}

- name: Install PHP
uses: shivammathur/setup-php@v1
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.phpVersions }}
extensions: mbstring, intl, gd, xml, sqlite
- name: Setup problem matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: Set Composer cache
id: composer-cache
php-version: ${{ matrix.phpVersion }}
tools: composer
extensions: ${{ env.extensions }}

- name: Setup dependency cache
id: composercache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache Composer dependencies
uses: actions/cache@v1

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
path: ${{ steps.composercache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install Composer dependencies
run: composer install --no-interaction --no-progress --no-suggest --no-scripts

- name: Reset October modules
run: |
git reset --hard HEAD
composer dumpautoload
- name: Run post-update Composer scripts
run: php artisan package:discover

- name: Reset October modules
run: |
git reset --hard HEAD
composer dumpautoload
- name: Run Linting and Tests
run: |
./vendor/bin/parallel-lint --exclude vendor --exclude storage --exclude tests/fixtures/plugins/testvendor/goto/Plugin.php .
./vendor/bin/phpunit --prepend ./vendor/october/rain/src/Support/helpers.php
- name: Setup problem matchers for PHPUnit
if: matrix.phpVersion == '7.4'
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Run tests
run: ./vendor/bin/phpunit --prepend ./vendor/october/rain/src/Support/helpers.php
77 changes: 77 additions & 0 deletions .github/workflows/utilities/phpcs-pr
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/usr/bin/env php
<?php
if (empty($argv[1])) {
echo 'You must provide a base branch to check this PR against.';
echo "\n";
exit(1);
}

// Get a changelist of files from Git for this PR.
$fileList = shell_exec('git diff --name-only --diff-filter=ACMR origin/' . $argv[1] . ' HEAD');
$files = array_filter(explode("\n", $fileList));

foreach ($files as &$file) {
if (strpos($file, ' ') !== false) {
$file = str_replace(' ', '\\ ', $file);
}
}

// Run all changed files through the PHPCS code sniffer and generate a CSV report
$csv = shell_exec('phpcs --colors -nq --report="csv" --extensions="php" ' . implode(' ', $files));
$lines = array_map(function ($row) {
return array_map(function ($column) {
return trim($column, '"');
}, explode(',', $row));
}, array_filter(explode("\n", $csv)));

// Remove header row
array_shift($lines);

if (!count($lines)) {
echo "\e[0;32mFound no issues with code quality.\e[0m";
echo "\n";
exit(0);
} else {
// Group errors by file
$files = [];

foreach ($lines as $line) {
$filename = str_replace(dirname(dirname(dirname(__DIR__))), '', $line[0]);

if (empty($files[$filename])) {
$files[$filename] = [];
}

$files[$filename][] = [
'warning' => ($line[3] === 'warning'),
'message' => $line[4],
'line' => $line[1],
];
}

// Render report
echo "\e[0;31mFound "
. ((count($lines) === 1)
? '1 issue'
: count($lines) . ' issues')
. " with code quality.\e[0m";
echo "\n";

foreach ($files as $file => $errors) {
echo "\n";
echo "\e[1;37m" . str_replace('"', '', $file) . "\e[0m";
echo "\n\n";

foreach ($errors as $error) {
echo "\e[2m" . str_pad(' L' . $error['line'], 7) . " | \e[0m";
if ($error['warning'] === false) {
echo "\e[0;31mERR:\e[0m ";
} else {
echo "\e[1;33mWARN:\e[0m ";
}
echo $error['message'];
echo "\n";
}
}
exit(1);
}
77 changes: 77 additions & 0 deletions .github/workflows/utilities/phpcs-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/usr/bin/env php
<?php
if (empty($argv[1])) {
echo 'You must provide a commit SHA to check.';
echo "\n";
exit(1);
}

// Get a changelist of files from Git for this push.
$fileList = shell_exec('git show --name-only --pretty="" --diff-filter=ACMR ' . $argv[1]);
$files = array_filter(explode("\n", $fileList));

foreach ($files as &$file) {
if (strpos($file, ' ') !== false) {
$file = str_replace(' ', '\\ ', $file);
}
}

// Run all changed files through the PHPCS code sniffer and generate a CSV report
$csv = shell_exec('phpcs --colors -nq --report="csv" --extensions="php" ' . implode(' ', $files));
$lines = array_map(function ($row) {
return array_map(function ($column) {
return trim($column, '"');
}, explode(',', $row));
}, array_filter(explode("\n", $csv)));

// Remove header row
array_shift($lines);

if (!count($lines)) {
echo "\e[0;32mFound no issues with code quality.\e[0m";
echo "\n";
exit(0);
} else {
// Group errors by file
$files = [];

foreach ($lines as $line) {
$filename = str_replace(dirname(dirname(dirname(__DIR__))), '', $line[0]);

if (empty($files[$filename])) {
$files[$filename] = [];
}

$files[$filename][] = [
'warning' => ($line[3] === 'warning'),
'message' => $line[4],
'line' => $line[1],
];
}

// Render report
echo "\e[0;31mFound "
. ((count($lines) === 1)
? '1 issue'
: count($lines) . ' issues')
. " with code quality.\e[0m";
echo "\n";

foreach ($files as $file => $errors) {
echo "\n";
echo "\e[1;37m" . str_replace('"', '', $file) . "\e[0m";
echo "\n\n";

foreach ($errors as $error) {
echo "\e[2m" . str_pad(' L' . $error['line'], 7) . " | \e[0m";
if ($error['warning'] === false) {
echo "\e[0;31mERR:\e[0m ";
} else {
echo "\e[1;33mWARN:\e[0m ";
}
echo $error['message'];
echo "\n";
}
}
exit(1);
}
4 changes: 2 additions & 2 deletions modules/backend/helpers/Backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,14 @@ protected function parseAsset($file, $skinAsset)
$contents = file_get_contents($assetFile);

// Find all assets that are compiled in this file
preg_match_all('/^=require\s+([A-z0-9-_+\.\/]+)$/m', $contents, $matches, PREG_SET_ORDER);
preg_match_all('/^=require\s+([A-z0-9-_+\.\/]+)[\n|\r\n|$]/m', $contents, $matches, PREG_SET_ORDER);

// Determine correct asset path
$directory = str_replace(basename($file), '', $file);

if (count($matches)) {
$results = array_map(function ($match) use ($directory) {
return $directory . $match[1];
return str_replace('/', DIRECTORY_SEPARATOR, $directory . $match[1]);
}, $matches);

foreach ($results as $i => $result) {
Expand Down
6 changes: 3 additions & 3 deletions modules/cms/classes/CodeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ protected function rebuild($path)
$body = preg_replace('/^\s*function/m', 'public function', $body);

$namespaces = [];
$pattern = '/(use\s+[a-z0-9_\\\\]+(\s+as\s+[a-z0-9_]+)?;\n?)/mi';
$pattern = '/(use\s+[a-z0-9_\\\\]+(\s+as\s+[a-z0-9_]+)?;(\r\n|\n)?)/mi';
preg_match_all($pattern, $body, $namespaces);
$body = preg_replace($pattern, '', $body);

Expand All @@ -142,13 +142,13 @@ protected function rebuild($path)

foreach ($namespaces[0] as $namespace) {
if (str_contains($namespace, '\\')) {
$fileContents .= $namespace;
$fileContents .= trim($namespace).PHP_EOL;
}
}

$fileContents .= 'class '.$className.$parentClass.PHP_EOL;
$fileContents .= '{'.PHP_EOL;
$fileContents .= $body.PHP_EOL;
$fileContents .= trim($body).PHP_EOL;
$fileContents .= '}'.PHP_EOL;

$this->validate($fileContents);
Expand Down
Loading

0 comments on commit 75e6633

Please sign in to comment.