Skip to content

Commit

Permalink
Merge pull request #264 from CouscousPHP/updates
Browse files Browse the repository at this point in the history
  • Loading branch information
mnapoli committed Sep 2, 2022
2 parents 43f9b11 + 432c36f commit e6566fe
Show file tree
Hide file tree
Showing 31 changed files with 188 additions and 124 deletions.
87 changes: 87 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: CI

on:
push:
branches: ['master']
pull_request:
branches: ['*']
schedule:
- cron: '0 0 * * *'

jobs:

tests:
name: Tests - PHP ${{ matrix.php }} ${{ matrix.dependency-version }}
runs-on: ubuntu-latest
timeout-minutes: 15
strategy:
matrix:
php: [ '7.4', '8.0', '8.1' ]
dependency-version: [ '' ]
include:
- php: '7.4'
dependency-version: '--prefer-lowest'
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
tools: composer:v2
coverage: none
- name: Cache Composer dependencies
uses: actions/cache@v2
with:
path: ~/.composer/cache
key: php-${{ matrix.php }}-composer-locked-${{ hashFiles('composer.lock') }}
restore-keys: php-${{ matrix.php }}-composer-locked-
- name: Install PHP dependencies
run: composer update ${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-progress --no-suggest
- name: PHPUnit
run: vendor/bin/phpunit

cs:
name: Coding standards
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
tools: composer:v2, cs2pr
coverage: none
- name: Cache Composer dependencies
uses: actions/cache@v2
with:
path: ~/.composer/cache
key: php-composer-locked-${{ hashFiles('composer.lock') }}
restore-keys: php-composer-locked-
- name: Install PHP dependencies
run: composer install --no-interaction --no-progress --no-suggest
- name: PHP CodeSniffer
run: vendor/bin/phpcs -q --no-colors --report=checkstyle | cs2pr

psalm:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
tools: composer:v2, cs2pr
coverage: none
- name: Cache Composer dependencies
uses: actions/cache@v2
with:
path: ~/.composer/cache
key: php-composer-locked-${{ hashFiles('composer.lock') }}
restore-keys: php-composer-locked-
- name: Install PHP dependencies
run: composer install --no-interaction --no-progress --no-suggest
- name: psalm
run: vendor/bin/psalm --output-format=checkstyle | cs2pr
27 changes: 27 additions & 0 deletions .github/workflows/website.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Website

on:
# This job runs when a new release is published
release:
types: [ published ]

jobs:

deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@v2
with:
php-version: 8.0
coverage: none
- uses: ramsey/composer-install@v1
- run: |
./travis-prepare-release.sh
bin/couscous travis-auto-deploy
- name: Upload phar to release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: bin/couscous.phar
tag: ${{ github.ref }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
/Vagrantfile
/.vagrant
/node_modules
.phpunit.result.cache
43 changes: 0 additions & 43 deletions .travis.yml

This file was deleted.

31 changes: 16 additions & 15 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "couscous/couscous",
"description": "Documentation website generator",
"license": "MIT",
"autoload": {
"psr-4": {
Expand All @@ -15,29 +16,29 @@
"bin/couscous"
],
"require": {
"php": ">=7.1",
"symfony/console": "~3.0|~4.0|~5.0",
"symfony/filesystem": "~3.0|~4.0|~5.0",
"symfony/finder": "~3.0|~4.0|~5.0",
"symfony/process": "~3.0|~4.0|~5.0",
"symfony/yaml": "~3.0|~4.0|~5.0",
"twig/twig": "~1.10",
"erusev/parsedown": "~1.7.4",
"erusev/parsedown-extra": "~0.8",
"phine/phar": "~1.0",
"mnapoli/front-yaml": "~1.5",
"php-di/php-di": "^5.2.1",
"psr/log": "~1.0",
"php": ">=7.4",
"symfony/console": "~4.0|~5.0|~6.0",
"symfony/filesystem": "~4.0|~5.0|~6.0",
"symfony/finder": "~4.0|~5.0|~6.0",
"symfony/process": "~4.0|~5.0|~6.0",
"symfony/yaml": "~4.0|~5.0|~6.0",
"twig/twig": "^1.44",
"erusev/parsedown": "^1.7.4",
"erusev/parsedown-extra": "^0.8.1",
"phine/phar": "^1.0",
"mnapoli/front-yaml": "^1.5",
"php-di/php-di": "^6.0",
"psr/log": "^1.0",
"padraic/phar-updater": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "~7.5",
"phpunit/phpunit": "^8.5",
"squizlabs/php_codesniffer": "^3.3",
"vimeo/psalm": "^3.16"
},
"config": {
"platform": {
"php": "7.1.3"
"php": "7.4.0"
}
}
}
11 changes: 2 additions & 9 deletions src/Application/Cli/DeployCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Filesystem\Filesystem;

/**
* Generate and deploy the website.
Expand All @@ -31,21 +30,15 @@ class DeployCommand extends Command
*/
private $deployer;

/**
* @var Filesystem
*/
private $filesystem;

/**
* @var Git
*/
private $git;

public function __construct(Generator $generator, Deployer $deployer, Filesystem $filesystem, Git $git)
public function __construct(Generator $generator, Deployer $deployer, Git $git)
{
$this->generator = $generator;
$this->deployer = $deployer;
$this->filesystem = $filesystem;
$this->git = $git;

parent::__construct();
Expand Down Expand Up @@ -117,7 +110,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
// If no branch was provided, use the configured one or the default
if (!$targetBranch) {
/** @var string */
$targetBranch = isset($project->metadata['branch']) ? $project->metadata['branch'] : 'gh-pages';
$targetBranch = $project->metadata['branch'] ?? 'gh-pages';
}

$output->writeln('');
Expand Down
2 changes: 1 addition & 1 deletion src/Application/Cli/InitTemplateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$directory = getcwd().'/'.$dirName.'/';
/** @var string */
$templateName = $input->getArgument('template_name');
$templateName = $templateName.$fileExtension;
$templateName .= $fileExtension;

$fileLocation = $directory.$templateName;
$fileExists = file_exists($fileLocation);
Expand Down
3 changes: 2 additions & 1 deletion src/Application/Cli/PreviewCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
if (!$this->isFound($livereload)) {
$output->writeln(
'<error>Impossible to launch Livereload, '
.'did you forgot to install it with "pip install livereload" or "npm install -g livereload"?</error>'
.'did you forgot to install it with "pip install livereload" '
.'or "npm install -g livereload"?</error>'
);

return 1;
Expand Down
2 changes: 1 addition & 1 deletion src/Application/Cli/TravisAutoDeployCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 0;
}

$isPullRequest = (int) getenv('TRAVIS_PULL_REQUEST') > 0 ? true : false;
$isPullRequest = (int) getenv('TRAVIS_PULL_REQUEST') > 0;

if ($isPullRequest) {
$output->writeln('<comment>[NOT DEPLOYED] Not deploying Couscous for pull requests</comment>');
Expand Down
6 changes: 3 additions & 3 deletions src/Application/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@
DI\get(Module\Scripts\Step\ExecuteAfterScripts::class),
],

Couscous\Generator::class => DI\object()
Couscous\Generator::class => DI\autowire()
->constructorParameter('steps', DI\get('steps')),

'application' => DI\object(Symfony\Component\Console\Application::class)
'application' => DI\create(Symfony\Component\Console\Application::class)
->constructor('Couscous', 'dev-master')
->method('add', DI\get(Application\Cli\GenerateCommand::class))
->method('add', DI\get(Application\Cli\PreviewCommand::class))
Expand All @@ -59,7 +59,7 @@
->method('add', DI\get(Application\Cli\TravisAutoDeployCommand::class))
->method('add', DI\get(Application\Cli\InitTemplateCommand::class)),

Symfony\Component\Console\Logger\ConsoleLogger::class => DI\object()
Symfony\Component\Console\Logger\ConsoleLogger::class => DI\autowire()
->constructorParameter('verbosityLevelMap', [
// Custom verbosity map
LogLevel::EMERGENCY => OutputInterface::VERBOSITY_NORMAL,
Expand Down
1 change: 1 addition & 0 deletions src/CommandRunner/Git.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public function push(string $directory, string $branch, string $remote = 'origin
* @param string $remote Remote name
*
* @return string The git URL
* @throws CommandException
*/
public function getRemoteUrl(string $remote = 'origin'): string
{
Expand Down
2 changes: 1 addition & 1 deletion src/Model/Metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Metadata implements \ArrayAccess
/**
* @var array
*/
private $values = [];
private $values;

public function __construct(array $values = [])
{
Expand Down
4 changes: 2 additions & 2 deletions src/Model/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function findFilesByType(string $class): array
public function sourceFiles(): Finder
{
/** @var list<string> */
$includedDirectories = $this->metadata['include'] ? $this->metadata['include'] : [];
$includedDirectories = $this->metadata['include'] ?: [];

// To be sure that included directories are under the source one
if (!empty($includedDirectories)) {
Expand All @@ -121,7 +121,7 @@ public function sourceFiles(): Finder
}

/** @var list<string> */
$exclude = $this->metadata['exclude'] ? $this->metadata['exclude'] : [];
$exclude = $this->metadata['exclude'] ?: [];
$excludedDirectories = new ExcludeList($exclude);

if (is_file($this->sourceDirectory.'/.gitignore')) {
Expand Down
2 changes: 1 addition & 1 deletion src/Model/WatchList/WatchList.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function getChangedFiles(): array
}, $this->watches);

/** @var list<string> */
$files = call_user_func_array('array_merge', $files);
$files = array_merge(...$files);

return array_unique($files);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Module/Config/Step/LoadConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
class LoadConfig implements Step
{
const FILENAME = 'couscous.yml';
private const FILENAME = 'couscous.yml';

/**
* @var Filesystem
Expand Down
3 changes: 2 additions & 1 deletion src/Module/Config/Step/OverrideBaseUrlForPreview.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
namespace Couscous\Module\Config\Step;

use Couscous\Model\Project;
use Couscous\Step;

/**
* Override the baseUrl if we are in preview.
*
* @author Matthieu Napoli <[email protected]>
*/
class OverrideBaseUrlForPreview implements \Couscous\Step
class OverrideBaseUrlForPreview implements Step
{
public function __invoke(Project $project): void
{
Expand Down
3 changes: 2 additions & 1 deletion src/Module/Config/Step/OverrideConfigFromCLI.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
namespace Couscous\Module\Config\Step;

use Couscous\Model\Project;
use Couscous\Step;
use Psr\Log\LoggerInterface;

/**
* Override config variables when specified using --config option.
*
* @author D.J. Marcolesco <[email protected]>
*/
class OverrideConfigFromCLI implements \Couscous\Step
class OverrideConfigFromCLI implements Step
{
/**
* @var LoggerInterface
Expand Down
Loading

0 comments on commit e6566fe

Please sign in to comment.