Commit d13d90b2 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Script de création du fichier (de config) de version

parent f01bc508
Loading
Loading
Loading
Loading

bin/bump-version

deleted100755 → 0
+0 −61
Original line number Diff line number Diff line
#!/usr/bin/env php
<?php

/**
 * Script à utiliser pour mettre à jour la version courante de l'application,
 * configurée dans 'config/autoload/version.global.php'.
 *
 * Usage:  bump-version [<version>]
 *
 * Ex:     bump-version 1.3
 */

require __DIR__ . '/../vendor/autoload.php';

use Zend\Config\Writer\PhpArray;

$defaultConfig = [
    'unicaen-app' => [
        'app_infos' => [
            'version' => 'Aucune',
        ],
    ]
];

$configFilepath = 'config/autoload/version.global.php';
echo "Fichier de config: $configFilepath" . PHP_EOL;

if (!is_readable($configFilepath)) {
    echo "Fichier de config $configFilepath introuvable ou illisible." . PHP_EOL;
    exit(1);
}

$config = require $configFilepath;

if (! isset($config['unicaen-app']['app_infos']['version'])) {
    $config = array_merge_recursive($config, $defaultConfig);
}
$current = $config['unicaen-app']['app_infos']['version'];
echo sprintf("Version actuelle: %s.", $current) . PHP_EOL;

$new = isset($argv[1]) ? $argv[1] : null;
if ($new === null) {
    $message = "Nouvelle version ? ";
    $new = readline($message);
}

if (version_compare($new, $current) <= 0) {
    echo ":-( Impossible, la nouvelle version doit être supérieure à l'actuelle." . PHP_EOL;
    exit(1);
}

$config['unicaen-app']['app_infos']['version'] = $new;
$config['unicaen-app']['app_infos']['date'] = date('d/m/Y');
$config['comment'] = "Fichier généré le " . date('d/m/Y à H:i:s') . ' avec ' . __FILE__;

$phpArray = new PhpArray();
$phpArray
    ->setUseBracketArraySyntax(true)
    ->toFile($configFilepath, $config);

echo "Nouvelle version inscrite: $new" . PHP_EOL;
+58 −0
Original line number Diff line number Diff line
#!/usr/bin/env php
<?php

/**
 * Script à utiliser pour inscrire dans le fichier de config locale le numéro et la date de version de l'application
 * spécifiés en argument.
 *
 * Le chemin du fichier de config créé est par défaut 'config/autoload/auto.version.local.php'.
 *
 * Usage:  ./create-version-config-file --number <version> --date <date> [--file <path>]
 * Ex:     ./create-version-config-file --number 2.0.0 --date "03/11/2020" --file "/app/config/autoload/auto.version.local.php"
 */

require __DIR__ . '/../vendor/autoload.php';

use Zend\Config\Writer\PhpArray;

const ROOT_DIR = __DIR__ . '/..';

const DEFAULT_FILE_PATH = ROOT_DIR . '/config/autoload/auto.version.local.php';
const ARG_VERSION_NUMBER = '--number';
const ARG_VERSION_DATE = '--date';
const ARG_FILE_PATH = '--file';

$versionNumber = ($pos = array_search(ARG_VERSION_NUMBER, $argv)) !== false ? ($argv[$pos+1] ?? null) : null;
$versionDate = ($pos = array_search(ARG_VERSION_DATE, $argv)) !== false ? ($argv[$pos+1] ?? null) : null;
$outputFilepath = ($pos = array_search(ARG_FILE_PATH, $argv)) !== false ? ($argv[$pos+1] ?? null) : null;

if ($versionNumber === null) {
    echo ":-( Vous devez spécifier le numéro de version via " . ARG_VERSION_NUMBER . PHP_EOL;
    exit(1);
}
if ($versionDate === null) {
    echo ":-( Vous devez spécifier la date de version via " . ARG_VERSION_DATE . PHP_EOL;
    exit(1);
}
if ($outputFilepath === null) {
    $outputFilepath = DEFAULT_FILE_PATH;
}

$config = [
    'unicaen-app' => [
        'app_infos' => [
            'version' => $versionNumber,
            'date' => $versionDate,
        ],
    ],
    'comment' => sprintf("Fichier généré le %s avec le script '%s'.", date('d/m/Y à H:i:s'), basename(__FILE__))
];

$phpArray = new PhpArray();
$phpArray
    ->setUseBracketArraySyntax(true)
    ->toFile($outputFilepath, $config);

echo "Fichier de config créé : " . realpath($outputFilepath) . PHP_EOL;
echo "  Version inscrite : " . $versionNumber . PHP_EOL;
echo "  Date inscrite : " . $versionDate . PHP_EOL;