Skip to content

Commit

Permalink
Merge pull request #483 from KnpLabs/v2-unstable-bundle-config
Browse files Browse the repository at this point in the history
feat: add bundle configuration
  • Loading branch information
alexpozzi authored Oct 9, 2023
2 parents 1923834 + c4f42da commit 9f6a146
Show file tree
Hide file tree
Showing 13 changed files with 461 additions and 32 deletions.
75 changes: 50 additions & 25 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,55 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
- name: Validate composer.json
run: composer validate --strict --no-check-lock
cs-fixer:
run: |
(cd src/Bundle && composer validate --strict --no-check-lock)
tests:
runs-on: ubuntu-20.04
name: PHP-CS-Fixer
strategy:
fail-fast: false
matrix:
include:
- description: 'Symfony 6.3 DEV'
php: '8.2'
symfony: '6.3.*@dev'
- description: 'Symfony 6.2'
php: '8.2'
symfony: '6.2.*'
- description: 'Symfony 6.0'
php: '8.1'
symfony: '6.0.*'
- description: 'Symfony 5.4'
php: '7.3'
symfony: '5.4.*'
- description: 'Beta deps'
php: '7.2'
beta: true
name: PHP ${{ matrix.php }} tests (${{ matrix.description }})
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Cache
uses: actions/cache@v3
with:
path: ~/.composer/cache/files
key: composer-${{ matrix.php }}-${{ matrix.symfony }}-${{ matrix.composer_option }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.3'
- run: composer install --prefer-dist --no-interaction --no-progress --ansi
- run: vendor/bin/php-cs-fixer fix --diff --dry-run --verbose
tests:
runs-on: ubuntu-20.04
php-version: ${{ matrix.php }}
- run: |
sed -ri 's/"symfony\/(.+)": "(.+)"/"symfony\/\1": "'${{ matrix.symfony }}'"/' src/Bundle/composer.json;
if: matrix.symfony
- run: |
composer config minimum-stability dev
composer config prefer-stable true
if: matrix.beta
- run: |
(cd src/Bundle && composer update --prefer-dist --no-interaction --no-progress --ansi ${{ matrix.composer_option }})
- run: |
(cd src/Bundle && vendor/bin/phpunit)
tests-windows:
runs-on: windows-2022
strategy:
fail-fast: false
matrix:
Expand All @@ -41,19 +75,13 @@ jobs:
- description: 'Symfony 6.0'
php: '8.1'
symfony: '6.0.*'
- description: 'Symfony 5.0'
- description: 'Symfony 5.4'
php: '7.3'
symfony: '5.0.*'
- description: 'Symfony 4.4'
php: '7.1'
symfony: '4.3.*@dev'
- description: 'Symfony 3.4'
php: '7.3'
symfony: '3.4.*'
symfony: '5.4.*'
- description: 'Beta deps'
php: '7.2'
beta: true
name: PHP ${{ matrix.php }} tests (${{ matrix.description }})
name: "[WINDOWS] PHP ${{ matrix.php }} tests (${{ matrix.description }})"
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -67,16 +95,13 @@ jobs:
with:
php-version: ${{ matrix.php }}
- run: |
sed -ri 's/"symfony\/(.+)": "(.+)"/"symfony\/\1": "'${{ matrix.symfony }}'"/' composer.json;
(Get-Content composer.json) -replace '("symfony/[^"]+": )"[^"]+"', '$1"${{ matrix.symfony }}"' | Out-File -encoding ASCII src/Bundle/composer.json
if: matrix.symfony
- run: |
composer config minimum-stability dev
composer config prefer-stable true
if: matrix.beta
- name: remove cs-fixer for Symfony 6
if: contains(matrix.symfony, '6.3.*@dev')
run: |
composer remove --dev friendsofphp/php-cs-fixer pedrotroller/php-cs-custom-fixer --no-update
- run: composer update --prefer-dist --no-interaction --no-progress --ansi ${{ matrix.composer_option }}
- run: vendor/bin/phpunit
- run: vendor/bin/phpstan analyse --ansi --no-progress
- run: |
{cd src/Bundle && composer update --prefer-dist --no-interaction --no-progress --ansi ${{ matrix.composer_option }}}
- run: |
{cd src/Bundle && vendor/bin/phpunit}
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM composer:2.6.3 as composer

###############################

FROM php:8.2.10-fpm-alpine3.18

WORKDIR /src

COPY --from=composer /usr/bin/composer /usr/bin/composer

COPY ./entrypoint /usr/local/share/entrypoint
COPY ./src /src

ENTRYPOINT ["/usr/local/share/entrypoint"]
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
IMAGE_TAG:=knplabs/snappy:test

.PHONY: build
build:
docker build ./ -t "${IMAGE_TAG}"

.PHONY: test
test: build
$(MAKE) -C src/Bundle test IMAGE_TAG="${IMAGE_TAG}" ARGS="${ARGS}"
8 changes: 8 additions & 0 deletions entrypoint
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh

set -o pipefail
set -o errexit

(cd /src/Bundle && composer install)

exec "${@}"
3 changes: 2 additions & 1 deletion src/Bundle/.gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/spec/ export-ignore
/Tests/ export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/phpunit.xml.dist export-ignore
1 change: 1 addition & 0 deletions src/Bundle/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/composer.lock
/vendor
.phpunit.result.cache
49 changes: 49 additions & 0 deletions src/Bundle/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

namespace KnpLabs\Snappy\Bundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('snappy');

$treeBuilder->getRootNode()
->children()
->arrayNode('backends')
->useAttributeAsKey('name')
->arrayPrototype()
->children()
->scalarNode('driver')
->isRequired()
->validate()
->ifNotInArray(['wkhtmltopdf', 'chromium'])
->thenInvalid('Invalid backend driver %s')
->end()
->end()
->integerNode('timeout')
->min(1)
->defaultValue(30)
->end()
->scalarNode('binary_path')
->isRequired()
->cannotBeEmpty()
->end()
->arrayNode('options')
->useAttributeAsKey('name')
->scalarPrototype()->end()
->end()
->end()
->end()
->end()
->end()
;

return $treeBuilder;
}
}
18 changes: 18 additions & 0 deletions src/Bundle/DependencyInjection/SnappyExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace KnpLabs\Snappy\Bundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;

class SnappyExtension extends Extension
{
public function load(array $config, ContainerBuilder $container): void
{
foreach($config['backends'] as $backend) {
// @TODO: load backend services
}
}
}
3 changes: 3 additions & 0 deletions src/Bundle/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.PHONY: test
test:
docker run --rm -i -w /src/Bundle -v "$(shell pwd)/../:/src" "${IMAGE_TAG}" vendor/bin/phpunit $(ARGS) -v
6 changes: 4 additions & 2 deletions src/Bundle/SnappyBundle.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?php

declare(strict_types=1);

namespace KnpLabs\Snappy\Bundle;

use Symfony\Component\HttpKernel\Bundle\AbstractBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;

class SnappyBundle extends AbstractBundle
class SnappyBundle extends Bundle
{

}
Loading

0 comments on commit 9f6a146

Please sign in to comment.