Skip to content

Commit 1741c85

Browse files
committed
minor #1 Add link command (Nyholm)
This PR was squashed before being merged into the main branch. Discussion ---------- Add link command | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | Docs? | no | Issues | | License | MIT This PR will also include fixes to make the CI green Commits ------- e8b3949 Add link command
2 parents 64a4b60 + e8b3949 commit 1741c85

File tree

4 files changed

+95
-7
lines changed

4 files changed

+95
-7
lines changed

.github/workflows/.utils.sh

100644100755
File mode changed.

.github/workflows/code-quality.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@ jobs:
3232
strategy:
3333
fail-fast: false
3434
matrix:
35-
php-version: [ '8.1', '8.2', '8.3', '8.4']
35+
php-version: [ '8.2', '8.3', '8.4']
3636
dependency-version: ['']
3737
symfony-version: ['']
3838
minimum-stability: ['stable']
3939
include:
4040
# lowest deps
41-
- php-version: '8.1'
41+
- php-version: '8.2'
4242
dependency-version: 'lowest'
4343
# LTS version of Symfony
44-
- php-version: '8.1'
44+
- php-version: '8.2'
4545
symfony-version: '6.4.*'
4646
steps:
4747
- name: Checkout
@@ -55,13 +55,14 @@ jobs:
5555
echo COMPOSER_VALIDATE='composer validate --strict' >> $GITHUB_ENV
5656
echo PHPSTAN='vendor/bin/phpstan' >> $GITHUB_ENV
5757
58+
PACKAGES=$(find src/ -mindepth 2 -type f -name composer.json -not -path "*/vendor/*" -printf '%h\n' | sed 's/^src\///' | grep -Ev "examples" | sort | tr '\n' ' ')
5859
echo "Packages: $PACKAGES"
5960
echo "PACKAGES=$PACKAGES" >> $GITHUB_ENV
6061
6162
- name: Setup PHP
6263
uses: shivammathur/setup-php@v2
6364
with:
64-
php-version: '8.1'
65+
php-version: '8.2'
6566
tools: flex
6667

6768
- name: Install root dependencies

.github/workflows/unit-tests.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
strategy:
2121
fail-fast: false
2222
matrix:
23-
php-version: ['8.1', '8.2', '8.3', '8.4']
23+
php-version: ['8.2', '8.3', '8.4']
2424
dependency-version: ['']
2525
symfony-version: ['']
2626
minimum-stability: ['stable']
@@ -29,10 +29,10 @@ jobs:
2929
- minimum-stability: 'dev'
3030
php-version: '8.4'
3131
# lowest deps
32-
- php-version: '8.1'
32+
- php-version: '8.2'
3333
dependency-version: 'lowest'
3434
# LTS version of Symfony
35-
- php-version: '8.1'
35+
- php-version: '8.2'
3636
symfony-version: '6.4.*'
3737

3838
env:
@@ -48,6 +48,7 @@ jobs:
4848
echo PHPUNIT='vendor/bin/phpunit' >> $GITHUB_ENV
4949
[ 'lowest' = '${{ matrix.dependency-version }}' ] && export SYMFONY_DEPRECATIONS_HELPER=weak
5050
51+
PACKAGES=$(find src/ -mindepth 2 -type f -name composer.json -not -path "*/vendor/*" -printf '%h\n' | sed 's/^src\///' | grep -Ev "examples" | sort | tr '\n' ' ')
5152
echo "Packages: $PACKAGES"
5253
echo "PACKAGES=$PACKAGES" >> $GITHUB_ENV
5354

link

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
/*
5+
* This file is part of the Symfony package.
6+
*
7+
* (c) Fabien Potencier <[email protected]>
8+
*
9+
* For the full copyright and license information, please view the LICENSE
10+
* file that was distributed with this source code.
11+
*/
12+
13+
require __DIR__.'/vendor/autoload.php';
14+
15+
use Symfony\Component\Filesystem\Filesystem;
16+
17+
/**
18+
* Links dependencies of a project to a local clone of the main symfony/symfony GitHub repository.
19+
*
20+
* @author Kévin Dunglas <[email protected]>
21+
*/
22+
23+
$copy = false !== $k = array_search('--copy', $argv, true);
24+
$copy && array_splice($argv, $k, 1);
25+
$rollback = false !== $k = array_search('--rollback', $argv, true);
26+
$rollback && array_splice($argv, $k, 1);
27+
$pathToProject = $argv[1] ?? getcwd();
28+
29+
if (!is_dir("$pathToProject/vendor/symfony")) {
30+
echo 'Links dependencies of a project to a local clone of the main symfony/ai GitHub repository.'.PHP_EOL.PHP_EOL;
31+
echo "Usage: $argv[0] /path/to/the/project".PHP_EOL;
32+
echo ' Use `--copy` to copy dependencies instead of symlink'.PHP_EOL.PHP_EOL;
33+
echo ' Use `--rollback` to rollback'.PHP_EOL.PHP_EOL;
34+
echo "The directory \"$pathToProject\" does not exist or the dependencies are not installed, did you forget to run \"composer install\" in your project?".PHP_EOL;
35+
exit(1);
36+
}
37+
38+
$sfPackages = array();
39+
40+
$filesystem = new Filesystem();
41+
$directories = glob(__DIR__.'/src/*', GLOB_ONLYDIR | GLOB_NOSORT);
42+
43+
foreach ($directories as $dir) {
44+
if ($filesystem->exists($composer = "$dir/composer.json")) {
45+
$sfPackages[json_decode(file_get_contents($composer))->name] = $dir;
46+
}
47+
}
48+
49+
foreach (glob("$pathToProject/vendor/symfony/*", GLOB_ONLYDIR | GLOB_NOSORT) as $dir) {
50+
$package = 'symfony/'.basename($dir);
51+
52+
if (!isset($sfPackages[$package])) {
53+
continue;
54+
}
55+
56+
if ($rollback) {
57+
$filesystem->remove($dir);
58+
echo "\"$package\" has been rollback from \"$sfPackages[$package]\".".PHP_EOL;
59+
continue;
60+
}
61+
62+
if (!$copy && is_link($dir)) {
63+
echo "\"$package\" is already a symlink, skipping.".PHP_EOL;
64+
continue;
65+
}
66+
67+
$sfDir = ('\\' === DIRECTORY_SEPARATOR || $copy) ? $sfPackages[$package] : $filesystem->makePathRelative($sfPackages[$package], dirname(realpath($dir)));
68+
69+
$filesystem->remove($dir);
70+
71+
if ($copy) {
72+
$filesystem->mirror($sfDir, $dir);
73+
echo "\"$package\" has been copied from \"$sfPackages[$package]\".".PHP_EOL;
74+
} else {
75+
$filesystem->symlink($sfDir, $dir);
76+
echo "\"$package\" has been linked to \"$sfPackages[$package]\".".PHP_EOL;
77+
}
78+
}
79+
80+
foreach (glob("$pathToProject/var/cache/*", GLOB_NOSORT) as $cacheDir) {
81+
$filesystem->remove($cacheDir);
82+
}
83+
84+
if ($rollback) {
85+
echo PHP_EOL."Rollback done, do not forget to run \"composer install\" in your project \"$pathToProject\".".PHP_EOL;
86+
}

0 commit comments

Comments
 (0)