Skip to content

Commit

Permalink
Revive CI (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubtobiasz authored Sep 5, 2024
2 parents feafac6 + 6b63355 commit 8eba93d
Show file tree
Hide file tree
Showing 19 changed files with 187 additions and 54 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/_matrix.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"pr": {
"ci": {
"include": [
{
"php": "8.0",
"sylius": "1.12.*",
"symfony": "5.4.*",
"mysql": "8.0"
},
{
"php": "8.3",
"sylius": "1.13.*",
"symfony": "6.4.*",
"mysql": "8.0"
}
]
},
"daily": {
"php": ["8.0", "8.3"],
"sylius": ["1.12.*", "1.13.*"],
"symfony": ["5.4.*", "6.4.*"],
"mysql": ["8.0"]
}
}
}
61 changes: 40 additions & 21 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,42 @@
name: Continuous Integration

on:
push: ~
pull_request: ~
release:
types: [created]
workflow_dispatch: ~
workflow_call:
inputs:
type:
description: "Type of the build"
required: true
type: string

jobs:
get-matrix:
runs-on: ubuntu-latest
name: "Get matrix"
outputs:
matrix: ${{ steps.matrix.outputs.prop }}
steps:
- name: "Checkout"
uses: actions/checkout@v4

-
name: "Get matrix"
id: matrix
uses: notiz-dev/github-action-json-property@release
with:
path: '.github/workflows/_matrix.json'
prop_path: '${{ inputs.type }}.ci'

tests:
needs: get-matrix

runs-on: ubuntu-latest

name: "Sylius ${{ matrix.sylius }}, PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }}, MySQL ${{ matrix.mysql }}"

strategy:
fail-fast: false
matrix:
php: ["8.0", "8.1"]
symfony: ["5.4.*", "^6.0"]
sylius: ["^1.12"]
node: ["16.x"]
mysql: ["5.7", "8.0"]
matrix: ${{ fromJson(needs.get-matrix.outputs.matrix) }}

env:
APP_ENV: test
Expand All @@ -36,18 +52,21 @@ jobs:
build_type: "plugin"
cache_key: "${{ github.run_id }}-${{ runner.os }}-${{ hashFiles('composer.json') }}-sylius-${{ matrix.sylius }}-symfony-${{ matrix.symfony }}"
cache_restore_key: "${{ github.run_id }}-${{ runner.os }}-${{ hashFiles('composer.json') }}-sylius-${{ matrix.sylius }}-symfony-${{ matrix.symfony }}"
e2e: "yes"
e2e_js: "yes"
database_version: ${{ matrix.mysql }}
php_version: ${{ matrix.php }}
symfony_version: ${{ matrix.symfony }}
sylius_version: ${{ matrix.sylius }}
e2e_js: true

-
name: Upload logs
uses: actions/upload-artifact@v3
if: failure()
with:
name: Logs
path: |
var/log/
if-no-files-found: ignore
- name: Check dependencies
continue-on-error: true
run: vendor/bin/composer-dependency-analyser

- name: Static analysis
run: vendor/bin/phpstan

- name: Check coding standard
run: vendor/bin/ecs check

- name: Run tests
run: vendor/bin/phpunit
18 changes: 18 additions & 0 deletions .github/workflows/ci__daily.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Continuous Integration (Daily)

on:
schedule:
-
cron: "0 3 * * *" # Run every day at 3am
workflow_dispatch: ~

concurrency:
group: ci-${{ github.workflow }}-${{ github.ref }}-minimal
cancel-in-progress: true

jobs:
ci:
name: CI
uses: ./.github/workflows/ci.yaml
with:
type: "daily"
22 changes: 22 additions & 0 deletions .github/workflows/ci__pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Continuous Integration (PR)

on:
pull_request:
paths-ignore:
- ".platform/**"
- "*.md"
push:
branches:
- main
workflow_dispatch: ~

concurrency:
group: ci-${{ github.workflow }}-${{ github.ref }}-minimal
cancel-in-progress: true

jobs:
ci:
name: CI
uses: ./.github/workflows/ci.yaml
with:
type: "pr"
14 changes: 14 additions & 0 deletions composer-dependency-analyser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

use ShipMonk\ComposerDependencyAnalyser\Config\Configuration;
use ShipMonk\ComposerDependencyAnalyser\Config\ErrorType;

$config = new Configuration();

return $config
//// Adjusting scanned paths
->addPathToScan(__DIR__ . '/src', isDev: false)
->disableComposerAutoloadPathScan() // disable automatic scan of autoload & autoload-dev paths from composer.json
->ignoreErrorsOnPackage('sylius/sylius', [ErrorType::DEV_DEPENDENCY_IN_PROD])
->ignoreErrorsOnPackage('sylius/core-bundle', [ErrorType::UNUSED_DEPENDENCY])
;
24 changes: 15 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
"license": "MIT",
"autoload": {
"psr-4": {
"CommerceWeavers\\SyliusTpayPlugin\\": "src/",
"Tests\\CommerceWeavers\\SyliusTpayPlugin\\Behat\\": "tests/Behat"
"CommerceWeavers\\SyliusTpayPlugin\\": "src/"
}
},
"autoload-dev": {
Expand All @@ -18,13 +17,20 @@
"require": {
"php": "^8.0",
"sylius/core-bundle": "^1.12",
"tpay-com/tpay-openapi-php": "^1.8"
"tpay-com/tpay-openapi-php": "^1.8",
"payum/core": "^1.7",
"sylius/resource-bundle": "^1.10",
"symfony/config": "5.4.* || ^6.0",
"symfony/dependency-injection": "5.4.* || ^6.0",
"symfony/form": "5.4.* || ^6.0",
"symfony/http-foundation": "5.4.* || ^6.0",
"symfony/http-kernel": "5.4.* || ^6.0",
"symfony/routing": "5.4.* || ^6.0"
},
"conflict": {
"sylius/sylius": "<1.12"
},
"require-dev": {
"alphpaca/monocle-constraint": "^0.1",
"phpspec/prophecy-phpunit": "^2.2",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "^1.8.1",
Expand All @@ -33,32 +39,32 @@
"phpstan/phpstan-webmozart-assert": "^1.2.0",
"phpunit/phpunit": "^9.5",
"polishsymfonycommunity/symfony-mocker-container": "^1.0",
"shipmonk/composer-dependency-analyser": "^1.7",
"sylius-labs/coding-standard": "^4.2",
"sylius/sylius": "^1.12",
"symfony/browser-kit": "^5.4 || ^6.0",
"symfony/debug-bundle": "^5.4 || ^6.0",
"symfony/dotenv": "^5.4 || ^6.0",
"symfony/flex": "^2.4",
"symfony/intl": "^5.4 || ^6.0",
"symfony/monolog-bundle": "^3.10",
"symfony/web-profiler-bundle": "^5.4 || ^6.0"
},
"config": {
"sort-packages": true,
"allow-plugins": {
"alphpaca/monocle-constraint": true,
"dealerdirect/phpcodesniffer-composer-installer": false,
"phpstan/extension-installer": true,
"symfony/flex": true,
"symfony/runtime": true
}
},
"extra": {
"branch-alias": {
"dev-main": "1.0-dev"
},
"monocle": {
"constraint": {
"symfony/symfony": "5.4.*"
}
"symfony": {
"require": "5.4.*"
}
},
"scripts": {
Expand Down
1 change: 0 additions & 1 deletion ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

declare(strict_types=1);

use PhpCsFixer\Fixer\ClassNotation\VisibilityRequiredFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;

return static function (ECSConfig $ecsConfig): void {
Expand Down
7 changes: 3 additions & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ parameters:
paths:
- src

excludes_analyse:
# Makes PHPStan crash
excludePaths:
- 'src/CommerceWeaversSyliusTpayPlugin.php'
- 'src/DependencyInjection/Configuration.php'

# Test dependencies
- 'tests/Application/src/**.php'

ignoreErrors:
- '/Parameter #1 \$configuration of method Symfony\\Component\\DependencyInjection\\Extension\\Extension::processConfiguration\(\) expects Symfony\\Component\\Config\\Definition\\ConfigurationInterface, Symfony\\Component\\Config\\Definition\\ConfigurationInterface\|null given\./'
- '/Parameter \#1 \$request \([^)]+\) of method [^:]+::execute\(\) should be contravariant with parameter \$request \(mixed\) of method Payum\\Core\\Action\\ActionInterface::execute\(\)/'
14 changes: 12 additions & 2 deletions src/CommerceWeaversSyliusTpayPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,19 @@
namespace CommerceWeavers\SyliusTpayPlugin;

use Sylius\Bundle\CoreBundle\Application\SyliusPluginTrait;
use Symfony\Component\HttpKernel\Bundle\AbstractBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;

final class CommerceWeaversSyliusTpayPlugin extends AbstractBundle
final class CommerceWeaversSyliusTpayPlugin extends Bundle
{
use SyliusPluginTrait;

public function getPath(): string
{
if (!isset($this->path)) {
$reflected = new \ReflectionObject($this);
$this->path = \dirname($reflected->getFileName(), 2);
}

return $this->path;
}
}
4 changes: 2 additions & 2 deletions src/Controller/PaymentNotificationAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

final class PaymentNotificationAction
{
public function __construct (
public function __construct(
private Payum $payum,
private NotifyFactoryInterface $notifyFactory,
) {
Expand All @@ -34,7 +34,7 @@ public function __invoke(Request $request): Response

return new Response('TRUE');
} catch (HttpResponse $reply) {
return new Response($reply->getCode(), $reply->getStatusCode(), $reply->getHeaders());
return new Response((string) $reply->getCode(), $reply->getStatusCode(), $reply->getHeaders());
} catch (ReplyInterface $reply) {
throw new \LogicException('Unsupported reply', previous: $reply);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __invoke(PreSubmitEvent $preSubmitEvent): void
[
'label' => 'commerce_weavers_sylius_tpay.admin.gateway_configuration.client_secret',
'mapped' => false,
]
],
);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Form/Type/TpayGatewayConfigurationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

final class TpayGatewayConfigurationType extends AbstractType
{
public function __construct (
public function __construct(
private PreventSavingEmptyClientSecretListener $preventSavingEmptyClientSecretListener,
) {
}
Expand All @@ -37,15 +37,15 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
PasswordType::class,
[
'label' => 'commerce_weavers_sylius_tpay.admin.gateway_configuration.client_secret',
]
],
)
->add(
'production_mode',
CheckboxType::class,
[
'label' => 'commerce_weavers_sylius_tpay.admin.gateway_configuration.production_mode',
'value' => false,
]
],
)
;

Expand Down
15 changes: 12 additions & 3 deletions src/Payum/Action/Api/CreateTransactionAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Routing\RouterInterface;
use Tpay\OpenApi\Api\TpayApi;
use Webmozart\Assert\Assert;

/**
* @property TpayApi $api
Expand All @@ -20,7 +21,7 @@ final class CreateTransactionAction extends BaseApiAwareAction implements Generi
{
use GenericTokenFactoryAwareTrait;

public function __construct (
public function __construct(
private RouterInterface $router,
private string $successRoute,
private string $errorRoute,
Expand All @@ -37,16 +38,24 @@ public function execute($request): void
/** @var PaymentInterface $model */
$model = $request->getModel();
$details = $model->getDetails();
$token = $request->getToken();
Assert::notNull($token);

$order = $model->getOrder();
Assert::notNull($order);
$localeCode = $order->getLocaleCode();
Assert::notNull($localeCode);
$customer = $order->getCustomer();
Assert::notNull($customer);
$billingAddress = $order->getBillingAddress();
Assert::notNull($billingAddress);
$amount = $model->getAmount();
Assert::notNull($amount);

$notifyToken = $this->createNotifyToken($model, $request->getToken(), $localeCode);
$notifyToken = $this->createNotifyToken($model, $token, $localeCode);

$response = $this->api->transactions()->createTransaction([
'amount' => number_format($model->getAmount() / 100, 2, thousands_separator: ''),
'amount' => number_format($amount / 100, 2, thousands_separator: ''),
'description' => sprintf('zamówienie #%s', $order->getNumber()), // TODO: Introduce translations
'payer' => [
'email' => $customer->getEmail(),
Expand Down
3 changes: 2 additions & 1 deletion src/Payum/Action/Api/NotifyAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ public function execute($request): void
$model = $request->getModel();
$details = $model->getDetails();

/** @var array{tr_status?: string} $notificationData */
$notificationData = $request->getData();
$status = $notificationData['tr_status'] ?? '';

$details['tpay']['status'] = match(true) {
$details['tpay']['status'] = match (true) {
str_contains($status, 'TRUE') => PaymentInterface::STATE_COMPLETED,
str_contains($status, 'CHARGEBACK') => PaymentInterface::STATE_REFUNDED,
default => PaymentInterface::STATE_FAILED,
Expand Down
Loading

0 comments on commit 8eba93d

Please sign in to comment.