Skip to content

Commit 3d3ef12

Browse files
committed
refactor: cleanup CI script
1 parent 22aebae commit 3d3ef12

2 files changed

Lines changed: 17 additions & 9 deletions

File tree

.github/scripts/continuous-integration

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@
1010
* the LICENSE file that was distributed with this source code.
1111
*/
1212

13-
require __DIR__ . '/../../vendor/codeigniter4/codeigniter4/system/Test/bootstrap.php';
13+
require __DIR__ . '/../../vendor/codeigniter4/codeigniter4/system/util_bootstrap.php';
1414

1515
use CodeIgniter\CLI\CLI;
1616
use Translations\Tests\AbstractTranslationTestCase;
1717

18-
if (! isset($argv[1])) {
18+
if (! isset($argv[1]) || ! is_string($argv[1])) {
1919
CLI::error('No GitHub Event provided.', 'light_gray', 'red');
2020

2121
exit(1);
2222
}
2323

24-
$event = (string) $argv[1];
24+
$event = $argv[1];
2525

2626
if (! in_array($event, ['--pull-request', '--push'], true)) {
2727
CLI::error('Invalid GitHub Event provided.', 'light_gray', 'red');
@@ -35,8 +35,14 @@ if ($event === '--pull-request') {
3535
$files = shell_exec('git diff --name-only --diff-filter=ACMRTUXB HEAD~..HEAD');
3636
}
3737

38-
$isCIAffected = str_contains((string) $files, '.github/scripts/continuous-integration');
39-
$isBuildAffected = str_contains((string) $files, '.github/workflows/build.yml');
38+
if (! is_string($files)) {
39+
CLI::error('Unable to retrieve the list of changed files.', 'light_gray', 'red');
40+
41+
exit(1);
42+
}
43+
44+
$isCIAffected = str_contains($files, '.github/scripts/continuous-integration');
45+
$isBuildAffected = str_contains($files, '.github/workflows/build.yml');
4046
$isTestAffected = preg_match('/tests\/Language\/(.+)Test(?:|Case)\.php/', $files) === 1;
4147

4248
$files = str_replace(["\r\n", "\r"], "\n", $files);
@@ -66,7 +72,7 @@ $failed = [];
6672

6773
$phpunit = 'vendor/bin/phpunit';
6874

69-
if (CLI::isWindows()) {
75+
if (is_windows()) {
7076
$phpunit = strtr($phpunit, '/', '\\');
7177
}
7278

@@ -87,14 +93,14 @@ if ($count > 0 && $count < count(AbstractTranslationTestCase::$locales)) {
8793
foreach ($locales as $locale) {
8894
$class = array_search($locale, AbstractTranslationTestCase::$locales, true);
8995

90-
if ($class === false) {
96+
if (! is_string($class)) {
9197
CLI::error(sprintf('The locale "%s" has no corresponding test case yet.', $locale), 'light_gray', 'red');
9298
CLI::error('You can read on the Contributing Guide for details on adding test cases.', 'light_gray', 'red');
9399

94100
exit(1);
95101
}
96102

97-
$class = preg_replace('/^Translations\\\\Tests\\\\(.+)$/u', '$1', (string) $class);
103+
$class = preg_replace('/^Translations\\\\Tests\\\\(.+)$/u', '$1', $class);
98104

99105
CLI::write("Executing vendor/bin/phpunit --color=always --filter {$class}\n", 'black', 'yellow');
100106
passthru("{$phpunit} --color=always --filter {$class}", $return);
@@ -137,7 +143,7 @@ if ($count > 0 && $count < count(AbstractTranslationTestCase::$locales)) {
137143

138144
foreach ($reasons as [$reason, $explanation]) {
139145
if ($reason) {
140-
CLI::write('Reason: ' . $explanation . "\n", 'black', 'yellow');
146+
CLI::write("Reason: {$explanation}\n", 'black', 'yellow');
141147
break;
142148
}
143149
}

.github/workflows/build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ on:
99
paths:
1010
- Language/**
1111
- tests/Language/**
12+
- .github/scripts/continuous-integration
1213
- .github/workflows/build.yml
1314
pull_request:
1415
branches:
1516
- develop
1617
paths:
1718
- Language/**
1819
- tests/Language/**
20+
- .github/scripts/continuous-integration
1921
- .github/workflows/build.yml
2022

2123
permissions:

0 commit comments

Comments
 (0)