Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(update): Update scripts to Castor 0.18 #37

Merged
merged 1 commit into from
Sep 3, 2024
Merged
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
File renamed without changes.
11 changes: 5 additions & 6 deletions castor/github.php → .castor/github.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@
use Castor\Attribute\AsOption;
use Castor\Attribute\AsTask;

use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use function Castor\io;
use function Castor\run;
use const MonsieurBiz\SyliusSetup\Castor\SUGGESTED_PHP_VERSION;

const SUGGESTED_ENVS = ['staging', 'prod'];

#[AsTask(name: 'init', namespace: 'github:project', description: 'Init project configuration')]
function initGithubProjectConfig(
#[AsOption(description: 'Default branch name')] ?string $defaultBranch = 'develop',
#[AsOption(description: 'PHP Version', suggestedValues: [SUGGESTED_PHP_VERSION])] ?string $php = null,
#[AsOption(description: 'PHP Version', autocomplete: [SUGGESTED_PHP_VERSION])] ?string $php = null,
#[AsOption(description: 'Approving review count')] int $approvingReviewCount = 1,
#[AsOption(description: 'Autolink prefix, example: TICKET-')] ?string $autoLinkPrefix = null,
#[AsOption(description: 'Autolink url template, example: https://example.com/issues/<num>')] ?string $autoLinkUrlTemplate = null,
Expand All @@ -41,7 +40,7 @@ function initGithubProjectConfig(
}

// Create "develop" branch, push it and change default branch to "develop"
run(sprintf('git checkout -b %s', $defaultBranch), allowFailure: true, quiet: true); // Allow failure in case the branch already exists
run(sprintf('git checkout -b %s', $defaultBranch), quiet: true, allowFailure: true); // Allow failure in case the branch already exists
run(sprintf('git push -u origin %s', $defaultBranch), quiet: true);
$ghDefaultBranch = capture(sprintf('gh api --method PATCH -f default_branch=%s "/repos/%s" --jq .default_branch', $defaultBranch, $ghRepo));
if ($ghDefaultBranch !== $defaultBranch) {
Expand Down Expand Up @@ -71,7 +70,7 @@ function initGithubProjectConfig(

#[AsTask(name: 'init', namespace: 'github:env', description: 'Init environment (and variables if needed)')]
function initGithubEnv(
#[AsOption(description: 'Kind of environment', suggestedValues: SUGGESTED_ENVS)] ?string $environment = null,
#[AsOption(description: 'Kind of environment', autocomplete: SUGGESTED_ENVS)] ?string $environment = null,
#[AsOption(description: 'CLEVER_TOKEN value')] ?string $token = null,
#[AsOption(description: 'CLEVER_SECRET value')] ?string $secret = null,
#[AsOption(description: 'Setup the repository variables')] ?bool $setupEnvs = null,
Expand Down Expand Up @@ -112,7 +111,7 @@ function initGithubEnv(

#[AsTask(name: 'init', namespace: 'github:variables', description: 'Init repository variables')]
function initGithubVariables(
#[AsOption(description: 'Kind of environment', suggestedValues: SUGGESTED_ENVS)] ?string $environment = null,
#[AsOption(description: 'Kind of environment', autocomplete: SUGGESTED_ENVS)] ?string $environment = null,
#[AsOption(description: 'Production branch name')] ?string $branch = null,
#[AsOption(description: 'Production URL')] ?string $url = null,
): void {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2023 Monsieur Biz
Copyright 2023-present Monsieur Biz

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Then you can :
- Remove the `composer.lock` line in `apps/sylius/.gitignore` if you want to commit it.
- And code!

## Setup Github Repository
## Setup GitHub Repository

Simply run: `castor github:project:init`

Expand All @@ -35,7 +35,7 @@ Simply run: `castor clevercloud:setup` and follow the instructions.

Add a password for the HTTP auth using the `htpasswd` utility into `clevercloud/.htpasswd` file.

## Setup Github Environment
## Setup GitHub Environment

You'll need your credentials for Clever Cloud : `clever login` will help you get the required token and secret.

Expand All @@ -56,7 +56,7 @@ You can find some themes in [themes-examples/](themes-examples/themes/) and foll

### Which version of Sylius am I installing?

By default the `composer create-project` checks the platform you are working on.
By default, the `composer create-project` checks the platform you are working on.
We use `symfony` as a wrapper for PHP, this way you can change your PHP version in the `.php-version` file.
According to this composer will install the best version compatible with your computer.

Expand Down
41 changes: 21 additions & 20 deletions castor.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

use Castor\Attribute\AsOption;
use Castor\Attribute\AsTask;
use Castor\GlobalHelper;
use Symfony\Component\Console\Question\Question;

use function Castor\capture;
use function Castor\fs;
use function Castor\import;
use function Castor\io;
use function Castor\run;

import(__DIR__ . '/.castor/');

const DEFAULT_TIMEOUT_COMPOSER_PROCESS = 120;
const SUGGESTED_PHP_VERSION = '8.2';
const SUGGESTED_SYLIUS_VERSION = '1.12';
Expand All @@ -28,8 +29,8 @@ function reset(): void

#[AsTask(namespace: 'local', description: 'Init project')]
function setup(
#[AsOption(description: 'PHP Version', suggestedValues: [SUGGESTED_PHP_VERSION])] ?string $php = null,
#[AsOption(description: 'Sylius major version', suggestedValues: [SUGGESTED_SYLIUS_VERSION])] ?string $sylius = null,
#[AsOption(description: 'PHP Version', autocomplete: [SUGGESTED_PHP_VERSION])] ?string $php = null,
#[AsOption(description: 'Sylius major version', autocomplete: [SUGGESTED_SYLIUS_VERSION])] ?string $sylius = null,
): void {
# PHP Version
$phpVersion = $php ?? io()->ask('Which PHP do you want?', SUGGESTED_PHP_VERSION);
Expand Down Expand Up @@ -59,34 +60,34 @@ function setup(
run('symfony composer config --unset authors', path: 'apps/sylius/');
run('symfony composer config --unset keywords', path: 'apps/sylius/');
run('symfony composer config extra.symfony.allow-contrib true', path: 'apps/sylius/');
run('symfony composer require --no-scripts php="^' . $phpVersion . '"', path: 'apps/sylius/', timeout: DEFAULT_TIMEOUT_COMPOSER_PROCESS);
run('symfony composer require --no-scripts php="^' . $phpVersion . '"', timeout: DEFAULT_TIMEOUT_COMPOSER_PROCESS, path: 'apps/sylius/');

# Add scripts in composer.json
run('symfony composer config scripts.phpcs "php-cs-fixer fix --allow-risky=yes"', path: 'apps/sylius/');
run('symfony composer config scripts.phpmd "phpmd src/,plugins/ ansi phpmd.xml --exclude src/Migrations"', path: 'apps/sylius/');

# Allow plugins
run('symfony composer config allow-plugins.symfony/flex true', path: 'apps/sylius/', timeout: DEFAULT_TIMEOUT_COMPOSER_PROCESS);
run('symfony composer config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true', path: 'apps/sylius/', timeout: DEFAULT_TIMEOUT_COMPOSER_PROCESS);
run('symfony composer config allow-plugins.phpstan/extension-installer true', path: 'apps/sylius/', timeout: DEFAULT_TIMEOUT_COMPOSER_PROCESS);
run('symfony composer config allow-plugins.symfony/thanks true', path: 'apps/sylius/', timeout: DEFAULT_TIMEOUT_COMPOSER_PROCESS);
run('symfony composer config allow-plugins.symfony/runtime true', path: 'apps/sylius/', timeout: DEFAULT_TIMEOUT_COMPOSER_PROCESS);
run('symfony composer config allow-plugins.cweagans/composer-patches true', path: 'apps/sylius/', timeout: DEFAULT_TIMEOUT_COMPOSER_PROCESS);
run('symfony composer config allow-plugins.szeidler/composer-patches-cli true', path: 'apps/sylius/', timeout: DEFAULT_TIMEOUT_COMPOSER_PROCESS);
run('symfony composer config allow-plugins.symfony/flex true', timeout: DEFAULT_TIMEOUT_COMPOSER_PROCESS, path: 'apps/sylius/');
run('symfony composer config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true', timeout: DEFAULT_TIMEOUT_COMPOSER_PROCESS, path: 'apps/sylius/');
run('symfony composer config allow-plugins.phpstan/extension-installer true', timeout: DEFAULT_TIMEOUT_COMPOSER_PROCESS, path: 'apps/sylius/');
run('symfony composer config allow-plugins.symfony/thanks true', timeout: DEFAULT_TIMEOUT_COMPOSER_PROCESS, path: 'apps/sylius/');
run('symfony composer config allow-plugins.symfony/runtime true', timeout: DEFAULT_TIMEOUT_COMPOSER_PROCESS, path: 'apps/sylius/');
run('symfony composer config allow-plugins.cweagans/composer-patches true', timeout: DEFAULT_TIMEOUT_COMPOSER_PROCESS, path: 'apps/sylius/');
run('symfony composer config allow-plugins.szeidler/composer-patches-cli true', timeout: DEFAULT_TIMEOUT_COMPOSER_PROCESS, path: 'apps/sylius/');

# Add or update packages
run('symfony composer require --dev --no-scripts phpmd/phpmd="*"', path: 'apps/sylius/', timeout: DEFAULT_TIMEOUT_COMPOSER_PROCESS);
run('symfony composer require --dev --no-scripts phpunit/phpunit="^9.5" --with-all-dependencies', path: 'apps/sylius/', timeout: DEFAULT_TIMEOUT_COMPOSER_PROCESS);
run('symfony composer require --dev --no-scripts friendsofphp/php-cs-fixer', path: 'apps/sylius/', timeout: DEFAULT_TIMEOUT_COMPOSER_PROCESS);
run('symfony composer require --no-scripts cweagans/composer-patches', path: 'apps/sylius/', timeout: DEFAULT_TIMEOUT_COMPOSER_PROCESS);
run('symfony composer require --dev --no-scripts szeidler/composer-patches-cli', path: 'apps/sylius/', timeout: DEFAULT_TIMEOUT_COMPOSER_PROCESS);
run('symfony composer require --dev --no-scripts phpmd/phpmd="*"', timeout: DEFAULT_TIMEOUT_COMPOSER_PROCESS, path: 'apps/sylius/');
run('symfony composer require --dev --no-scripts phpunit/phpunit="^9.5" --with-all-dependencies', timeout: DEFAULT_TIMEOUT_COMPOSER_PROCESS, path: 'apps/sylius/');
run('symfony composer require --dev --no-scripts friendsofphp/php-cs-fixer', timeout: DEFAULT_TIMEOUT_COMPOSER_PROCESS, path: 'apps/sylius/');
run('symfony composer require --no-scripts cweagans/composer-patches', timeout: DEFAULT_TIMEOUT_COMPOSER_PROCESS, path: 'apps/sylius/');
run('symfony composer require --dev --no-scripts szeidler/composer-patches-cli', timeout: DEFAULT_TIMEOUT_COMPOSER_PROCESS, path: 'apps/sylius/');

# Fix for sylius and doctrine conflict
io()->info('Add conflict for doctrine/orm in order to fix an issue in Sylius.');
run("cat composer.json | jq --indent 4 '.conflict += {\"doctrine/orm\": \">= 2.15.2\"}' > composer.json.tmp", path: 'apps/sylius/');
run('mv composer.json.tmp composer.json', path: 'apps/sylius/');
io()->info('Run composer update after updating the composer.json file.');
run('symfony composer update', path: 'apps/sylius/', timeout: false);
run('symfony composer update', timeout: false, path: 'apps/sylius/');

# Copy dist files
run('cp -Rv dist/sylius/ apps/sylius'); // We have hidden files in dist/sylius
Expand All @@ -103,8 +104,8 @@ function setup(
fs()->appendToFile('apps/sylius/.gitignore', '/public/_themes' . PHP_EOL);

# We want to commit the composer.lock and yarn.lock
run('sed -i "" -e "/composer.lock/d" .gitignore', path: 'apps/sylius/', allowFailure: true);
run('sed -i "" -e "/yarn.lock/d" .gitignore', path: 'apps/sylius/', allowFailure: true);
run('sed -i "" -e "/composer.lock/d" .gitignore', allowFailure: true, path: 'apps/sylius/');
run('sed -i "" -e "/yarn.lock/d" .gitignore', allowFailure: true, path: 'apps/sylius/');

# install
run('make install', timeout: false);
Expand Down
1 change: 0 additions & 1 deletion infra/dev/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: "3"
services:
db:
image: "mysql:8"
Expand Down
2 changes: 1 addition & 1 deletion resources/makefiles/help.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
### ¯¯¯¯

help: SHELL=/bin/bash
help: ## Dislay this help
help: ## Display this help
@IFS=$$'\n'; for line in `grep -h -E '^[a-zA-Z_#-]+:?.*?##.*$$' $(MAKEFILE_LIST)`; do if [ "$${line:0:2}" = "##" ]; then \
echo $$line | awk 'BEGIN {FS = "## "}; {printf "\033[33m %s\033[0m\n", $$2}'; else \
echo $$line | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m%s\n", $$1, $$2}'; fi; \
Expand Down
4 changes: 2 additions & 2 deletions resources/makefiles/symfony.mk
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ symfony.server.log: ## Tail the logs
symfony.migration.generate: ## Generate migration file
$(call symfony.console, doctrine:migrations:diff --namespace="App\Migrations")

symfony.migration.execute: ## Excecute migration file
symfony.migration.execute: ## Execute migration file
$(call symfony.console, doctrine:migrations:execute ${ARGS})

symfony.migration.migrate: ## Excecute migration file
symfony.migration.migrate: ## Execute migration file
$(call symfony.console, doctrine:migrations:migrate)

symfony.messenger.setup: ## Setup the messenger transports (create messenger_message table)
Expand Down
Loading