Skip to content

Commit

Permalink
chore: Switch to individual illuminate/* packages instead of `larav…
Browse files Browse the repository at this point in the history
…el/framework` (#141)

Closes: #117
  • Loading branch information
LastDragon-ru authored Mar 21, 2024
2 parents 44c2941 + ef9ae26 commit ce80ae2
Show file tree
Hide file tree
Showing 94 changed files with 994 additions and 420 deletions.
12 changes: 0 additions & 12 deletions .github/actions/php/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ inputs:
required: false
type: string
default: ""
tools:
description: "Should tools be installed via composer or not (default `true`)"
required: false
type: boolean
default: true

runs:
using: composite
Expand Down Expand Up @@ -54,13 +49,6 @@ runs:
with:
working-directory: ${{ inputs.working-directory }}

- name: Install tools
if: ${{ inputs.tools == 'true' || inputs.tools == 1 }} # https://github.com/actions/runner/issues/1483
shell: bash
working-directory: ${{ inputs.working-directory }}
run: |
composer bin all install
- name: Setup problem matchers
shell: bash
run: |
Expand Down
27 changes: 27 additions & 0 deletions .github/actions/tool/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: 'Install Tool'
description: 'Install Tool (requires PHP to be installed first)'

inputs:
tool:
description: "Tool to install."
required: true
type: string
working-directory:
description: "The directory where `composer.json` is located (default repository root)."
required: false
type: string
default: ""

runs:
using: composite
steps:
- name: Detect path
id: path
shell: bash
working-directory: ${{ inputs.working-directory }}
run: |
echo "value=$(jq '.extra."bamarni-bin"."target-directory" // "vendor-bin"' -r -c composer.json)" >> $GITHUB_OUTPUT
- name: Install
uses: ramsey/composer-install@v3
with:
working-directory: ${{ inputs.working-directory && inputs.working-directory || '.' }}/${{ steps.path.outputs.value }}/${{ inputs.tool }}
66 changes: 64 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,45 @@ jobs:
uses: actions/checkout@v4
- name: Install PHP
uses: ./.github/actions/php
with:
dependencies: false
- name: Prepare
run: |
# Unwanted
# (because will install whole "laravel/framework")
composer remove --no-interaction --no-progress --ansi --no-update "orchestra/testbench"
composer remove --no-interaction --no-progress --ansi --no-update --dev "orchestra/testbench"
- name: Install dependencies
uses: ramsey/composer-install@v3

- name: Install monorepo-builder
uses: ./.github/actions/tool
with:
tool: monorepo-builder
- name: Check package versions
run: |
composer run-script monorepo-builder
- name: Install composer-dependency-analyser
uses: ./.github/actions/tool
with:
tool: composer-dependency-analyser
- name: Check dependencies
run: |
composer run-script composer-dependency-analyser
- name: Install composer-require-checker
uses: ./.github/actions/tool
with:
tool: composer-require-checker
- name: Check packages
run: |
composer run-script composer-require-checker
- name: Install composer-unused
uses: ./.github/actions/tool
with:
tool: composer-unused
- name: Check unused packages
run: |
composer run-script composer-unused
Expand All @@ -55,26 +85,50 @@ jobs:
uses: actions/checkout@v4
- name: Install PHP
uses: ./.github/actions/php
- name: Composer repositories
with:
dependencies: false
- name: Prepare
shell: bash
working-directory: ${{ needs.settings.outputs.packages-directory }}/${{ matrix.package }}
run: |
# Unwanted
# (because will install whole "laravel/framework")
composer remove --no-interaction --no-progress --ansi --no-update "orchestra/testbench"
composer remove --no-interaction --no-progress --ansi --no-update --dev "orchestra/testbench"
# Repositories for packages
# (because we need local version of the packages)
PACKAGES=$(echo '${{ needs.settings.outputs.packages-names }}' | jq 'map(select(. != "${{ matrix.package }}"))' | jq -c -r '.[]' | tr -d '\r')
while IFS= read -r PKG
do
composer config "repositories.${PKG}" path "../${PKG}"
done <<< "${PACKAGES}"
- name: Install package dependencies
- name: Install dependencies
uses: ramsey/composer-install@v3
with:
working-directory: ${{ needs.settings.outputs.packages-directory }}/${{ matrix.package }}

- name: Install composer-dependency-analyser
uses: ./.github/actions/tool
with:
tool: composer-dependency-analyser
- name: Check dependencies
run: |
composer run-script composer-dependency-analyser -- --composer-json="${{ needs.settings.outputs.packages-directory }}/${{ matrix.package }}/composer.json"
- name: Install composer-require-checker
uses: ./.github/actions/tool
with:
tool: composer-require-checker
- name: Check packages
run: |
composer run-script composer-require-checker -- "${{ needs.settings.outputs.packages-directory }}/${{ matrix.package }}/composer.json"
- name: Install composer-unused
uses: ./.github/actions/tool
with:
tool: composer-unused
- name: Check unused packages
run: |
composer run-script composer-unused -- "${{ needs.settings.outputs.packages-directory }}/${{ matrix.package }}/composer.json"
Expand All @@ -87,6 +141,10 @@ jobs:
uses: actions/checkout@v4
- name: Install PHP
uses: ./.github/actions/php
- name: Install phpcs
uses: ./.github/actions/tool
with:
tool: phpcs
- name: Execute
run: |
composer run-script phpcs -- --report=checkstyle | cs2pr
Expand All @@ -99,6 +157,10 @@ jobs:
uses: actions/checkout@v4
- name: Install PHP
uses: ./.github/actions/php
- name: Install phpstan
uses: ./.github/actions/tool
with:
tool: phpstan
- name: Execute
run: |
composer run-script phpstan -- --error-format=checkstyle | cs2pr
Expand Down
16 changes: 10 additions & 6 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
php-versions: ${{ steps.settings.outputs.php-versions }}
dependencies: ${{ steps.settings.outputs.dependencies }}
laravel-versions: ${{ steps.settings.outputs.laravel-versions }}
laravel-packages: ${{ steps.settings.outputs.laravel-packages }}
optional-packages: ${{ steps.settings.outputs.optional-packages }}
steps:
- name: Checkout
Expand All @@ -48,7 +49,6 @@ jobs:
with:
working-directory: ${{ env.WORKING_DIRECTORY }}
dependencies: false
tools: false

- name: Collect Settings
id: settings
Expand All @@ -65,7 +65,8 @@ jobs:
echo "dependencies=$(echo "[\"$DEPS_HIGHEST\", \"$DEPS_LOCKED\", \"$DEPS_LOWEST\"]" | jq "[.[] | select(length > 0)]" -r -c)" >> $GITHUB_OUTPUT
# Laravel
echo "laravel-versions=$(jq '.require."laravel/framework" // "null" | split("|") | sort' -c composer.json)" >> $GITHUB_OUTPUT
echo "laravel-versions=$(jq '.require | to_entries | map(select( (.key | startswith("illuminate/")) or (.key == "laravel/framework "))) | map( .value | split("|") ) | flatten | unique | sort | if . == [] then ["null"] else . end' -c composer.json)" >> $GITHUB_OUTPUT
echo "laravel-packages=$(jq '.require + ."require-dev" | to_entries | map(select( (.key | startswith("illuminate/")) or (.key == "laravel/framework "))) | map( .key ) | flatten | unique | sort ' -c composer.json)" >> $GITHUB_OUTPUT
# Optional packages
echo "optional-packages=$(jq '([((."extra"."lara-asp"."ci"."optional-packages" // ["null"]) | flatten | unique | sort | join(","))] + ["null"]) | unique' -r -c composer.json)" >> $GITHUB_OUTPUT
Expand Down Expand Up @@ -112,7 +113,6 @@ jobs:
with:
version: ${{ matrix.php }}
dependencies: false
tools: false
working-directory: ${{ env.WORKING_DIRECTORY }}

# Required to resolve packages correctly.
Expand All @@ -135,9 +135,13 @@ jobs:
shell: bash
working-directory: ${{ env.WORKING_DIRECTORY }}
run: |
composer remove --no-interaction --no-progress --ansi --no-update laravel/framework
composer require --no-interaction --no-progress --ansi --no-update "laravel/framework:${{ matrix.laravel }}"
composer remove --no-interaction --no-progress --ansi --no-update --dev larastan/larastan
PACKAGES=$(echo '${{ needs.settings.outputs.laravel-packages }}' | jq -c -r '.[]' | tr -d '\r')
while IFS= read -r PKG
do
# It will move package to `require` section, not critical here
composer require --no-interaction --no-progress --ansi --no-update "${PKG}:${{ matrix.laravel }}"
done <<< "${PACKAGES}"
- name: Remove optional packages
if: ${{ matrix.optional != 'null' }}
Expand Down
16 changes: 8 additions & 8 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,14 @@ EOT
fi
SHELL

config.vm.provision "PHP 8.1", type: "shell", privileged: false, inline: <<-SHELL
config.vm.provision "PHP 8.3", type: "shell", privileged: false, inline: <<-SHELL
sudo add-apt-repository -y ppa:ondrej/php
sudo apt-get install -y php8.1-{cli,common,mbstring,bcmath,zip,intl,mbstring,xml,xdebug,curl,gd,imagick,ldap,pdo-sqlite}
sudo sed -i 's/^error_reporting = .\+$/error_reporting = E_ALL/' /etc/php/8.1/cli/php.ini
sudo sed -i 's/^display_errors = .\+$/display_errors = On/' /etc/php/8.1/cli/php.ini
sudo sed -i 's/^;opcache\.enable=.\+$/opcache.enable=1/' /etc/php/8.1/cli/php.ini
sudo sed -i 's/^;opcache\.enable_cli=.\+$/opcache.enable_cli=1/' /etc/php/8.1/cli/php.ini
sudo tee -a /etc/php/8.1/mods-available/xdebug.ini > /dev/null <<"EOT"
sudo apt-get install -y php8.3-{cli,common,mbstring,bcmath,zip,intl,mbstring,xml,xdebug,curl,pdo-sqlite}
sudo sed -i 's/^error_reporting = .\+$/error_reporting = E_ALL/' /etc/php/8.3/cli/php.ini
sudo sed -i 's/^display_errors = .\+$/display_errors = On/' /etc/php/8.3/cli/php.ini
sudo sed -i 's/^;opcache\.enable=.\+$/opcache.enable=1/' /etc/php/8.3/cli/php.ini
sudo sed -i 's/^;opcache\.enable_cli=.\+$/opcache.enable_cli=1/' /etc/php/8.3/cli/php.ini
sudo tee -a /etc/php/8.3/mods-available/xdebug.ini > /dev/null <<"EOT"
xdebug.output_dir = /project/.xdebug
xdebug.profiler_output_name = callgrind.out.%t.%r
xdebug.client_host = 10.0.2.2
Expand All @@ -172,7 +172,7 @@ EOT
config.vm.provision "composer install", type: "shell", privileged: false, inline: <<-SHELL
if test -f "/project/composer.json"; then
(cd /project && composer install)
(cs /project && composer bin all install)
(cd /project && composer bin all install)
fi
SHELL

Expand Down
96 changes: 63 additions & 33 deletions composer-dependency-analyser.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?php declare(strict_types = 1);

use LastDragon_ru\LaraASP\Dev\App\Example;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\RefreshDatabaseState;
use Illuminate\Foundation\Testing\TestCase;
use Orchestra\Testbench\TestCase as TestbenchTestCase;
use ShipMonk\ComposerDependencyAnalyser\CliOptions;
use ShipMonk\ComposerDependencyAnalyser\ComposerJson;
use ShipMonk\ComposerDependencyAnalyser\Config\Configuration;
Expand All @@ -16,59 +20,85 @@
// General
$config = (new Configuration())
->enableAnalysisOfUnusedDevDependencies()
->disableReportingUnmatchedIgnores()
->ignoreUnknownClasses([
Example::class,
])
->ignoreErrorsOnPackage('symfony/deprecation-contracts', [ErrorType::UNUSED_DEPENDENCY])
->ignoreErrorsOnPackage('symfony/polyfill-php83', [ErrorType::UNUSED_DEPENDENCY])
->ignoreErrorsOnPackage('symfony/var-dumper', [ErrorType::UNUSED_DEPENDENCY])
->ignoreErrorsOnPackage('bamarni/composer-bin-plugin', [ErrorType::UNUSED_DEPENDENCY])
->ignoreErrorsOnPackage('orchestra/testbench', [ErrorType::UNUSED_DEPENDENCY])
->ignoreErrorsOnPackage('orchestra/testbench-core', [ErrorType::SHADOW_DEPENDENCY])
->ignoreErrorsOnPackage('phpstan/phpstan', [ErrorType::SHADOW_DEPENDENCY])
->ignoreErrorsOnPackage('laravel/scout', [ErrorType::DEV_DEPENDENCY_IN_PROD]);
->ignoreErrorsOnPackage('laravel/scout', [ErrorType::DEV_DEPENDENCY_IN_PROD])
->ignoreUnknownClasses([
FormRequest::class,
RefreshDatabase::class,
RefreshDatabaseState::class,
TestCase::class,
TestbenchTestCase::class,
]);

// Load composer.json
$path = Path::resolve($this->cwd, ($options->composerJson ?? 'composer.json'));
$json = (string) file_get_contents($path);
$json = json_decode($json, true, JSON_THROW_ON_ERROR);
$root = Path::realpath(dirname(__FILE__).'/composer.json') === Path::realpath($path);

if (!$root) {
$config->disableReportingUnmatchedIgnores();
}

// Configure paths
//
// In our case, tests located inside the same directory with class and
// `exclude-from-classmap` is used to exclude them from the class map.
// So we need to mark these excluded files as "dev".
$path = Path::resolve($this->cwd, ($options->composerJson ?? 'composer.json'));
$json = (string) file_get_contents($path);
$json = json_decode($json, true, JSON_THROW_ON_ERROR);
//
// Also, we don't want to check examples. The `autoload-dev.exclude-from-classmap`
// can be used to ignore them.
$excluded = $json['autoload']['exclude-from-classmap'] ?? [];
$ignored = $json['autoload-dev']['exclude-from-classmap'] ?? [];

if ($excluded) {
$config = $config->disableComposerAutoloadPathScan();
$regexp = array_map(
static function (string $exclude) use ($path): string {
// Similar to how composer process it, but not the exact match.
$exclude = dirname($path)."/{$exclude}";
$exclude = preg_replace('{/+}', '/', preg_quote(trim(strtr($exclude, '\\', '/'), '/')));
$exclude = strtr($exclude, ['\\*\\*' => '.+?', '\\*' => '[^/]+?']);
if ($excluded || $ignored) {
$config = $config->disableComposerAutoloadPathScan();
$regexp = static function (array $excluded) use ($path): ?string {
$regexp = array_map(
static function (string $exclude) use ($path): string {
// Similar to how composer process it, but not the exact match.
$exclude = dirname($path)."/{$exclude}";
$exclude = preg_replace('{/+}', '/', preg_quote(trim(strtr($exclude, '\\', '/'), '/')));
$exclude = strtr($exclude, ['\\*\\*' => '.+?', '\\*' => '[^/]+?']);

return $exclude;
},
$excluded,
);
$regexp = '{('.implode(')|(', $regexp).')}';
return $exclude;
},
$excluded,
);
$regexp = $regexp
? '{('.implode(')|(', $regexp).')}'
: null;

foreach ($composerJson->autoloadPaths as $absolutePath => $isDevPath) {
if ($isDevPath) {
$config = $config->addPathToScan($absolutePath, $isDevPath);
} elseif (is_file($absolutePath)) {
$config = $config->addPathToScan($absolutePath, (bool) preg_match($regexp, $absolutePath));
return $regexp;
};
$ignored = $regexp($ignored);
$excluded = $regexp($excluded);
$processor = static function (string $path, bool $isDev) use (&$processor, $config, $excluded, $ignored): void {
if (is_file($path)) {
$isDev = $isDev || ($excluded && (bool) preg_match($excluded, $path));
$isIgnored = $isDev && ($ignored && (bool) preg_match($ignored, $path));

if (!$isIgnored) {
$config->addPathToScan($path, $isDev);
}
} else {
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($absolutePath));
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));

foreach ($iterator as $entry) {
if (!$entry->isFile() || !in_array($entry->getExtension(), $config->getFileExtensions(), true)) {
continue;
}

$entryPath = $entry->getPathname();
$config = $config->addPathToScan($entryPath, (bool) preg_match($regexp, $entryPath));
$processor($entry->getPathname(), $isDev);
}
}
};

foreach ($composerJson->autoloadPaths as $absolutePath => $isDevPath) {
$processor($absolutePath, $isDevPath);
}
}

Expand Down
6 changes: 5 additions & 1 deletion composer-require-checker.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"symbol-whitelist": [
"Composer\\InstalledVersions",
"Laravel\\Scout\\Builder"
"Laravel\\Scout\\Builder",
"Illuminate\\Foundation\\Http\\FormRequest",
"Illuminate\\Foundation\\Testing\\RefreshDatabase",
"Illuminate\\Foundation\\Testing\\RefreshDatabaseState",
"Illuminate\\Foundation\\Testing\\TestCase"
]
}
Loading

0 comments on commit ce80ae2

Please sign in to comment.