Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .dagger/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Auto-generated by Dagger - do not commit
/sdk
/vendor
/.env
composer.json
composer.lock
entrypoint.php
README.md
.gitattributes
187 changes: 187 additions & 0 deletions .dagger/src/NormalizerBundle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
<?php

declare(strict_types=1);

namespace DaggerModule;

use Dagger\Attribute\DaggerFunction;
use Dagger\Attribute\DaggerObject;
use Dagger\Attribute\Doc;
use Dagger\Container;
use Dagger\Directory;

use function Dagger\dag;

#[DaggerObject]
#[Doc('BowlOfSoup NormalizerBundle CI Pipeline')]
class NormalizerBundle
{
#[DaggerFunction]
#[Doc('Create a PHP container with dependencies installed')]
public function base(
#[Doc('The source directory')]
Directory $source,
#[Doc('PHP version to use')]
string $phpVersion = '7.4'
): Container {
return dag()
->container()
->from("php:{$phpVersion}-cli")
->withExec(['apt-get', 'update'])
->withExec([
'apt-get',
'install',
'-y',
'git',
'unzip',
'libzip-dev',
'libxml2-dev',
])
->withExec(['docker-php-ext-install', 'zip', 'dom', 'simplexml'])
->withExec([
'sh',
'-c',
'curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer --version=1.10.22',
])
->withExec(['sh', '-c', "echo 'memory_limit = -1' > /usr/local/etc/php/conf.d/memory.ini"])
->withEnvVariable('COMPOSER_MEMORY_LIMIT', '-1')
->withMountedDirectory('/src', $source)
->withWorkdir('/src')
->withExec(['composer', 'install', '--no-interaction', '--prefer-dist']);
}

#[DaggerFunction]
#[Doc('Run Rector checks (dry-run)')]
public function rector(
#[Doc('The source directory')]
Directory $source,
#[Doc('PHP version to use')]
string $phpVersion = '7.4'
): string {
return $this->base($source, $phpVersion)
->withExec([
'vendor/bin/rector',
'process',
'--dry-run',
'--no-progress-bar',
'--ansi',
])
->stdout();
}

#[DaggerFunction]
#[Doc('Run PHPStan static analysis')]
public function phpstan(
#[Doc('The source directory')]
Directory $source,
#[Doc('PHP version to use')]
string $phpVersion = '7.4'
): string {
return $this->base($source, $phpVersion)
->withExec(['vendor/bin/phpstan', 'analyze', '--no-progress', '--ansi'])
->stdout();
}

#[DaggerFunction]
#[Doc('Run PHP-CS-Fixer checks (dry-run)')]
public function phpCsFixer(
#[Doc('The source directory')]
Directory $source,
#[Doc('PHP version to use')]
string $phpVersion = '7.4'
): string {
return $this->base($source, $phpVersion)
->withExec(['vendor/bin/php-cs-fixer', 'fix', '--dry-run', '--diff'])
->stdout();
}

#[DaggerFunction]
#[Doc('Run PHPUnit tests')]
public function phpunit(
#[Doc('The source directory')]
Directory $source,
#[Doc('PHP version to use')]
string $phpVersion = '7.4'
): string {
return $this->base($source, $phpVersion)
->withExec(['vendor/bin/phpunit'])
->stdout();
}

#[DaggerFunction]
#[Doc('Run PHPUnit tests with coverage and export coverage directory')]
public function phpunitCoverage(
#[Doc('The source directory')]
Directory $source,
#[Doc('PHP version to use')]
string $phpVersion = '8.2'
): Directory {
$container = $this->base($source, $phpVersion)
->withExec(['pecl', 'install', 'xdebug'])
->withExec(['docker-php-ext-enable', 'xdebug'])
->withEnvVariable('XDEBUG_MODE', 'coverage')
->withExec(['php', 'vendor/bin/phpunit']);

return $container->directory('/src/tests/coverage');
}

#[DaggerFunction]
#[Doc('Run all CI checks (PHPStan and PHPUnit)')]
public function test(
#[Doc('The source directory')]
Directory $source,
#[Doc('PHP version to use')]
string $phpVersion = '7.4',
#[Doc('Include Rector checks (optional, disabled by default)')]
bool $includeRector = false
): string {
$container = $this->base($source, $phpVersion);

// Run Rector if requested
if ($includeRector) {
$rectorOutput = $container
->withExec([
'vendor/bin/rector',
'process',
'--dry-run',
'--no-progress-bar',
'--ansi',
])
->stdout();
}

// Run PHPStan
$phpstanOutput = $container
->withExec(['vendor/bin/phpstan', 'analyze', '--no-progress', '--ansi'])
->stdout();

// Run PHPUnit and return output
$phpunitOutput = $container
->withExec(['vendor/bin/phpunit'])
->stdout();

return "✅ All CI checks passed!\n\n" . $phpunitOutput;
}

#[DaggerFunction]
#[Doc('Run CI for multiple PHP versions')]
public function testMatrix(
#[Doc('The source directory')]
Directory $source
): string {
$versions = ['7.2', '7.4', '8.2'];
$results = [];

foreach ($versions as $version) {
try {
$this->test($source, $version);
$results[] = "✅ PHP {$version}: PASSED";
} catch (\Exception $e) {
$results[] = "❌ PHP {$version}: FAILED";
throw $e;
}
}

return implode("\n", $results);
}
}
57 changes: 25 additions & 32 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,47 +11,40 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-version: [7.2, 7.4, 8.2]
include:
- php-version: 8.2
env:
SYMFONY_VERSION: ~5.4
php-version: [7.4, 8.2]
fail-fast: false

steps:
- uses: actions/checkout@v3

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
tools: composer:1.10.22

- name: Cache Composer dependencies
uses: actions/cache@v2
with:
path: $HOME/.composer/cache
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
- name: Install Dagger CLI
run: |
if [ "${{ matrix.env.SYMFONY_VERSION }}" != "" ]; then composer require "symfony/symfony:${{ matrix.env.SYMFONY_VERSION }}" --no-update; fi;
COMPOSER_MEMORY_LIMIT=-1 composer install
curl -fsSL https://dl.dagger.io/dagger/install.sh | BIN_DIR=$HOME/.local/bin sh
echo "$HOME/.local/bin" >> $GITHUB_PATH

- name: Setup Codecov
run: |
curl -Os https://uploader.codecov.io/latest/linux/codecov
chmod +x codecov
- name: Run Dagger CI Pipeline
run: dagger call test --source=. --php-version=${{ matrix.php-version }}
env:
DAGGER_CLOUD_TOKEN: ${{ secrets.DAGGER_CLOUD_TOKEN }}

- name: Run Rector
run: vendor/bin/rector process --dry-run --no-progress-bar --ansi
# Run with code coverage on PHP 8.2 and upload to Codecov
coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Run PHPStan
run: vendor/bin/phpstan analyze --no-progress --ansi
- name: Install Dagger CLI
run: |
curl -fsSL https://dl.dagger.io/dagger/install.sh | BIN_DIR=$HOME/.local/bin sh
echo "$HOME/.local/bin" >> $GITHUB_PATH

- name: Run PHPUnit tests
run: XDEBUG_MODE=coverage php vendor/bin/phpunit
- name: Run PHPUnit with Coverage
run: |
dagger call phpunit-coverage --source=. --php-version=8.2 export --path=./coverage

- name: Upload coverage to Codecov
run: ./codecov
uses: codecov/codecov-action@v4
with:
files: ./coverage/clover.xml
fail_ci_if_error: false
token: ${{ secrets.CODECOV_TOKEN }}
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@
!/var/**/
!/var/**/.gitkeep
/phpstan.neon
>>>>>>> fc967e0fc51238085fa8a2a2882bcdab42090dec

# Dagger
/.dagger/vendor/
/.dagger/sdk/
Loading
Loading