Skip to content

Commit

Permalink
Merge pull request #3 from AngryBytes/feat/upgrade
Browse files Browse the repository at this point in the history
Feat/upgrade
  • Loading branch information
stephank authored Aug 5, 2020
2 parents a9ea9ee + 3139b34 commit 9ba4d73
Show file tree
Hide file tree
Showing 30 changed files with 502 additions and 639 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/php-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
on: [push]
name: PHP checks
jobs:
composer-check:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['7.2', '7.3', '7.4']
name: PHP ${{ matrix.php-versions }} tests
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
tools: cs2pr

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}

- name: Run Composer install
run: composer install --prefer-dist

- name: Run PHP checks
run: composer phpcheck

- name: Run PHPUnit
run: composer phpunit
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/vendor/
composer.lock
.phpunit.result.cache
16 changes: 0 additions & 16 deletions .travis.yml

This file was deleted.

19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Changelog

## 1.1.0

### PHP support
* Dropped support for PHP `7.1` and lower.
* Added support for PHP `7.2`, `7.3` and `7.4`.

### 3rd party updates
* Updated `symfony/finder` to version `4.4`.

## 1.0.4
* Updated `symfony/finder` to version `3.3`.

## 1.0.3
* Re-added the missing `Naneau\ProjectVersioner\Versioner::has($directory)` method.

## 1.0.2
* Added `Naneau\ProjectVersioner\Reader\ComposerJson` for reading versions from a composer.json file.
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# PHP Project Versioner

[![Latest Stable Version](https://poser.pugx.org/naneau/project-versioner/v/stable.svg)](https://packagist.org/packages/naneau/project-versioner)
[![Build Status](https://travis-ci.org/naneau/php-project-versioner.svg?branch=master)](https://travis-ci.org/naneau/php-project-versioner)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/naneau/php-project-versioner/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/naneau/php-project-versioner/?branch=master)
[![PHP checks](https://github.com/AngryBytes/php-project-versioner/workflows/PHP%20checks/badge.svg)](https://github.com/AngryBytes/php-project-versioner/actions?query=workflow%3A%22PHP+checks%22)

**Note:** this is a fork of the original project as it appears to be abandoned.

This is a simple tool to obtain "versions" for projects in PHP.

Expand Down Expand Up @@ -31,7 +31,7 @@ use Naneau\ProjectVersioner\Versioner;
use Naneau\ProjectVersioner\Reader\Git\Commit\Exec as GitCommitReader;

// Create a versioner
$versioner = new Versioner(array(new GitCommitReader));
$versioner = new Versioner([new GitCommitReader]);

// Short commit hash like "gd8587c8"
$version = $versioner->get('/foo/bar');
Expand All @@ -46,7 +46,7 @@ use Naneau\ProjectVersioner\Versioner;
use Naneau\ProjectVersioner\Reader\Git\Tag\Exec as GitTagReader;

// Create a versioner
$versioner = new Versioner(array(new GitTagReader));
$versioner = new Versioner([new GitTagReader]);

// Last tag
$version = $versioner->get('/foo/bar');
Expand All @@ -61,7 +61,7 @@ use Naneau\ProjectVersioner\Versioner;
use Naneau\ProjectVersioner\Reader\Git\Tag\Exec as GitTagReader;

// Create a versioner
$versioner = new Versioner(array(new GitTagReader));
$versioner = new Versioner([new GitTagReader]);

// Last tag + commit info, like 4.3.2-9-gd504031
$version = $versioner->get('/foo/bar');
Expand All @@ -78,10 +78,10 @@ use Naneau\ProjectVersioner\Versioner;
use Naneau\ProjectVersioner\Reader\File as FileReader;

// Create a versioner
$versioner = new Versioner(array(
$versioner = new Versioner([
// Reader for "VERSION" file
new FileReader('VERSION')
));
]);

// Retrieve version from versioner
$version = $versioner->get('/foo/bar');
Expand All @@ -96,9 +96,9 @@ use Naneau\ProjectVersioner\Versioner;
use Naneau\ProjectVersioner\Reader\Finder\MTime as MTimeReader;

// Create a versioner
$versioner = new Versioner(array(
$versioner = new Versioner([
new MTimeReader('*.txt') // Look at all *.txt files
));
]);

// Highest mtime, like 1410806782
$version = $versioner->get('/foo/bar');
Expand All @@ -112,9 +112,9 @@ Using a different reader it is possible to use the *contents* of the files found
use Naneau\ProjectVersioner\Versioner;
use Naneau\ProjectVersioner\Reader\Finder\Contents as ContentsReader;

$versioner = new Versioner(array(
$versioner = new Versioner([
new ContentsReader('*.jpg')
));
]);

// Short hash of file contents, like gd504031
$version = $versioner->get('/foo/bar');
Expand All @@ -132,7 +132,7 @@ To look at all packages combined:
use Naneau\ProjectVersioner\Versioner;
use Naneau\ProjectVersioner\Reader\Composer as ComposerReader;

$versioner = new Versioner(array(new ComposerReader));
$versioner = new Versioner([new ComposerReader]);

// Short hash like "ae9b8a"
$version = $versioner->get('/foo/bar');
Expand All @@ -146,9 +146,9 @@ Or, looking for a specific package:
use Naneau\ProjectVersioner\Versioner;
use Naneau\ProjectVersioner\Reader\ComposerPackage as ComposerPackageReader;

$versioner = new Versioner(array(
$versioner = new Versioner([
new ComposerPackageReader('symfony/filesystem')
));
]);

// Composer Version (SemVer) like "v2.5.4"
$version = $versioner->get('/foo/bar');
Expand All @@ -165,10 +165,10 @@ use Naneau\ProjectVersioner\Versioner;
use Naneau\ProjectVersioner\Reader\ComposerPackage as ComposerPackageReader;
use Naneau\ProjectVersioner\Reader\Git\Tag\Exec as GitTagReader;

$versioner = new Versioner(array(
$versioner = new Versioner([
new ComposerPackageReader('symfony/filesystem'),
new GitTagReader
));
]);

// First version found
$version = $versioner->get('/foo/bar');
Expand Down
44 changes: 38 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,55 @@
{
"name": "naneau/project-versioner",
"name": "angrybytes/project-versioner",
"description": "A tool to maintain project/sub-project versions based on Composer, file mtimes, etc.",
"license": "MIT",
"authors": [
{
"name": "Maurice Fonk",
"email": "[email protected]"
},
{
"name": "Angry Bytes BV",
"email": "[email protected]",
"homepage": "https://angrybytes.com/"
}
],

"support": {
"email": "[email protected]"
},
"autoload": {
"psr-4": {"Naneau\\ProjectVersioner\\": "src/Naneau/ProjectVersioner/"}
"psr-4": {
"Naneau\\ProjectVersioner\\": "src/Naneau/ProjectVersioner/",
"Naneau\\ProjectVersioner\\Test\\": "tests/Naneau/ProjectVersioner/Test"
}
},
"config": {
"optimize-autoloader": true,
"sort-packages": true
},
"scripts": {
"phpcheck": [
"./vendor/bin/parallel-lint src/",
"./vendor/bin/phpstan analyse -l max --memory-limit=1G src/",
"./vendor/bin/phpcs -p --standard=PSR2 --extensions=php src/"
],
"phpcbf":[
"./vendor/bin/phpcbf -p --standard=PSR2 --extensions=php src/"
],
"phpunit": [
"./vendor/bin/phpunit"
]
},

"minimum-stability": "stable",
"require": {
"symfony/finder": "~2.5"
"ext-json": "*",
"php": "7.2.* || 7.3.* || 7.4.*",
"symfony/finder": "~4.4"
},
"require-dev": {
"phpunit/phpunit": "~4.2"
"jakub-onderka/php-console-highlighter": "^0.4.0",
"jakub-onderka/php-parallel-lint": "^1.0",
"phpstan/phpstan": "0.12.34",
"phpunit/phpunit": "~8.5",
"squizlabs/php_codesniffer": "^3.5"
}
}
15 changes: 7 additions & 8 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
cacheTokens="false"
colors="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/8.5/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
>

<testsuites>
<testsuite name="ProjectVersioner Test Squite">
<testsuite name="ProjectVersioner Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
Expand Down
29 changes: 12 additions & 17 deletions src/Naneau/ProjectVersioner/Reader/Composer.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
<?php
/**
* Composer.php
*
* @package ProjectVersioner
* @subpackage Reader
*/

namespace Naneau\ProjectVersioner\Reader;

use Naneau\ProjectVersioner\ReaderInterface;
Expand All @@ -14,29 +7,31 @@
* Composer
*
* Finds version from composer lock file
*
* @category Naneau
* @package ProjectVersioner
* @subpackage Reader
*/
class Composer implements ReaderInterface
{
/**
* {@inheritdoc}
**/
public function canRead($directory)
*/
public function canRead(string $directory): bool
{
return is_readable($directory . '/composer.lock');
}

/**
* {@inheritdoc}
**/
public function read($directory)
*/
public function read(string $directory)
{
$contents = file_get_contents($directory . '/composer.lock');
if (!$contents) {
return null;
}

return substr(
md5(file_get_contents($directory . '/composer.lock')),
0, 6
md5($contents),
0,
6
);
}
}
34 changes: 11 additions & 23 deletions src/Naneau/ProjectVersioner/Reader/ComposerJson.php
Original file line number Diff line number Diff line change
@@ -1,50 +1,38 @@
<?php
/**
* ComposerJson.php
*
* @package ProjectVersioner
* @subpackage Reader
*/

namespace Naneau\ProjectVersioner\Reader;

use Naneau\ProjectVersioner\ReaderInterface;

use \RuntimeException;
use \stdClass;
use stdClass;

/**
* Finds the "version" from the composer.json file
*
* @category Naneau
* @package ProjectVersioner
* @subpackage Reader
*/
class ComposerJson implements ReaderInterface
{
/**
* {@inheritdoc}
**/
public function canRead($directory)
*/
public function canRead(string $directory): bool
{
return is_readable($directory . '/composer.json');
}

/**
* {@inheritdoc}
**/
public function read($directory)
*/
public function read(string $directory)
{
$json = @file_get_contents($directory . '/composer.json');
if ($json === false) {
return false;
if (!$json) {
return null;
}

$json = json_decode($json);
$json = json_decode($json, false);
if (!($json instanceof stdClass) || empty($json->version)) {
return false;
}
return null;
}

return trim($json->version);
return trim($json->version);
}
}
Loading

0 comments on commit 9ba4d73

Please sign in to comment.