Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,23 @@ We accept contributions via pull requests on GitHub. Please review these guideli

## Guidelines

* Please follow the [PSR-12 Coding Style Guide](https://www.php-fig.org/psr/psr-12/), enforced by [StyleCI](https://styleci.io/).
* Please follow the [PSR-12 Coding Style Guide](https://www.php-fig.org/psr/psr-12/).
* Ensure that the current tests pass, and if you've added something new, add the tests where relevant.
* Send a coherent commit history, making sure each commit in your pull request is meaningful.
* You may need to [rebase](https://git-scm.com/book/en/v2/Git-Branching-Rebasing) to avoid merge conflicts.
* If you are changing or adding to the behaviour or public API, you may need to update the docs.
* Please remember that we follow [Semantic Versioning](https://semver.org/).

You will need [Castor](https://castor.jolicode.com/) to run the tests, fix CS
violations and run the static analysis. See [Castor's documentation](https://castor.jolicode.com/getting-started/installation/)
for installation instructions.

To install all the dependencies and tools, run:

```bash
$ castor install
```

## Running Tests

First, install the dependencies using [Composer](https://getcomposer.org/):
Expand All @@ -27,6 +37,23 @@ Then run [PHPUnit](https://phpunit.de/):
$ vendor/bin/phpunit
```

* A script `test-git-version.sh` is available in repository to test gitlib against many git versions.
* A script `test-git-versions.sh` is available in repository to test gitlib against many git versions.
* The tests will be automatically run by [GitHub Actions](https://github.com/features/actions) against pull requests.
* We also have [StyleCI](https://styleci.io/) set up to automatically fix any code style issues.

## Standard code

Use PHP-CS-Fixer to make your code compliant with gitlib's coding standards:

```bash
$ castor cs
```

## Static analysis

Use PHPStan to ensure the code is free of errors:

```bash
$ castor phpstan
```

Both checks run automatically via GitHub Actions against pull requests.
46 changes: 44 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,56 @@ on:
pull_request:

jobs:
check-cs:
name: Check Coding Standards
runs-on: ubuntu-24.04
steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'

- name: Setup Castor
uses: castor-php/setup-castor@2a495b8c91f00be6768ad8a040ba8634c797d386 # v1.1.0

- name: Run CS check
run: castor cs --dry-run

phpstan:
name: Static Analysis
runs-on: ubuntu-24.04
steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'

- name: Setup Castor
uses: castor-php/setup-castor@2a495b8c91f00be6768ad8a040ba8634c797d386 # v1.1.0

- name: Install dependencies
run: castor install

- name: Run PHPStan
run: castor phpstan

tests:
name: Test PHP ${{ matrix.php }} ${{ matrix.name }}
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
php: ['8.1', '8.2', '8.3', '8.4']
php: ['8.4', '8.5']
composer-flags: ['']
name: ['']
include:
- php: '8.0'
- php: '8.4'
composer-flags: '--prefer-lowest'
name: '(prefer lowest dependencies)'

Expand All @@ -32,6 +71,9 @@ jobs:
- name: Setup Problem Matchers
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Validate composer.json
run: composer validate --strict

- name: Install Composer dependencies
run: |
composer update --prefer-dist --no-interaction ${{ matrix.composer-flags }}
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/.phpunit.result.cache
/.castor.stub.php
/.php-cs-fixer.cache
/.phpunit.cache
/composer.lock
/phpunit.xml
/var/
/vendor
48 changes: 48 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

/*
* This file is part of Gitonomy.
*
* (c) Alexandre Salomé <alexandre.salome@gmail.com>
* (c) Julien DIDIER <genzo.wm@gmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

$fileHeaderComment = <<<'EOF'
This file is part of Gitonomy.

(c) Alexandre Salomé <alexandre.salome@gmail.com>
(c) Julien DIDIER <genzo.wm@gmail.com>

This source file is subject to the MIT license that is bundled
with this source code in the file LICENSE.
EOF;

$finder = PhpCsFixer\Finder::create()
->in(__DIR__)
->append([
__FILE__,
'castor.php',
])
->notPath('var')
;

return new PhpCsFixer\Config()
->setRiskyAllowed(true)
->setUnsupportedPhpVersionAllowed(true)
->setRules([
'@PHP84Migration' => true,
'@PhpCsFixer' => true,
'@Symfony' => true,
'@Symfony:risky' => true,
'php_unit_internal_class' => false, // From @PhpCsFixer but we don't want it
'php_unit_test_class_requires_covers' => false, // From @PhpCsFixer but we don't want it
'phpdoc_add_missing_param_annotation' => false, // From @PhpCsFixer but we don't want it
'header_comment' => ['header' => $fileHeaderComment],
'ordered_class_elements' => true, // Symfony(PSR12) override the default value, but we don't want
'blank_line_before_statement' => true, // Symfony(PSR12) override the default value, but we don't want
])
->setFinder($finder)
;
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
Gitlib for Gitonomy
===================

[![Build Status](https://img.shields.io/github/actions/workflow/status/gitonomy/gitlib/tests.yml?label=Tests&style=flat-square&branch=1.3)](https://github.com/gitonomy/gitlib/actions?query=workflow%3ATests+branch%3A1.3)
[![StyleCI](https://github.styleci.io/repos/5709354/shield?branch=1.3)](https://github.styleci.io/repos/5709354?branch=1.3)
[![License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](https://opensource.org/licenses/MIT)
[![Downloads](https://img.shields.io/packagist/dt/gitonomy/gitlib?style=flat-square)](https://packagist.org/packages/gitonomy/gitlib)

This library provides methods to access Git repository from PHP 5.6+.
This library provides methods to access Git repository from PHP 8.4+.

It makes shell calls, which makes it less performant than any solution.

Expand Down
37 changes: 37 additions & 0 deletions castor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/*
* This file is part of Gitonomy.
*
* (c) Alexandre Salomé <alexandre.salome@gmail.com>
* (c) Julien DIDIER <genzo.wm@gmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

use Castor\Attribute\AsRawTokens;
use Castor\Attribute\AsTask;

use function Castor\guard_min_version;
use function Castor\import;
use function Castor\run;

guard_min_version('1.0.0');

import(__DIR__.'/tools/php-cs-fixer/castor.php');
import(__DIR__.'/tools/phpstan/castor.php');

#[AsTask(description: 'Install dependencies')]
function install(): void
{
run(['composer', 'install']);
qa\cs\install();
qa\phpstan\install();
}

#[AsTask(description: 'Run PHPUnit', ignoreValidationErrors: true)]
function phpunit(#[AsRawTokens] array $rawTokens): void
{
run(['vendor/bin/phpunit', ...$rawTokens]);
}
9 changes: 4 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,15 @@
}
},
"require": {
"php": "^8.0",
"php": "^8.4",
"ext-pcre": "*",
"symfony/polyfill-mbstring": "^1.7",
"symfony/process": "^5.4 || ^6.0 || ^7.0 || ^8.0"
"symfony/process": "^6.4 || ^7.4 || ^8.1"
},
"require-dev": {
"ext-fileinfo": "*",
"phpspec/prophecy-phpunit": "^2.0",
"phpunit/phpunit": "^7.5.20 || ^8.5.20 || ^9.5.9",
"psr/log": "^1.0"
"phpunit/phpunit": "^12.0",
"psr/log": "^3.0"
},
"config": {
"preferred-install": "dist",
Expand Down
Loading
Loading