Skip to content
This repository has been archived by the owner on Mar 29, 2024. It is now read-only.

Commit

Permalink
upgraded the development stack
Browse files Browse the repository at this point in the history
  • Loading branch information
xavierlacot committed Sep 4, 2023
1 parent b80d155 commit 6737fdc
Show file tree
Hide file tree
Showing 35 changed files with 3,053 additions and 3,242 deletions.
18 changes: 9 additions & 9 deletions .castor/infra.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function destroy(

docker_compose(['down', '--remove-orphans', '--volumes', '--rmi=local'], withBuilder: true);
$files = finder()
->in(variable('root_dir') . '/infrastructure/docker/services/router/etc/ssl/certs/')
->in(variable('root_dir') . '/infrastructure/docker/services/router/certs/')
->name('*.pem')
->files()
;
Expand All @@ -91,20 +91,20 @@ function generate_certificates(
#[AsOption(description: 'Force the certificates re-generation without confirmation', shortcut: 'f')]
bool $force = false,
): void {
if (file_exists(variable('root_dir') . '/infrastructure/docker/services/router/etc/ssl/certs/cert.pem') && !$force) {
if (file_exists(variable('root_dir') . '/infrastructure/docker/services/router/certs/cert.pem') && !$force) {
io()->comment('SSL certificates already exists.');
io()->note('Run "castor infra:generate-certificates --force" to generate new certificates.');

return;
}

if ($force) {
if (file_exists($f = variable('root_dir') . '/infrastructure/docker/services/router/etc/ssl/certs/cert.pem')) {
io()->comment('Removing existing certificates in infrastructure/docker/services/router/etc/ssl/certs/*.pem.');
if (file_exists($f = variable('root_dir') . '/infrastructure/docker/services/router/certs/cert.pem')) {
io()->comment('Removing existing certificates in infrastructure/docker/services/router/certs/*.pem.');
unlink($f);
}

if (file_exists($f = variable('root_dir') . '/infrastructure/docker/services/router/etc/ssl/certs/key.pem')) {
if (file_exists($f = variable('root_dir') . '/infrastructure/docker/services/router/certs/key.pem')) {
unlink($f);
}
}
Expand All @@ -125,8 +125,8 @@ function generate_certificates(

run([
'mkcert',
'-cert-file', 'infrastructure/docker/services/router/etc/ssl/certs/cert.pem',
'-key-file', 'infrastructure/docker/services/router/etc/ssl/certs/key.pem',
'-cert-file', 'infrastructure/docker/services/router/certs/cert.pem',
'-key-file', 'infrastructure/docker/services/router/certs/key.pem',
$rootDomain,
"*.{$rootDomain}",
...variable('extra_domains'),
Expand All @@ -141,9 +141,9 @@ function generate_certificates(
return;
}

run(['infrastructure/docker/services/router/generate-ssl.sh']);
run(['infrastructure/docker/services/router/generate-ssl.sh'], quiet: true);

io()->success('Successfully generated self-signed SSL certificates in infrastructure/docker/services/router/etc/ssl/certs/*.pem.');
io()->success('Successfully generated self-signed SSL certificates in infrastructure/docker/services/router/certs/*.pem.');
io()->comment('Consider installing mkcert to generate locally trusted SSL certificates and run "castor infra:generate-certificates --force".');

if ($force) {
Expand Down
70 changes: 70 additions & 0 deletions .castor/qa.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

namespace qa;

use Castor\Attribute\AsOption;
use Castor\Attribute\AsTask;
use Symfony\Component\Console\Input\InputOption;

use function Castor\get_context;

#[AsTask(description: 'Runs all QA tasks')]
function all(): void
{
install();
cs();
phpstan();
rector();
twig_lint();
yaml_lint();
}

#[AsTask(description: 'Installs tooling')]
function install(): void
{
docker_compose_run('composer install -o', workDir: '/home/app/root/tools/php-cs-fixer');
docker_compose_run('composer install -o', workDir: '/home/app/root/tools/phpstan');
docker_compose_run('composer install -o', workDir: '/home/app/root/tools/rector');
}

#[AsTask(description: 'Fix coding standards')]
function cs(
#[AsOption(name: 'dry-run', description: 'Do not make changes and outputs diff', mode: InputOption::VALUE_NONE)]
?bool $dryRun = null,
): int {
$command = 'php-cs-fixer fix';

if ($dryRun === true) {
$command .= ' --dry-run --diff';
}

$c = get_context()
->withAllowFailure(true)
;

return docker_compose_run($command, c: $c, workDir: '/home/app/root')->getExitCode();
}

#[AsTask(description: 'Run the phpstan analysis')]
function phpstan(): int
{
return docker_compose_run('phpstan --configuration=/home/app/root/phpstan.neon analyse', workDir: '/home/app/root')->getExitCode();
}

#[AsTask(description: 'Run the rector upgrade')]
function rector(): int
{
return docker_compose_run('rector process', workDir: '/home/app/root')->getExitCode();
}

#[AsTask(name: 'twig-lint', description: 'Lint twig files')]
function twig_lint(): int
{
return docker_compose_run('bin/console lint:twig --show-deprecations templates', workDir: '/home/app/root')->getExitCode();
}

#[AsTask(name: 'yaml-lint', description: 'Lint YAML files')]
function yaml_lint(): int
{
return docker_compose_run('bin/console lint:yaml config', workDir: '/home/app/root')->getExitCode();
}
19 changes: 13 additions & 6 deletions .castor/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function about(): void
}

#[AsTask(description: 'Opens a shell (bash) into a builder container')]
function builder(string $user = 'app'): void
function builder(): void
{
$c = get_context()
->withTimeout(null)
Expand All @@ -56,7 +56,7 @@ function builder(string $user = 'app'): void
->withQuiet()
->withAllowFailure()
;
docker_compose_run('bash', c: $c, user: $user);
docker_compose_run('bash', c: $c);
}

#[AsContext(default: true)]
Expand All @@ -83,7 +83,15 @@ function create_default_context(): Context
$data['docker_compose_files'][] = 'docker-compose.override.yml';
}

$data['composer_cache_dir'] = cache('composer_cache_dir', fn () => capture(['composer', 'global', 'config', 'cache-dir', '-q'], onFailure: sys_get_temp_dir() . '/castor/composer'));
$data['composer_cache_dir'] = cache('composer_cache_dir', function () {
$composerCacheDir = capture(['composer', 'global', 'config', 'cache-dir', '-q'], onFailure: '');
// If PHP is broken, the output will not be a valid path but an error message
if (!is_dir($composerCacheDir)) {
$composerCacheDir = sys_get_temp_dir() . '/castor/composer';
}

return $composerCacheDir;
});

$platform = strtolower(php_uname('s'));
if (str_contains($platform, 'darwin')) {
Expand All @@ -110,7 +118,6 @@ function docker_compose_run(
string $runCommand,
Context $c = null,
string $service = 'builder',
string $user = 'app',
bool $noDeps = true,
string $workDir = null,
bool $portMapping = false,
Expand All @@ -119,7 +126,6 @@ function docker_compose_run(
$command = [
'run',
'--rm',
'-u', $user,
];

if ($noDeps) {
Expand Down Expand Up @@ -160,9 +166,10 @@ function docker_compose(array $subCommand, Context $c = null, bool $withBuilder
'PROJECT_DIRECTORY' => variable('project_directory'),
'PROJECT_ROOT_DOMAIN' => variable('root_domain'),
'PROJECT_DOMAINS' => $domains,
'USER_ID' => variable('user_id'),
'COMPOSER_CACHE_DIR' => variable('composer_cache_dir'),
'PHP_VERSION' => variable('php_version'),
], false)
])
;

$command = [
Expand Down
4 changes: 0 additions & 4 deletions .env.test

This file was deleted.

46 changes: 27 additions & 19 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,44 @@ on:
branches:
- master
pull_request:
branches:
- master

jobs:
cs-check:
name: Check Coding Standards
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Cache composer
uses: actions/cache@v2
with:
path: ~/.composer/cache/
key: composer-ubuntu-${{ github.sha }}
-
name: Checkout
uses: actions/checkout@v3

- name: Setup
-
name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
extensions: mbstring, fileinfo, json, intl, dom
tools: jolicode/castor

-
name: Build and start the infrastructure
run: castor start

-
name: Install quality tools
run: castor qa:install

-
name: Check coding standards
run: castor qa:cs --dry-run

- name: Run composer install
run: composer install -n --prefer-dist --no-interaction
- name: Lint Twig files
run: castor qa:twig-lint

- name: Check coding standards
run: php vendor/bin/php-cs-fixer fix --dry-run --diff
env:
PHP_CS_FIXER_IGNORE_ENV: 1
- name: Lint YAML files
run: castor qa:yaml-lint

- name: Lint Twig and yaml files
run: |
php bin/console lint:yaml config
php bin/console lint:twig templates
-
name: Run PHPStan
run: castor qa:phpstan
26 changes: 8 additions & 18 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# tools dependencies
tools/*/vendor/

###> symfony/framework-bundle ###
/.env.local
/.env.local.php
Expand All @@ -7,31 +10,18 @@
/var/
/vendor/
###< symfony/framework-bundle ###

###> symfony/phpunit-bridge ###
.phpunit
/phpunit.xml
###< symfony/phpunit-bridge ###

###> symfony/webpack-encore-bundle ###
/node_modules/
/public/build/
npm-debug.log
yarn-error.log
###< symfony/webpack-encore-bundle ###

###> friendsofphp/php-cs-fixer ###
/.php-cs-fixer.php
/.php-cs-fixer.cache
###< friendsofphp/php-cs-fixer ###

###> phpunit/phpunit ###
/phpunit.xml
.phpunit.result.cache
###< phpunit/phpunit ###

###> jolicode/docker-starter ###
/.castor.stub.php
/infrastructure/docker/docker-compose.override.yml
/infrastructure/docker/services/router/etc/ssl/certs/*.pem
/infrastructure/docker/services/router/certs/*.pem
###< jolicode/docker-starter ###
###> friendsofphp/php-cs-fixer ###
/.php-cs-fixer.php
/.php-cs-fixer.cache
###< friendsofphp/php-cs-fixer ###
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,13 @@ Type `castor` in the shell to have the list of available tasks.
Watch for changes:

```sh
$ castor app:watch
$ castor app:front:watch
```

#### CS fix

```sh
$ castor qa:install
$ castor qa:cs
```

Expand Down
19 changes: 0 additions & 19 deletions bin/phpunit

This file was deleted.

Loading

0 comments on commit 6737fdc

Please sign in to comment.