PHPackages                             tomzx/php-semver-checker-git - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. tomzx/php-semver-checker-git

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

tomzx/php-semver-checker-git
============================

PHP Semantic Versioning Checker for GIT

v0.8.1(4y ago)28695[10 issues](https://github.com/tomzx/php-semver-checker-git/issues)[3 PRs](https://github.com/tomzx/php-semver-checker-git/pulls)MITPHPPHP &gt;=7.3

Since Jan 24Pushed 3y ago1 watchersCompare

[ Source](https://github.com/tomzx/php-semver-checker-git)[ Packagist](https://packagist.org/packages/tomzx/php-semver-checker-git)[ Docs](https://github.com/tomzx/php-semver-checker-git)[ RSS](/packages/tomzx-php-semver-checker-git/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (6)Versions (21)Used By (0)

PHP Semantic Versioning Checker for `git`
=========================================

[](#php-semantic-versioning-checker-for-git)

[![License](https://camo.githubusercontent.com/ac0d26d32ebbe3296397ec4c2ca0fe524943c3a00c0f595019bb61164be816ce/68747470733a2f2f706f7365722e707567782e6f72672f746f6d7a782f7068702d73656d7665722d636865636b65722d6769742f6c6963656e73652e737667)](https://packagist.org/packages/tomzx/php-semver-checker-git)[![Latest Stable Version](https://camo.githubusercontent.com/9e89790c1914be189fdfdd1ae5adfd9a51af7de2abd21bd90f744b6c7291ec10/68747470733a2f2f706f7365722e707567782e6f72672f746f6d7a782f7068702d73656d7665722d636865636b65722d6769742f762f737461626c652e737667)](https://packagist.org/packages/tomzx/php-semver-checker-git)[![Latest Unstable Version](https://camo.githubusercontent.com/aeeb597b5b39c19659759b3a089653e2dc6fd9d5cc11df550afb611a12d53738/68747470733a2f2f706f7365722e707567782e6f72672f746f6d7a782f7068702d73656d7665722d636865636b65722d6769742f762f756e737461626c652e737667)](https://packagist.org/packages/tomzx/php-semver-checker-git)[![Build Status](https://camo.githubusercontent.com/c49c3fd5ddcbae99b65266d2aa9e873f1d97fad7bed7b46b413856294b265801/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f746f6d7a782f7068702d73656d7665722d636865636b65722d6769742f436f6e74696e756f7573253230696e746567726174696f6e2e737667)](https://github.com/tomzx/php-semver-checker-git/actions?query=workflow%3A%22Continuous+integration%22)[![Code Coverage](https://camo.githubusercontent.com/ff2f26353ed07c70f01d40f8672c031536ee7f9a928291ec80963b5539d91be7/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f746f6d7a782f7068702d73656d7665722d636865636b65722d676974)](https://app.codecov.io/gh/tomzx/php-semver-checker-git/)[![Total Downloads](https://camo.githubusercontent.com/a357f587f2a2d54489712b71666dea993d6d7c9c2002baf0240f2efcd6260238/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f746f6d7a782f7068702d73656d7665722d636865636b65722d6769742e737667)](https://packagist.org/packages/tomzx/php-semver-checker-git)

PHP Semantic Versioning Checker for `git` is a console/library which allows you to inspect a set of before and after source code using GIT.

The command line utility will use an existing `git` repository to compare to changesets using anything `git checkout` would accept (sha1, branch, tag). It will checkout in `detached` mode in order not to pollute your list of branches.

**Note** It is strongly suggested you do not run this directly on any repository you do not want to lose. Make a copy of it beforehand and run `php-semver-checker-git` on that copy instead.

Getting started
---------------

[](#getting-started)

As this is still an alpha package, it is not suggested to include `php-semver-checker-git` directly in your composer.json. There are however a couple ways to use the tool:

1. **Preferred method** Download the [latest .phar build](https://psvcg.coreteks.org/php-semver-checker-git.phar). Note that the .phar build is generally less bleeding edge than the following methods.
2. `php composer.phar create-project tomzx/php-semver-checker-git --stability=dev` will clone to a new php-semver-checker-git folder in your current working directory
3. `git clone https://github.com/tomzx/php-semver-checker-git.git` and `php composer.phar install` in the newly cloned directory.

See the example section for examples of how to use the tool.

### Building `php-semver-checker-git.phar`

[](#building-php-semver-checker-gitphar)

First, make sure you have [box](https://github.com/box-project/box2) installed. Then, in the base directory, you can run the following command which will generate the `php-semver-checker-git.phar` file.

```
box build
```

### Using `php-semver-checker-git` with `GitHub actions`

[](#using-php-semver-checker-git-with-github-actions)

It is very easy to add `php-semver-checker-git` to your build process and to get a nice report you can check in the `GitHub actions` logs. In a file under `.github/workflows/`, add the following:

```
name: Continuous integration

on: [push]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout code
      uses: actions/checkout@v2
      with:
        fetch-depth: 0

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

    # Your own CI configuration goes here

    - name: Evaluate semantic versioning
      run: |
        wget https://psvcg.coreteks.org/php-semver-checker-git.phar
        php php-semver-checker-git.phar suggest -vvv --include-before=src --include-after=src --details --allow-detached
```

In order to simplify the above call to `php-semver-checker-git`, we suggest you create a `php-semver-checker-git.yml` configuration file at the root of your project. In it, you can put the following:

```
allow-detached: true
details: true
include-before: src
include-after: src
```

With this configuration file, you can update the configuration file created previously:

Before:

```
  # Your own CI configuration goes here

    - name: Evaluate semantic versioning
      run: |
        wget https://psvcg.coreteks.org/php-semver-checker-git.phar
        php php-semver-checker-git.phar suggest -vvv --include-before=src --include-after=src --details --allow-detached
```

After:

```
  # Your own CI configuration goes here

    - name: Evaluate semantic versioning
      run: |
        wget https://psvcg.coreteks.org/php-semver-checker-git.phar
        php php-semver-checker-git.phar suggest -vvv
```

Example
-------

[](#example)

### Compare two commits (without semantic versioning)

[](#compare-two-commits-without-semantic-versioning)

```
# arguments are: before-commit/branch/tag after-commit/branch/tag
php bin/php-semver-checker-git compare v1.6.4 v2.0.0 --include-before=src --include-after=src
```

### Compare HEAD against your latest semantic version tag

[](#compare-head-against-your-latest-semantic-version-tag)

```
php bin/php-semver-checker-git suggest --allow-detached --include-before=src --include-after=src
```

Note: `--allow-detached` is very useful when you are running this command on [`GitHub actions`](https://github.com/features/actions) or any other continuous integration provider. It is necessary when a checkout is done on a particular commit, which makes `HEAD` become `detached`. If this option is not passed to the command, it will abort. This is done because it is impossible to revert the original `detached` branch when the `suggest` command completes.

### Compare HEAD against a specific tag constraint

[](#compare-head-against-a-specific-tag-constraint)

```
php bin/php-semver-checker-git suggest --allow-detached --include-before=src --include-after=src  --tag=~5.0
```

Note: `--tag` supports any semantic versioning constraint such as `
