Skip to content

Commit

Permalink
chore(actions): add release please workflow and lint (#8)
Browse files Browse the repository at this point in the history
* style(php): apply cs fixer and phpstan

* chore(ci): add automated tests and release

* Update composer.json

Co-authored-by: Lucas Mirloup <[email protected]>

---------

Co-authored-by: Lucas Mirloup <[email protected]>
  • Loading branch information
thislg and lucasmirloup authored May 23, 2024
1 parent 4cebf33 commit e49ba42
Show file tree
Hide file tree
Showing 15 changed files with 142 additions and 46 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Release

on:
push:
branches:
- "master"

env:
PHP_EXTENSIONS: "zip"
PHP_VERSION: "8.3"

jobs:
release:
runs-on: ubuntu-latest

permissions:
contents: write
pull-requests: write

if: github.ref == 'refs/heads/master'

steps:
- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: "${{ env.PHP_VERSION }}"
extensions: "${{ env.PHP_EXTENSIONS }}"
tools: humbug/box

- name: Validate composer.json and composer.lock
run: composer validate --strict

- uses: google-github-actions/release-please-action@v4
id: create_release
with:
target-branch: master
42 changes: 42 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Tests

on:
push:
branches: ["master"]
pull_request:
branches: ["*"]

permissions:
contents: read

jobs:
tests:

strategy:
matrix:
php_version: ["7.4", "8.0", "8.1", "8.2", "8.3"]

runs-on: ubuntu-latest
container:
image: "lephare/php:${{ matrix.php_version }}"
env:
XDEBUG_MODE: coverage

steps:
- uses: actions/checkout@v4

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Install dependencies (PHP ${{ matrix.php_version }})
run: |
composer config --global cache-dir .composer
composer install --prefer-dist --no-interaction --no-progress
- name: Coding Style (PHP ${{ matrix.php_version }})
run: |
composer run-script lint:ci
composer run-script analyse
- name: Unit Tests (PHP ${{ matrix.php_version }})
run: composer run-script test:ci
3 changes: 3 additions & 0 deletions .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
".": "2.1.0"
}
21 changes: 3 additions & 18 deletions Handler/RotatingFileHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,8 @@
namespace LePhare\Import\Handler;

use Monolog\Handler\RotatingFileHandler as BaseRotatingFileHandler;
use Monolog\Logger;

if (Logger::API === 1) {
class RotatingFileHandler extends BaseRotatingFileHandler
{
use RotatingFileHandlerTrait {
setFilenameFormat as private typedSetFilenameFormat;
}

public function setFilenameFormat($filenameFormat, $dateFormat)
{
return $this->typedSetFilenameFormat($filenameFormat, $dateFormat);
}
}
} else {
class RotatingFileHandler extends BaseRotatingFileHandler
{
use RotatingFileHandlerTrait;
}
class RotatingFileHandler extends BaseRotatingFileHandler
{
use RotatingFileHandlerTrait;
}
2 changes: 1 addition & 1 deletion Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct(
StrategyRepositoryInterface $strategyRepository,
LoadStrategyRepositoryInterface $loadStrategyRepository,
ConfigurationInterface $configuration,
LoggerInterface $logger = null
?LoggerInterface $logger = null
) {
$this->configuration = $configuration;
$this->connection = $connection;
Expand Down
2 changes: 1 addition & 1 deletion ImportConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('import');

/** @var ArrayNodeDefinition */
/** @var ArrayNodeDefinition $rootNode */
$rootNode = $treeBuilder->getRootNode();

$replaceParameter = function ($string) {
Expand Down
2 changes: 1 addition & 1 deletion Load/CsvLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

use Behat\Transliterator\Transliterator;
use Doctrine\DBAL\Connection;
use ForceUTF8\Encoding;
use LePhare\Import\Configuration\CredentialsInterface;
use LePhare\Import\Exception\ImportException;
use LePhare\Import\ImportResource;
use ForceUTF8\Encoding;

/** @api */
class CsvLoader implements LoaderInterface
Expand Down
2 changes: 1 addition & 1 deletion Load/ExcelLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function supports(ImportResource $resource, array $context): bool
return false;
}

if (!class_exists(\PhpOffice\PhpSpreadsheet\IOFactory::class)) {
if (!class_exists(IOFactory::class)) {
throw new ImportException('PhpSpreadsheet library is missing. Try "composer require phpoffice/phpspreadsheet"');
}

Expand Down
2 changes: 1 addition & 1 deletion Load/TextLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

use Behat\Transliterator\Transliterator;
use Doctrine\DBAL\Connection;
use ForceUTF8\Encoding;
use LePhare\Import\Configuration\CredentialsInterface;
use LePhare\Import\Exception\ImportException;
use LePhare\Import\ImportResource;
use ForceUTF8\Encoding;

/** @api */
class TextLoader implements LoaderInterface
Expand Down
2 changes: 1 addition & 1 deletion Tests/ImportConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public function providerConfigurations(): iterable
];

yield '“delimiter” should be evaluated' => [
array_merge($defaults, [
array_merge($defaults, [
'name' => $config['name'],
'source_dir' => str_replace('%kernel.project_dir%', '/app', $config['source_dir']),
'resources' => [
Expand Down
5 changes: 2 additions & 3 deletions Tests/ImportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Psr\Log\LoggerInterface;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Yaml\Yaml;

/**
* @covers \LePhare\Import\Import
Expand Down Expand Up @@ -112,7 +111,7 @@ public function testExecuteWithException(): void
'strategy' => 'load_alphabetically',
],
],
], ]));
], ]));

$this->assertFalse($this->import->execute());
}
Expand Down Expand Up @@ -142,7 +141,7 @@ public function testExecuteWithWrongStrategyShouldFail(): void
'strategy' => 'bad_strategy_name',
],
],
], ]));
], ]));

$this->assertFalse($this->import->execute());
}
Expand Down
9 changes: 9 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,20 @@
"php-mock/php-mock-prophecy": "^0.1.1",
"phpoffice/phpspreadsheet": "^1.19",
"phpspec/prophecy": "^1.10",
"phpspec/prophecy-phpunit": "^2.2",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "^1.4",
"phpunit/phpunit": "^9.6",
"symfony/phpunit-bridge": "^5.4|^6.0|^7.0"
},
"scripts": {
"analyse": "./vendor/bin/phpstan analyse --no-progress",
"lint": "@lint:fix --dry-run",
"lint:ci": "@lint:fix --using-cache=no --dry-run",
"lint:fix": "./vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php",
"test:ci": "@test --colors=never --coverage-text",
"test": "./vendor/bin/phpunit"
},
"suggest": {
"phpoffice/phpspreadsheet": "Import XLS files"
},
Expand Down
9 changes: 9 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,13 @@ parameters:
- .
excludePaths:
- vendor
ignoreErrors:
-
message: '#Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\NodeParentInterface::.+\(\)#'
paths:
- ImportConfiguration.php
-
message: '#Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\NodeDefinition::.+\(\)#'
paths:
- ImportConfiguration.php
tmpDir: .phpstan.cache
36 changes: 17 additions & 19 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd" backupGlobals="false" colors="true" bootstrap="vendor/autoload.php" failOnRisky="true" failOnWarning="true">
<testsuites>
<testsuite name="Import Test Suite">
<directory>./Tests/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>./</directory>
<exclude>
<directory suffix=".dist.php">./</directory>
<directory>./Resources</directory>
<directory>./Tests</directory>
<directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="false" colors="true" bootstrap="vendor/autoload.php" failOnRisky="true" failOnWarning="true">
<coverage>
<include>
<directory>./</directory>
</include>
<exclude>
<directory suffix=".dist.php">./</directory>
<directory>./Resources</directory>
<directory>./Tests</directory>
<directory>./vendor</directory>
</exclude>
</coverage>
<testsuites>
<testsuite name="Import Test Suite">
<directory>./Tests/</directory>
</testsuite>
</testsuites>
</phpunit>
13 changes: 13 additions & 0 deletions release-please-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json",
"release-type": "php",
"include-component-in-tag": false,
"packages": {
".": {
"changelog-path": "CHANGELOG.md",
"draft": true,
"package-name": "release-please-action",
"release-type": "php"
}
}
}

0 comments on commit e49ba42

Please sign in to comment.