Skip to content

Commit 6b4c51d

Browse files
committed
Replace the nightly build cron with an upstream language baseline check
1 parent e2afbf9 commit 6b4c51d

11 files changed

Lines changed: 780 additions & 13 deletions

File tree

.github/scripts/continuous-integration

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,23 @@ if (! in_array($event, ['--pull-request', '--push'], true)) {
3131
exit(1);
3232
}
3333

34-
$files = shell_exec($event === '--pull-request'
34+
$command = $event === '--pull-request'
3535
? 'git diff --name-only --diff-filter=ACMRTUXB origin/develop..HEAD'
36-
: 'git diff --name-only --diff-filter=ACMRTUXB HEAD~..HEAD');
36+
: 'git diff --name-only --diff-filter=ACMRTUXB HEAD~..HEAD';
3737

38-
if (! is_string($files)) {
39-
CLI::error('Unable to retrieve the list of changed files.', 'light_gray', 'red');
38+
$output = [];
39+
$resultCode = 0;
40+
41+
exec($command, $output, $resultCode);
42+
43+
if ($resultCode !== 0) {
44+
CLI::error(sprintf('Unable to retrieve the list of changed files. "%s" exited with code %d.', $command, $resultCode), 'light_gray', 'red');
4045

4146
exit(1);
4247
}
4348

49+
$files = implode("\n", $output);
50+
4451
$isCIAffected = str_contains($files, '.github/scripts/continuous-integration');
4552
$isBuildAffected = str_contains($files, '.github/workflows/build.yml');
4653
$isTestAffected = preg_match('/tests\/Language\/(.+)Test(?:|Case)\.php/', $files) === 1;
@@ -78,10 +85,11 @@ if ($count === 0 && ! ($isCIAffected || $isBuildAffected || $isTestAffected)) {
7885
exit(0);
7986
}
8087

88+
$returns = 0;
89+
8190
// Check this first to account for new ICU locale additions
8291
if ($count > 0 && $count < count(AbstractTranslationTestCase::$locales)) {
83-
$returns = 0;
84-
$return = 0;
92+
$return = 0;
8593

8694
foreach ($locales as $locale) {
8795
$class = array_search($locale, AbstractTranslationTestCase::$locales, true);
@@ -109,7 +117,6 @@ if ($count > 0 && $count < count(AbstractTranslationTestCase::$locales)) {
109117
} elseif ($count === count(AbstractTranslationTestCase::$locales) || $isCIAffected || $isBuildAffected || $isTestAffected) {
110118
$count = count(AbstractTranslationTestCase::$locales);
111119
ob_start();
112-
$returns = 0;
113120

114121
CLI::write('Testing all language files in all locales.', 'black', 'yellow');
115122

@@ -124,7 +131,7 @@ if ($count > 0 && $count < count(AbstractTranslationTestCase::$locales)) {
124131
CLI::write(sprintf("Reason: %s\n", $reasonMessage), 'black', 'yellow');
125132
}
126133

127-
passthru("{$phpunit} --color=always --exclude-group=auto-review", $returns);
134+
passthru("{$phpunit} --color=always --exclude-group=auto-review --exclude-group=upstream", $returns);
128135

129136
$result = ob_get_clean();
130137
$failed = [];

.github/workflows/build.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
name: build
22

33
on:
4-
schedule:
5-
- cron: '0 0 * * *'
64
push:
75
branches:
86
- develop
@@ -48,7 +46,7 @@ jobs:
4846

4947
- name: Checkout other refs
5048
run: |
51-
git fetch --no-tags --prune --depth=2 origin +refs/heads/*:refs/remotes/origin/*
49+
git fetch --no-tags --prune origin +refs/heads/*:refs/remotes/origin/*
5250
5351
- name: Setup PHP
5452
uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 # 2.37.2

.github/workflows/upstream.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: upstream
2+
3+
on:
4+
schedule:
5+
- cron: '0 3 * * *'
6+
push:
7+
branches:
8+
- develop
9+
paths:
10+
- tests/Upstream/**
11+
- .github/workflows/upstream.yml
12+
pull_request:
13+
branches:
14+
- develop
15+
paths:
16+
- tests/Upstream/**
17+
- .github/workflows/upstream.yml
18+
workflow_dispatch:
19+
20+
permissions:
21+
contents: read
22+
23+
concurrency:
24+
group: upstream-${{ github.ref }}
25+
cancel-in-progress: true
26+
27+
jobs:
28+
baseline:
29+
name: Upstream Language Baseline [PHP ${{ matrix.php-version }}]
30+
runs-on: ubuntu-24.04
31+
if: github.repository == 'codeigniter4/translations'
32+
timeout-minutes: 15
33+
34+
strategy:
35+
fail-fast: false
36+
# Run only on the highest supported PHP version to reduce API load
37+
matrix:
38+
php-version: ['8.5']
39+
40+
steps:
41+
- name: Checkout code
42+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
43+
with:
44+
persist-credentials: false
45+
46+
- name: Setup PHP
47+
uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # 2.37.0
48+
with:
49+
php-version: ${{ matrix.php-version }}
50+
extensions: intl, mbstring
51+
coverage: none
52+
env:
53+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
54+
55+
- name: Get composer cache directory
56+
id: composer-cache
57+
run: echo "COMPOSER_CACHE_FILES_DIR=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
58+
59+
- name: Cache composer dependencies
60+
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
61+
with:
62+
path: ${{ steps.composer-cache.outputs.COMPOSER_CACHE_FILES_DIR }}
63+
key: composer-PHP_${{ matrix.php-version }}-${{ hashFiles('**/composer.json') }}
64+
restore-keys: composer-PHP_${{ matrix.php-version }}-
65+
66+
- name: Install dependencies
67+
run: composer update --ansi
68+
env:
69+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
70+
71+
- name: Run Upstream Test Suite
72+
run: vendor/bin/phpunit --color=always --group=upstream

.php-cs-fixer.dist.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
'bin/generate-page',
2727
'bin/test',
2828
'bin/update-en-comments',
29+
'bin/update-upstream-baseline',
2930
]);
3031

3132
$overrides = [

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
[![build](https://github.com/codeigniter4/translations/actions/workflows/build.yml/badge.svg)](https://github.com/codeigniter4/translations/actions/workflows/build.yml)
44
[![code style](https://github.com/codeigniter4/translations/actions/workflows/code-style.yml/badge.svg)](https://github.com/codeigniter4/translations/actions/workflows/code-style.yml)
5+
[![upstream](https://github.com/codeigniter4/translations/actions/workflows/upstream.yml/badge.svg)](https://github.com/codeigniter4/translations/actions/workflows/upstream.yml)
56
[![Latest Stable Version](https://poser.pugx.org/codeigniter4/translations/v)](//packagist.org/packages/codeigniter4/translations)
67
[![Total Downloads](https://poser.pugx.org/codeigniter4/translations/downloads)](//packagist.org/packages/codeigniter4/translations)
78
[![License](https://poser.pugx.org/codeigniter4/translations/license)](//packagist.org/packages/codeigniter4/translations)

bin/test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ CLI::write(
7272
'light_gray',
7373
'red',
7474
);
75-
exec($phpunit, $output, $resultCode);
75+
exec("{$phpunit} --exclude-group=upstream", $output, $resultCode);
7676

7777
$untranslatedLocales = [];
7878

bin/update-upstream-baseline

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
declare(strict_types=1);
5+
6+
/**
7+
* This file is part of CodeIgniter 4 framework.
8+
*
9+
* (c) CodeIgniter Foundation <admin@codeigniter.com>
10+
*
11+
* For the full copyright and license information, please view
12+
* the LICENSE file that was distributed with this source code.
13+
*/
14+
15+
require __DIR__ . '/../vendor/codeigniter4/codeigniter4/system/util_bootstrap.php';
16+
17+
use CodeIgniter\CLI\CLI;
18+
19+
helper(['array', 'filesystem']);
20+
21+
$enDir = __DIR__ . '/../vendor/codeigniter4/codeigniter4/system/Language/en/';
22+
23+
if (! is_dir($enDir)) {
24+
CLI::error('No "Language/en" directory. Please run "composer update".', 'light_gray', 'red');
25+
26+
exit(1);
27+
}
28+
29+
$baseline = [];
30+
31+
foreach (directory_map($enDir, 1) as $file) {
32+
$baseline[$file] = array_keys(array_flatten_with_dots(require $enDir . $file));
33+
}
34+
35+
ksort($baseline);
36+
37+
$entries = '';
38+
39+
foreach ($baseline as $file => $keys) {
40+
$entries .= sprintf(" '%s' => [\n", $file);
41+
42+
foreach ($keys as $key) {
43+
$entries .= sprintf(" '%s',\n", $key);
44+
}
45+
46+
$entries .= " ],\n";
47+
}
48+
49+
$baselineFile = __DIR__ . '/../tests/Upstream/baseline.php';
50+
51+
$contents = <<<PHP
52+
<?php
53+
54+
declare(strict_types=1);
55+
56+
/**
57+
* This file is part of CodeIgniter 4 framework.
58+
*
59+
* (c) CodeIgniter Foundation <admin@codeigniter.com>
60+
*
61+
* For the full copyright and license information, please view
62+
* the LICENSE file that was distributed with this source code.
63+
*/
64+
65+
// @auto-generated by "php bin/update-upstream-baseline". Do not edit by hand.
66+
return [
67+
{$entries}];
68+
69+
PHP;
70+
71+
if (file_put_contents($baselineFile, $contents) === false) {
72+
CLI::error(sprintf('Failed to write the baseline to "%s".', $baselineFile), 'light_gray', 'red');
73+
74+
exit(1);
75+
}
76+
77+
$phpCsFixer = 'vendor/bin/php-cs-fixer';
78+
79+
if (is_windows()) {
80+
$phpCsFixer = strtr($phpCsFixer, '/', '\\');
81+
}
82+
83+
passthru(sprintf('%s fix --quiet tests/Upstream/baseline.php', $phpCsFixer));
84+
85+
CLI::write(sprintf(
86+
'Recorded %d language keys across %d files.',
87+
array_sum(array_map(static fn (array $keys): int => count($keys), $baseline)),
88+
count($baseline),
89+
), 'black', 'green');

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
"autoload-dev": {
3737
"psr-4": {
3838
"Translations\\Tests\\": "tests/Language/",
39-
"Translations\\Tests\\AutoReview\\": "tests/AutoReview"
39+
"Translations\\Tests\\AutoReview\\": "tests/AutoReview",
40+
"Translations\\Tests\\Upstream\\": "tests/Upstream"
4041
}
4142
},
4243
"config": {

phpunit.dist.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
<testsuite name="Language Test Suite">
1919
<directory suffix="Test.php">tests/Language</directory>
2020
</testsuite>
21+
<testsuite name="Upstream Test Suite">
22+
<directory suffix="Test.php">tests/Upstream</directory>
23+
</testsuite>
2124
</testsuites>
2225

2326
<source ignoreIndirectDeprecations="true" restrictNotices="true" restrictWarnings="true">

0 commit comments

Comments
 (0)