Skip to content

Commit 2ec30b1

Browse files
feat: add standalone PHAR distribution (#157)
* refactor: extract translation-validation command behavior into a shared trait * feat: add standalone PHAR distribution * refactor: simplify standalone command wiring and dedupe test setup * fix: disable credential persistence on PHAR workflow checkout
1 parent 125d787 commit 2ec30b1

12 files changed

Lines changed: 525 additions & 235 deletions

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
/.gitattributes export-ignore
1010
/.gitignore export-ignore
1111
/.php-cs-fixer.php export-ignore
12+
/box.json export-ignore
1213
/codecov.yml export-ignore
1314
/composer.lock export-ignore
1415
/Dockerfile export-ignore

.github/workflows/phar.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: PHAR
2+
on:
3+
push:
4+
tags:
5+
- '*'
6+
pull_request:
7+
branches:
8+
- '**'
9+
workflow_dispatch:
10+
11+
permissions:
12+
contents: write
13+
14+
jobs:
15+
phar:
16+
runs-on: ubuntu-latest
17+
name: Build PHAR
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v7
21+
with:
22+
fetch-depth: 0
23+
persist-credentials: false
24+
25+
- name: Setup PHP
26+
uses: shivammathur/setup-php@v2
27+
with:
28+
php-version: '8.4'
29+
extensions: libxml, mbstring, simplexml, dom, intl
30+
tools: composer, box
31+
32+
- name: Install Composer dependencies (production only)
33+
run: composer install --no-dev --no-interaction --no-progress
34+
35+
- name: Compile PHAR
36+
run: box compile --no-interaction
37+
38+
- name: Smoke test (valid files -> exit 0)
39+
run: php composer-translation-validator.phar tests/src/Fixtures/translations/xliff/success
40+
41+
- name: Smoke test (invalid files -> exit 1)
42+
run: |
43+
set +e
44+
php composer-translation-validator.phar tests/src/Fixtures/translations/xliff/fail
45+
code=$?
46+
set -e
47+
if [ "$code" -ne 1 ]; then
48+
echo "Expected exit code 1 for invalid fixtures, got $code" >&2
49+
exit 1
50+
fi
51+
52+
- name: Generate checksum
53+
if: startsWith(github.ref, 'refs/tags/')
54+
run: sha256sum composer-translation-validator.phar > composer-translation-validator.phar.sha256
55+
56+
- name: Attach PHAR to release
57+
if: startsWith(github.ref, 'refs/tags/')
58+
uses: softprops/action-gh-release@v2
59+
with:
60+
files: |
61+
composer-translation-validator.phar
62+
composer-translation-validator.phar.sha256

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
/tests/composer.lock
1111
/tests/vendor
1212

13+
# PHAR build artifacts
14+
/*.phar
15+
1316
# Node.js / VitePress
1417
node_modules/
1518
docs/.vitepress/cache/

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
- feat: provide a standalone PHAR distribution for CI and non-Composer projects
11+
1012
## [1.5.0] - 2026-06-29
1113

1214
- feat: add target-language consistency check for XLIFF files (filename locale vs. declared target-language)

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ Supports XLIFF, YAML, JSON and PHP translation files.
3232
composer require --dev move-elevator/composer-translation-validator
3333
```
3434

35+
Alternatively, a dependency-free [standalone PHAR](https://move-elevator.github.io/composer-translation-validator/getting-started/installation#standalone-phar) is available for CI or non-Composer projects.
36+
3537
## 📊 Usage
3638

3739
Validate your translation files by running the command:

bin/composer-translation-validator

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
declare(strict_types=1);
5+
6+
/*
7+
* This file is part of the "composer-translation-validator" Composer plugin.
8+
*
9+
* (c) 2025-2026 Konrad Michalik <km@move-elevator.de>
10+
*
11+
* For the full copyright and license information, please view the LICENSE
12+
* file that was distributed with this source code.
13+
*/
14+
15+
use MoveElevator\ComposerTranslationValidator\Command\StandaloneValidateTranslationCommand;
16+
use Symfony\Component\Console\Application;
17+
18+
(static function (): void {
19+
$autoloads = [
20+
__DIR__.'/../vendor/autoload.php', // running from source / inside the PHAR
21+
__DIR__.'/../../../autoload.php', // installed as a dependency
22+
];
23+
24+
foreach ($autoloads as $autoload) {
25+
if (is_file($autoload)) {
26+
require $autoload;
27+
28+
return;
29+
}
30+
}
31+
32+
fwrite(\STDERR, 'Composer autoloader not found. Run "composer install".'.\PHP_EOL);
33+
exit(1);
34+
})();
35+
36+
// Replaced with the git tag by Box at compile time; stays literal when run from
37+
// source. The '@' check must not reference the placeholder string itself,
38+
// otherwise Box would replace it here too.
39+
$version = '@git_version@';
40+
if (str_contains($version, '@')) {
41+
$version = 'dev';
42+
}
43+
44+
$application = new Application('composer-translation-validator', $version);
45+
// The PHAR bundles the Symfony version pinned in composer.lock (>= 8), where
46+
// Application::addCommand() replaced the removed add().
47+
$application->addCommand(new StandaloneValidateTranslationCommand());
48+
$application->setDefaultCommand('validate-translations', true);
49+
50+
exit($application->run());

box.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/box-project/box/main/res/schema.json",
3+
"main": "bin/composer-translation-validator",
4+
"output": "composer-translation-validator.phar",
5+
"compression": "GZ",
6+
"git": "git_version",
7+
"check-requirements": true,
8+
"exclude-dev-files": true,
9+
"blacklist": [
10+
"src/Plugin.php",
11+
"src/Capability/ValidateTranslationCommandProvider.php"
12+
]
13+
}

docs/getting-started/installation.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,34 @@ composer require --dev move-elevator/composer-translation-validator
1515

1616
The plugin will be automatically registered with Composer and the `validate-translations` command becomes available.
1717

18+
This is the recommended way to use the tool inside a Composer/PHP project.
19+
20+
## Standalone PHAR
21+
22+
For CI pipelines or non-Composer projects, a standalone PHAR is available. It runs as its own process with all dependencies bundled, so it never conflicts with your project's dependencies.
23+
24+
Download the latest PHAR (and its checksum) from the [GitHub releases page](https://github.com/move-elevator/composer-translation-validator/releases):
25+
26+
```bash
27+
curl -L -o composer-translation-validator.phar \
28+
https://github.com/move-elevator/composer-translation-validator/releases/latest/download/composer-translation-validator.phar
29+
curl -L -o composer-translation-validator.phar.sha256 \
30+
https://github.com/move-elevator/composer-translation-validator/releases/latest/download/composer-translation-validator.phar.sha256
31+
32+
# Verify the download
33+
sha256sum -c composer-translation-validator.phar.sha256
34+
35+
chmod +x composer-translation-validator.phar
36+
```
37+
38+
Run it directly against your translation folders:
39+
40+
```bash
41+
./composer-translation-validator.phar ./translations --recursive
42+
```
43+
44+
The PHAR accepts the same arguments and options as the `validate-translations` command.
45+
1846
## Verify Installation
1947

2048
Check that the command is available:
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the "composer-translation-validator" Composer plugin.
7+
*
8+
* (c) 2025-2026 Konrad Michalik <km@move-elevator.de>
9+
*
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
12+
*/
13+
14+
namespace MoveElevator\ComposerTranslationValidator\Command;
15+
16+
use Symfony\Component\Console\Command\Command;
17+
18+
/**
19+
* StandaloneValidateTranslationCommand.
20+
*
21+
* @author Konrad Michalik <km@move-elevator.de>
22+
* @license GPL-3.0-or-later
23+
*/
24+
class StandaloneValidateTranslationCommand extends Command
25+
{
26+
use TranslationValidationBehavior;
27+
}

0 commit comments

Comments
 (0)