GithubHelp home page GithubHelp logo

version's Introduction

Version

Take control over your Laravel app version

Latest Stable Version License Code Quality Build

Coverage StyleCI Downloads

Description

This package is a Laravel (5.5+) utility which helps you keep and manage your application version, increment version numbers (major, minor, patch, commit), and can also use your last commit hash.

The end results of this package are:

  • Print a version on a page.
  • Print it in the console, via an Artisan command.

Full SemVer compatibility

This package is able to parse a SemVer version:

v2.0.1-alpha.1227

And translate it to be used as:

label: v
major: 2
minor: 0
patch: 1
prerelease: alpha
buildmetadata: 1227
commit: 49ffe2

You can use the format function to rewrite and show it in your app, for instance, as:

MyApp version 2.0.1 - alpha 1227 (commit 49ffe2)

Some use cases for those results could be:

  • Make sure a rollback was successful.
  • Know if an update reached all servers.
  • Check if a user is looking at the last version of your app.
  • Verify if is Travis CI testing the version it is supposed to be testing.
  • You simple love to version your stuff, and you like to see them in all your pages? That's cool too. :)
  • What's your use case? Tell us!

Features

Easily control you app version using a YAML config file

version: 
    current:
        major: 1
        minor: 0
        patch: 0
        format: '{$major}.{$minor}.{$patch}'
    commit:
        mode: number
        number: 701036

Use your git commit as your app commit hash/number

Configure it

commit:
    mode: git-local

And you may have an output like this

MyApp version 1.0.0 (commit a9c03f)

Or just use an incremental commit hash/number:

commit:
    mode: number
    number: 701036

To get

MyApp version 1.0.0 (commit 701036)

Easily increment your version numbers, using Artisan commands

php artisan version:commit

Which should print the new version number

New commit: 701037
MyApp version 1.0.0 (commit 701037) 

Available for all of them:

$ php artisan version:major   
$ php artisan version:minor   
$ php artisan version:patch   
$ php artisan version:build   

The output format is highly configurable

You can configure the :

format:
  version: "{$major}.{$minor}.{$patch}"
  full: "version {{'format.version'}} (commit {$commit})"
  compact: "v{{'format.version'}}-{$commit}"

Those are the results for full and compact formats

MyApp version 1.0.0 (commit 701037)
MyApp v1.0.0-701037

It gives you access to dynamic methods:

Version::compact()

And should you create a new one:

format:
  awesome: "awesome version {$major}.{$minor}.{$patch}"

It will also become callable:

Version::awesome()

A Facade is available

Version::version() // 1.2.25

Version::commit() // 703110

Version::major() // 1

Version::minor() // 2

Version::patch() // 25

Version::format('full') // version 1.0.0 (commit 703110)

Version::full() // version 1.0.0 (commit 703110) -- dynamic method

Version::format('compact') // v.1.0.0-703110

Version::compact() // v.1.0.0-703110 -- dynamic method

Instantiating it

If you prefer not to use the Façade:

dd(
    Version::format()
);

The best ways to instantiate it are:

A simple PHP object instantiation:

$version = new \PragmaRX\Version\Package\Version();

dd(
    $version->format()
);

Or to get an already instantiated Version object from the container:

dd(
    app(\PragmaRX\Version\Package\Version::class)->format()
);

But you have to make sure you published the config file

A Blade directive is also ready to be used in your views

You can use this directive to render a full version format:

@version

Or choose the format:

@version('full')
@version('compact')

You can configure the directive name:

blade_directive: printversion

Then

@printversion('compact')

Git tags

You can use your git tags as application versions, all you need is to set the version source to "git":

version_source: git

And if you add a commit hash/number to your tags:

$ git tag -a -f v0.1.1.3128

Version will use it as your app commit hash/number

Matching other version (git tags) formats

You probably only need to change the git version matcher

git:
  ...
  version:
    matcher: "/[V|v]*[ersion]*\\s*\\.*(\\d+)\\.(\\d+)\\.(\\d+)\\.*(\\w*)/"

So let's say you tag your releases as

2017120299
YYYYMMDD##

You can change your matcher to

git:
  version:
    matcher: "/(\d{4})(\d{2})(\d{2})(?:\d{2})/"

And remove dots from your formats:

format:
  compact: "v{$major}{$minor}{$patch}-{$commit}"

Using the current application version in your code

Here's a community example on how to send the app version number when logging an exception to Bugsnag:

<?php

namespace App\Exceptions;

use PragmaRX\Version\Package\Version;
use Bugsnag\BugsnagLaravel\Facades\Bugsnag;

class Handler extends ExceptionHandler
{
    public function report(Exception $exception)
    {
        if ($this->shouldReport($exception)) {
            Bugsnag::setAppVersion((new Version())->format('version'));
            Bugsnag::notifyException($exception);
        }
    }
}

Commit Timestamp

This package also lets you absorb the last commit timestamp or store the current date to the version.yml file. This is the format in the config file:

timestamp:
  year:
  month:
  day:
  hour:
  minute:
  second:
  timezone:

To absorb you only need to configure mode: absorb then execute:

php artisan version:absorb

But you can also set mode: increment then execute:

php artisan version:timestamp

To store the current date and time to the config file:

$ php artisan version:minor
New timestamp: 2019-09-16 18:23:03
MyApp version 2.3.2 (commit 49ffe2)

And you can then use it to show in your app:

Version::format('timestamp-full')

Artisan commands

Those are the commands you have at your disposal:

version:show

Show the current app version:

$ php artisan version:show
PragmaRX version 1.0.0 (build 701031)

$ php artisan version:show --format=compact
PragmaRX v1.0.0-701031

$ php artisan version:show --format=compact --suppress-app-name
v1.0.0-701031

version:absorb

You need to set mode: absorb.

Version can absorb git version and commit to the config file, so you can delete the .git folder and still keep your version and commit for fast access. You have to configure git_absorb in your config file:

commit:
  #...  
  git_absorb: git-local # "false", "git-local" or "git-remote"

And run it

$ php artisan version:absorb

The usual configuration setup to implement absorb is:

version_source: config             ## must be set as config
current:
    major: 1                       ## |
    minor: 0                       ## | --> will be changed by absorb
    patch: 0                       ## |
    git_absorb: git-local          ## configure to get from local or remote
commit:
    mode: number                   ## must be set as number
    number: f477c8                 ## will be changed by absorb
    git_absorb: git-local          ## configure to get from local or remote 

version:(major|minor|patch|commit)

You need to set mode: increment.

Increment the version item:

$ php artisan version:minor
New minor version: 5
MyApp version 1.5.0 (commit 701045)

Regex Matcher

This is the current regex used to break a version string:

^(?P<label>[v|V]*[er]*[sion]*)[\.|\s]*(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$

You can test it online: https://regex101.com/r/Ly7O1x/42

Install

Via Composer

$ composer require pragmarx/version

Then publish the configuration file you'll have to:

$ php artisan vendor:publish --provider="PragmaRX\Version\Package\ServiceProvider"

And you should be good to use it in your views:

@version

As git versions are cached, you can tell composer to refresh your version numbers every time an update or install occur, by adding the refresh command to post-autoload-dump:

"post-autoload-dump": [
    ...
    "@php artisan version:refresh"
]

[Optional] You may also can automated this process by set inside your .git/hooks/post-commit. It will automatic run the command once you have make a commit.

#!/bin/sh

php artisan version:refresh

If you are using Git commits on your commit numbers, you may have to add the git repository to your .env file

VERSION_GIT_REMOTE_REPOSITORY=https://github.com/antonioribeiro/version.git

If you are using git-local make sure the current folder is a git repository

Minimum requirements

  • Laravel 5.5
  • PHP 7.0

Testing

$ composer test

Troubleshooting

  • If you are having trouble to install because of symfony/router (3.3/3.4) or symfony/yaml (3.3/3.4), you can try to:
rm -rf vendor
rm composer.lock
composer install

Author

Antonio Carlos Ribeiro

License

This package is licensed under the MIT License - see the LICENSE file for details

Contributing

Pull requests and issues are welcome.

version's People

Contributors

antonioribeiro avatar dylan-dpc avatar gjj avatar irazasyed avatar lucascudo avatar pgtruesdell avatar shiroamada avatar softquantum avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

version's Issues

Grammar fix

src/package/Support/Git.php:47
"No git tags not found in this repository"

Just a double negative. Not a really big deal. Sorry for being a grammar nazi.

Increment Mode should also update local git commit hash

Hi, The previous feature of incrementing and simultaneously updating the commit hash from local git commit should be bought back, because version:commit is just adding one number to the commit and is confusing, whereas we tend to forget tagging after each commit

Instantiating xml file from IoC Container

When trying to instantiate the Version model, I get this error.
Class pragmarx.yaml does not exist

Seems the Model is tryting to get an XML file from the IoC that is not registered.

When digging deeper
$yaml = $this->instantiateClass($yaml ?: app('pragmarx.yaml'), 'yaml');
This line is the culprit, and $yaml parameter seems off here.

$yaml = $this->instantiateClass($config ?: app('pragmarx.yaml'), 'yaml');
This seems a better option as its get the propery out of the config

Compatibility with symfony/yaml 5

I am currently not able to install the package because it depends on pragmarx/yaml which in turn depends on symfony/yaml 4.

Is there any way to make this (or the dependend project) compatible with symfony/yaml 5?

Failing in Laravel 6.x

Running Laravel 6.4.1 and Version 1.0.2
getting ErrorException (E_ERROR) Undefined index: optional (View: /home/vagrant/code/resources/views/layouts/main.blade.php) (View: /home/vagrant/code/resources/views/layouts/main.blade.php) Previous exceptions Undefined index: optional (View: /home/vagrant/code/resources/views/layouts/main.blade.php) (0) Undefined index: optional (0)

Was working fine in 5.8

Thanks

Version inside of another config file.

I am needing a way to get the version inside of another config file. My thoughts on a new command that would be something like laravel's key:generate that would update the .env with the current version. Thoughts?

git-local build [commit] hash is not updating

My debug environment has no issues with versioning (whatsoever) but my staging environment will not show the latest commit hash and will not use tags. I am happy to forego using tags, but the build hash is critical!

The build number is not the one defaulted in the config, but an old commit?

Any ideas what is wrong?

version_source: config
blade_directive: version
current:
    major: 0
    minor: 1
    patch: 10
    format: '{$major}.{$minor}.{$patch}'
    git_absorb: false
cache:
    enabled: true
    key: pragmarx-version
    time: 525600
build:
    mode: git-local
    number: 701031
    length: 6
    increment_by: 1
    git_absorb: false
git:
    git-local: 'git rev-parse --verify HEAD'
    git-remote: 'git ls-remote {$repository}'
    branch: refs/heads/master
    repository: 'hidden'
    version: { git-local: 'git describe', git-remote: 'git ls-remote {$repository} | grep tags/ | grep -v {} | cut -d / -f 3 | sort --version-sort | tail -1', matcher: '/[V|v]*[ersion]*\s*\.*(\d+)\.(\d+)\.(\d+)\.*(\w*)/' }
format:
    major: '{$major}'
    minor: '{$minor}'
    patch: '{$patch}'
    build: '{$build}'
    version: '{$major}.{$minor}.{$patch} (build {$build})'
    full: 'version {$major}.{$minor}.{$patch} (build {$build})'
    compact: 'v{$major}.{$minor}.{$patch}-{$build}'

Docs are out of date

Is there any up-to-date documentation? The documentation in the repo is three years old!

Getting "Class pragmarx.yaml does not exist"

Hi,

The package is working ok, but now I am trying to get the version number from a file that is under config/ directory (trying to set the release value on sentry.io configuration).

Is there a way to use the library from other than a file under app directory ?

(I think I am using 0.2.7)

Add formatting options to format configuration

It seems that only raw values from the current version configuration sets can be output using the format string. When outputting times with single digit minutes this leads to timestamps that look like: "8:8" (8 minutes after eight).

It would be great if there were some options for simple variable transformations (like padding a variable with zeroes in this case). e.g.

{$timestamp.hour}:{$timestamp.minute|pl:0:2}

for padding from left to size 2 with zeroes etc.

Commit version is not shown

image

Hi I am trying to show my current commit, bu it's always shown empty: ''version 0.1.1 (commit )''
I don't know if I am setting up in a bad way.

Support SemVer pre-release labels

Examples: 1.0.0-alpha, 1.0.0-alpha.1, 1.0.0-0.3.7, 1.0.0-x.7.z.92.
(Source: https://semver.org/#spec-item-9)

Currently

  • When I create an annotated tag with a pre-release label (accordingly to the SemVer specs) -- e.g. v0.8.0-beta, the label is ignored.
  • When I update the matcher regex, the Git.php handle it as the build
    public function version($type)
    {
        $version = $this->extractVersion($this->getVersionFromGit());

        return [
            'major' => $this->getMatchedVersionItem($version, 1),

            'minor' => $this->getMatchedVersionItem($version, 2),

            'patch' => $this->getMatchedVersionItem($version, 3),

            'build' => $this->getMatchedVersionItem($version, 4),
        ][$type];
    }

Proposal

  • Support SemVer pre-release labels as the 4th default property. Thus the build would be the 5th.

(I intend myself to create a PR for that)

How to have different Caching Key for different ENV

Great package, works very well. I was wondering is there a way just like we do in any config/*.php that by looking at env we can change values?

I am mainly looking at cache key, can I use different caching key for different env?

I can see it as a good use case, few of our environments are sharing cache so it always mess up the build number, which is set to be git hash.

Once again thanks for very nice product.

Class 'Symfony\Component\Yaml\Parser' not found

Ran composer require pragmarx/version, then php artisan vendor:publish --provider="PragmaRX\Version\Package\ServiceProvider".

Then when I refresh my app, I get the error

Class 'Symfony\Component\Yaml\Parser' not found

This is within a Homestead environment using:

  • Laravel 8.18.1
  • PHP 7.4.10
  • Composer 2.0.12

I tried installing Symfony, but it keeps erroring out and it appears that Symfony is already installed though. composer require symfony/yaml

Can't Install

When I try to install using composer this is what i get:

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Conclusion: remove symfony/routing v3.4.0
    - Conclusion: don't install symfony/routing v3.4.0
    - Installation request for pragmarx/version ^0.2.1 -> satisfiable by pragmarx/version[v0.2.1].
    - symfony/yaml v3.3.0 conflicts with symfony/routing[v3.4.0].
    - symfony/yaml v3.3.1 conflicts with symfony/routing[v3.4.0].
    - symfony/yaml v3.3.10 conflicts with symfony/routing[v3.4.0].
    - symfony/yaml v3.3.11 conflicts with symfony/routing[v3.4.0].
    - symfony/yaml v3.3.12 conflicts with symfony/routing[v3.4.0].
    - symfony/yaml v3.3.13 conflicts with symfony/routing[v3.4.0].
    - symfony/yaml v3.3.2 conflicts with symfony/routing[v3.4.0].
    - symfony/yaml v3.3.3 conflicts with symfony/routing[v3.4.0].
    - symfony/yaml v3.3.4 conflicts with symfony/routing[v3.4.0].
    - symfony/yaml v3.3.5 conflicts with symfony/routing[v3.4.0].
    - symfony/yaml v3.3.6 conflicts with symfony/routing[v3.4.0].
    - symfony/yaml v3.3.7 conflicts with symfony/routing[v3.4.0].
    - symfony/yaml v3.3.8 conflicts with symfony/routing[v3.4.0].
    - symfony/yaml v3.3.9 conflicts with symfony/routing[v3.4.0].
    - Installation request for symfony/routing (locked at v3.4.0) -> satisfiable by symfony/routing[v3.4.0].
    - pragmarx/version v0.2.1 requires pragmarx/yaml ^0.1 -> satisfiable by pragmarx/yaml[v0.1.0, v0.1.1, v0.1.2, v0.1.3].
    - pragmarx/yaml v0.1.3 requires symfony/yaml ^3.3 -> satisfiable by symfony/yaml[v3.3.0, v3.3.1, v3.3.10, v3.3.11, v3.3.12, v3.3.13, v3.3.2, v3.3.3, v3.3.4, v3.3.5, v3.3.6, v3.3.7, v3.3.8, v3.3.9, v3.4.0].
    - pragmarx/yaml v0.1.2 requires symfony/yaml ^3.3 -> satisfiable by symfony/yaml[v3.3.0, v3.3.1, v3.3.10, v3.3.11, v3.3.12, v3.3.13, v3.3.2, v3.3.3, v3.3.4, v3.3.5, v3.3.6, v3.3.7, v3.3.8, v3.3.9, v3.4.0].
    - pragmarx/yaml v0.1.1 requires symfony/yaml ~3.3 -> satisfiable by symfony/yaml[v3.3.0, v3.3.1, v3.3.10, v3.3.11, v3.3.12, v3.3.13, v3.3.2, v3.3.3, v3.3.4, v3.3.5, v3.3.6, v3.3.7, v3.3.8, v3.3.9, v3.4.0].
    - pragmarx/yaml v0.1.0 requires symfony/yaml ~3.3 -> satisfiable by symfony/yaml[v3.3.0, v3.3.1, v3.3.10, v3.3.11, v3.3.12, v3.3.13, v3.3.2, v3.3.3, v3.3.4, v3.3.5, v3.3.6, v3.3.7, v3.3.8, v3.3.9, v3.4.0].
    - Conclusion: don't install symfony/yaml v3.4.0|install symfony/yaml v3.3.0|install symfony/yaml v3.3.1|install symfony/yaml v3.3.10|install symfony/yaml v3.3.11|install symfony/yaml v3.3.12|install symfony/yaml v3.3.13|install symfony/yaml v3.3.2|install symfony/yaml v3.3.3|install symfony/yaml v3.3.4|install symfony/yaml v3.3.5|install symfony/yaml v3.3.6|install symfony/yaml v3.3.7|install symfony/yaml v3.3.8|install symfony/yaml v3.3.9


Installation failed, reverting ./composer.json to its original content.

Storing versioning

Hi,

Are there any events triggered when the version number changes? Would be nice to for instance store the consecutive version numbers in a database for later reference.

Edwin

Write compact version via artisan

Hey! Great project! I've got a suggestion... it would be helpful to be able to write the compact version out using composer, e.g:

php artisan version:show --compact > VERSION

Part of my build process for packaging removes the .git directory, so it'd be nice to be able to bake that version number in. I've been using something like this in the past:

git rev-parse --quiet --verify HEAD 2>/dev/null || echo VERSION

It's not clear what might happen if the .git directory is gone. I'm trying to experiment, I'm moving the .git folder out but the command still works. Dunno what's happening there. But that's a different issue.

It'd be nice to have the option to 1) write the version to a file 2) use the file if git isn't available. Maybe that means having the cache be able to write out to a specified file instead of wherever Laravel caches.

(suggest) Lead zero & v max

Hi, First thank for this cool code !

But, I am a little bit disappointed :

1 - no lead zero in Patch and Build (number incrementable mode), in natural order or, just for styling, lead zero in this two field is better than no-lz.
Natural order != number order, the annoying problem :

  • 1.1.1
  • 1.10.1 <- not the good place
  • 1.3.1

With LZ :

  • 1.01.01
  • 1.03.01
  • 1.10.01 <- good place

This can be easy to fix with a function like sprintf %.2d %.3d etc.
Yaml can be modified like this :

field: # can be major | minor | patch | build
  val: 1 # value of field
  lead: 0 # format descriptor précision : n<2 or not set or null =  %d  | n>1  = %.nd (max 4)
  inc: 1 # val increment

2 - v max & auto inc superior field :
version part is not human readable above 99 (on multiple field) or 999 (on one field)
v16.1248.3469 ... not cool
hex format ? :
v16.4E0.D8D ... not really cool ...

v26.76.084 ... sound little better, no ?

Well, UP to BIG major. By default, can be :
Patch max 0..255
Minor max 0..255
Like, RAD Studio (Delphi), version controller. This made bigger major number. Only build can be huge number or hex format (like the current on git-local/remote)

Extend yaml :

field: # can be major | minor | patch | build
  val: 1 # value of field
  lead: 0 # format descriptor précision : n<2 or not set or null =  %d  | n>1  = %.nd (max 4)
  inc: 1 # val increment
  max: 255 # if at the next inc, val = 256, val return to 0, next field is incremented. 
  # major and build field ignore max.

Logic, (not tested), from scratch :

class TVersionBuilderField
{
  protected $_val; // field value
  protected $_lead; // lead zero control
  protected $_inc; // increment val
  protected $_max; // max value of val
  protected $_ignore; // ignore max value
  protected $_reset; // val < 0 or val > max, ctrl

  function __construct($aVal=0, $aLead=0, $aInc=1, $aMax=255, $aIgnore=false)
  {
    $this->_val    = $aVal;
    $this->_lead   = $aLead==0 ? '%d':'%.'.$aLead.'d'; // select the good descriptor
    $this->_inc    = $aInc;
    $this->_max    = $aMax;
    $this->_ignore = $aIgnore || $aMax == 0; // force ignore from null max
    $this->_reset   = false;
  }

  // return true if val has exceeded interval 0..max on last inc/dec call, else false.
  public function reset()
  {
    return $this->_reset;
  }

  // return raw value of val
  public function toInt()
  {
    return $this->_val;
  }

  // return val at hex format (without precision) 
  public function toHex()
  {
    return sprintf('%x', $this->_val);
  }

  // return val at string format (with or without precision : n, 0n, 00n ...)
  public function toStr()
  {
    return sprintf($this->_lead, $this->_val);
  }

  // controlled val incrementation
  function inc()
  {
    $this->_reset = false;
    $this->_val += $this->_inc;
    if( !$this->ignore )
    {
      $this->_reset = $this->_val > $this->_max;
      if( $this->_reset )
      {
        $this->_val = 0;
      }
    }
    return $this;
  }

  // controlled val decrementation
  function dec()
  {
    $this->_reset = false;
    $this->_val -= $this->_inc;
    $this->_reset = $this->_val < 0;
    if( $this->_reset )
    {
      $this->_val = !$this->ignore ? ($this->_max - $this->_val) : 0;
    }
    return $this;
  }
}

// main version class
class TVersionBuilder
{
  function __construct($aMajor, $aMinor, $aPatch)
  {
    $this->major = new TVersionBuilderField($aMajor, 0, 1, 0,  true);
    $this->minor = new TVersionBuilderField($aMinor, 2, 1, 99, false);
    $this->patch = new TVersionBuilderField($aPatch, 2, 1, 99, false);
  }

  // main inc caller, with auto fields inc.
  function inc()
  {
    if( $this->patch->inc()->reset() )
    {
      if( $this->minor->inc()->reset() )
      {
        $this->major->inc();
      }
    }
    return $this;
  }

  // main dec caller, with auto fields dec and no under-zero ctrl
  function dec()
  {
    if( $this->patch->toInt() > 0)
    {
      if( $this->patch->dec()->reset() )
      {
        if( $this->minor->toInt() > 0 )
        {
          if( $this->minor->dec()->reset() )
          {
            if( $this->major->toInt() > 0 ) $this->major->dec();
          }
        }
      }
    }
    return $this;
  }

  // return full version raw string like 1.1.1 or 1.02.03 or 1.2.034 ...
  function toStr()
  {
    return sprintf('%s.%s.%s', $this->major->toStr(), $this->minor->toStr(), $this->patch->toStr());
  }
}

What do you think ?

Remote repository not pulling from .env file if Laravel config is cached

Whenever the Laravel application config is cached (via php artisan config:cache) the VERSION_GIT_REMOTE_REPOSITORY setting in the .env is no longer available to the version.yml file. This is expected Laravel behavior as described here: https://laravel.com/docs/5.8/configuration#configuration-caching

Perhaps a better solution for handling the package config would be to have a standard config/version.php file and then only store the current version and build numbers in a version.yml file in the project root.

support Laravel 5.6

support Laravel 5.6?

Using version ^0.2.4 for pragmarx/version
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Can only install one of: laravel/framework[v5.6.0, 5.5.x-dev].
    - Can only install one of: laravel/framework[5.5.x-dev, v5.6.0].
    - Can only install one of: laravel/framework[5.5.x-dev, v5.6.0].
    - pragmarx/version v0.2.4 requires laravel/framework 5.5.* -> satisfiable by laravel/framework[5.5.x-dev].
    - Installation request for pragmarx/version ^0.2.4 -> satisfiable by pragmarx/version[v0.2.4].
    - Installation request for laravel/framework (locked at v5.6.0, required as 5.6.*) -> satisfiable by laravel/framework[v5.6.0].

version:refresh command issue in 1.0

I noticed that the version:refresh command has been removed in version 1.0. Is there an alternative we can use? Also, the documentation is out of sync as it still recommends to use version:refresh in a git hook.

version:absorb not reading latest commit hash

When running version:refresh or version:absorb, it should update build.number in the YAML file, but I can't seem to get it to update. I am on the master branch. I delete the .git directory in the distribution tarball since it ends up being about 50mb, without it, the tar is about 8mb. But that's an aside.

$ git log <snipped>

commit d63f0ee2f8f1c9078621a83da8692fe3d56df3ae (HEAD -> master, origin/master, origin/HEAD)

$ php artisan version:refresh

Version was refreshed.
phpvms version 7.0.0 (build 451e9e)

$ php artisan version:absorb
In Git.php line 46:

  No git tags not found in this repository

451e9e is from Dec 15th (crazy I didn't notice till now...). It was working when just running this:

php artisan version:show --format compact --suppress-app-name

But, not it's not updating at all. I'm not sure what's changed. My config is this:

version_source: config # "config", "git-local" or "git-remote"
current:
  major: 7
  minor: 0
  patch: 0
  git_absorb: git-local
  format: "{$major}.{$minor}.{$patch}"
build:
  mode: number
  number: 451e9e
  git_absorb: git-local
git:
  git-local: "git rev-parse --verify HEAD"
  git-remote: "git ls-remote {$repository}"
  branch: "refs/heads/master"
  repository: "{{ env('VERSION_GIT_REMOTE_REPOSITORY') }}"
  version:
    git-local: "git describe"
    git-remote: "git ls-remote {$repository} | grep tags/ | grep -v {} | cut -d \/ -f 3 | sort --version-sort | tail -1"
    matcher: "/[V|v]*[ersion]*\\s*\\.*(\\d+)\\.(\\d+)\\.(\\d+)\\.*(\\w*)/"
format:
  major: "{$major}"
  minor: "{$minor}"
  patch: "{$patch}"
  build: "{$build}"
  version: "{$major}.{$minor}.{$patch} (build {$build})"
  full: "version {{'format.version'}}"
  compact: "v{$major}.{$minor}.{$patch}-{$build}"
  ## add as many formats as you need !!!!

version:absorb to show local git commit hash (when git describe is empty)?

What I would like to achieve:

  • manually maintain major/minor/patch and timestamp
  • get commit hash from git

In my environment I don't have git versions / tags

$ git describe
fatal: No names found, cannot describe anything.

I created the default config/version.yml and when running php artisan version:absorb
I get the Exception GitTagNotFound.

I tried changing the commit mode as shown in the documentation:

commit:
    mode: git-local

php artisan version:absorb still results in Exception GitTagNotFound
Same when changing mode to increment.

How do I achieve this (manually maintain major/minor/patch and get commit from local git commit)?

Best way to approach my desired workflow

FYI - we use github, but we don't use tags/releases.

What I want to do is to be able to manually alter the major and minor numbers via artisan commands (mode: increment?), but have the patch number increment automatically with each commit.

Any thoughts on how best to approach this sort of thing? Thanks in advance!

package not working / trying to access array offset

Installed the package and copied the config file:

root@dev:/var/www/html/proj# php artisan vendor:publish --provider="PragmaRX\Version\Package\ServiceProvider"
Copied File [/vendor/pragmarx/version/src/config/version.yml] To [/config/version.yml]
Publishing complete.
root@dev:/var/www/html/proj# php artisan version:commit

   ErrorException

  Trying to access array offset on value of type null

  at vendor/pragmarx/version/src/package/Support/Increment.php:50
     46▕      */
     47▕     public function incrementCommit($by = null)
     48▕     {
     49▕         $result = $this->increment(function ($config) use ($by) {
  ➜  50▕             $increment_by = $by ?: $config['commit']['increment-by'];
     51▕
     52▕             $config['current']['commit'] = $this->incrementHex($config['current']['commit'], $increment_by);
     53▕
     54▕             return $config;

      +18 vendor frames
  19  artisan:37
      Illuminate\Foundation\Console\Kernel::handle()

The config file itself is the plain config file, no edits made:

mode: 'absorb' # or 'increment'
blade-directive: version
current:
  label: v
  major: 1
  minor: 0
  patch: 0
  prerelease:
  buildmetadata:
  commit: 100001
  timestamp:
    mode: absorb
    year:
    month:
    day:
    hour:
    minute:
    second:
    timezone:
commit:
  mode: absorb
  length: 6
  increment-by: 1
git:
  from: 'local' # or "remote"
  commit:
    local: 'git rev-parse --verify HEAD'
    remote: 'git ls-remote {$repository}'
  branch: refs/heads/master
  repository: '' ### you can use config() to get it here: {{ config('version.git.remote.repository') }}. Do not use env()
  version:
    local: 'git describe'
    remote: 'git ls-remote {$repository} | grep tags/ | grep -v {} | cut -d / -f 3 | sort --version-sort | tail -1'
    matcher: '/^(?P<label>[v|V]*[er]*[sion]*)[\.|\s]*(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/'
  timestamp:
    local: 'git show -s --format=%ci'
    remote: 'git show -s --format=%ci origin/master' ## we will have to find a better way
format:
  regex:
    optional_bracket: '\[(?P<prefix>.*?)(?P<spaces>\s*)(?P<delimiter>\?\=)(?P<optional>.*?)\]'
  label: "{$label}"
  major: "{$major}"
  minor: "{$minor}"
  patch: "{$patch}"
  prerelease: "{$prerelease}"
  buildmetadata: "{$buildmetadata}"
  commit: "{$commit}"
  version: 'version {$major}.{$minor}.{$patch} (commit {$commit})'
  version-only: 'version {$major}.{$minor}.{$patch}'
  ## Bracket enclosed expressions "[.?{$variable}]" are only rendered if the ?={$variable} is filled
  full: '{$version-only}[.?={$prerelease}][+?={$buildmetadata}] (commit {$commit})'
  compact: "v{$major}.{$minor}.{$patch}-{$commit}"
  timestamp-year: '{$timestamp.year}'
  timestamp-month: '{$timestamp.month}'
  timestamp-day: '{$timestamp.day}'
  timestamp-hour: '{$timestamp.hour}'
  timestamp-minute: '{$timestamp.minute}'
  timestamp-second: '{$timestamp.second}'
  timestamp-timezone: '{$timestamp.timezone}'
  timestamp-datetime: '{$timestamp.year}-{$timestamp.month}-{$timestamp.day} {$timestamp.hour}:{$timestamp.minute}:{$timestamp.second}'
  timestamp-full: '{$timestamp.year}-{$timestamp.month}-{$timestamp.day} {$timestamp.hour}:{$timestamp.minute}:{$timestamp.second} {$timestamp.timezone}'
  ## add as many formats as you need !!!!

The git folder is inside the project folder itself, default as usual.

ls -alh /var/www/html/proj/ | grep .git
drwxrwxr-x 7 dev www-data 4.0K Oct 24 12:29 .git

Any idea where things go wrong?
Running

root@dev:/var/www/html/proj# git rev-parse --verify HEAD
abec161d268c07....

Compatibility with php 7.2

Fresh install on MacOS, php 7.2, Laravel 5.5

after command

$ php artisan version:show

In Resolver.php line 33:

count(): Parameter must be an array or an object that implements Countable

Suppose one of dependency packages write this. May be "pragmarx/yaml"

Unable to get version number

when using blade directive: I got nothing

when showing version on php artisan: I got the app name

when trying to build: I got message:
Version is in git absorb mode, cannot be incremented

Not sure it is in absorb mode, since the config file have it false in all absorb options!

Conflict with Blade directives from other packages

Hi Antonio,

Thank you for your hard work, much appreciated.

I am using your package in a project with https://github.com/spatie/laravel-permission. Your version package declares the version directive in the register method and it seems to get the other directives to go away. I do not know all the internals but moving it to the boot method solved my problem. I can do a PR if this can be a suitable solution.

/**
     * Boot Service Provider.
     */
    public function boot()
    {
        $this->publishConfiguration();
        $this->registerBlade();
    }

Weird issue with commit number going hex on me

I have this in version.yml:

commit:
  mode: increment
  length: 6
  increment-by: 1

But when I move from commit number "10" to what should be "11", things move to "10e". Am I missing something?

`mode: git-local` not having any impact

I'm trying to use the git sha for the commit number by changing mode: git-local, but when I call php artisan version I get APP version 1.0.0 (commit 100001) instead of the sha. What am I doing wrong?

According to the documentation, I should run php artisan version:refresh but I get a command not defined error.

mode: 'absorb' # or 'increment'
blade-directive: version
current:
  label: v
  major: 1
  minor: 0
  patch: 0
  prerelease:
  buildmetadata:
  commit: 100001
  timestamp:
    mode: absorb
    year:
    month:
    day:
    hour:
    minute:
    second:
    timezone:
commit:
  mode: git-local
  length: 6
  increment-by: 1
git:
  from: 'local' # or "remote"
  commit:
    local: 'git rev-parse --verify HEAD'
    remote: 'git ls-remote {$repository}'
  branch: refs/heads/master
  repository: '' ### you can use config() to get it here: {{ config('version.git.remote.repository') }}. Do not use env()
  version:
    local: 'git describe'
    remote: 'git ls-remote {$repository} | grep tags/ | grep -v {} | cut -d / -f 3 | sort --version-sort | tail -1'
    matcher: '/^(?P<label>[v|V]*[er]*[sion]*)[\.|\s]*(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/'
  timestamp:
    local: 'git show -s --format=%ci'
    remote: 'git show -s --format=%ci origin/master' ## we will have to find a better way
format:
  regex:
    optional_bracket: '\[(?P<prefix>.*?)(?P<spaces>\s*)(?P<delimiter>\?\=)(?P<optional>.*?)\]'
  label: "{$label}"
  major: "{$major}"
  minor: "{$minor}"
  patch: "{$patch}"
  prerelease: "{$prerelease}"
  buildmetadata: "{$buildmetadata}"
  commit: "{$commit}"
  version: 'version {$major}.{$minor}.{$patch} (commit {$commit})'
  version-only: 'version {$major}.{$minor}.{$patch}'
  ## Bracket enclosed expressions "[.?{$variable}]" are only rendered if the ?={$variable} is filled
  full: '{$version-only}[.?={$prerelease}][+?={$buildmetadata}] (commit {$commit})'
  compact: "v{$major}.{$minor}.{$patch}-{$commit}"
  timestamp-year: '{$timestamp.year}'
  timestamp-month: '{$timestamp.month}'
  timestamp-day: '{$timestamp.day}'
  timestamp-hour: '{$timestamp.hour}'
  timestamp-minute: '{$timestamp.minute}'
  timestamp-second: '{$timestamp.second}'
  timestamp-timezone: '{$timestamp.timezone}'
  timestamp-datetime: '{$timestamp.year}-{$timestamp.month}-{$timestamp.day} {$timestamp.hour}:{$timestamp.minute}:{$timestamp.second}'
  timestamp-full: '{$timestamp.year}-{$timestamp.month}-{$timestamp.day} {$timestamp.hour}:{$timestamp.minute}:{$timestamp.second} {$timestamp.timezone}'
  ## add as many formats as you need !!!!

Getting Exception on reading version.yml

I'm getting the following exception when I try to use any command:

[Symfony\Component\Debug\Exception\FatalThrowableError]            
Call to undefined method Symfony\Component\Yaml\Yaml::parseFile()  

Thoughts on Changelog..?

Hi!
Looks like a neat package! Though i feel like versioning also comes with changelogs? What are your thoughts on that and is it anything you plan on adding as well?

PHP8

Hi,

When could we expect PHP8.0 support? This is our last package needing support.

Thanks.

No git tags found in this repository

I can't ever get this to work on my staging server. Working fine on local using git-local.

@php artisan version:refresh
In Git.php line 47:

No git tags found in this repository

Script @php artisan version:refresh handling the post-autoload-dump event returned with error code 1

Here is my version.yml file
version_yml_-roastar_com-___documents_laravel_homestead_sites_roastar_com

reset major, minor and patch values

Hey there, I'm using the package for a while on a project but now I'm trying to reset the values like minor and patch to zero. For example currently I have v 0.0.12, and with artisan version:patch get v 0.0.13. So far so good, now if I'm planning to release a new version like v 1.0.0...how can I reset the patch value? or automatically on minor or major increments it's reseted?

@version directive doesn't always work straight away

Laravel: 5.6.*
PHP: 7.1.*

The directive worked perfectly on our development environment straight away, but when transferred to the client's staging server we just saw the custom @Version('compact') blade directive.

Removed the vendor directory and reinstalled all packages but still no joy. Both servers could read/write to the configuration file, but it didn't render the content from the custom blade directive.

Despite no caching being configured on our development environment, the live environment required the views cache to be cleared using php artisan view:clear

It may be worth adding to the docs for reference.

php artisan version:refresh not defined

Hi, i read documentation to gain automate process of getting actual version from git repo. In docs is
php artisan version:refresh

This command throws Command "version:refresh" is not defined.. Do I something wrong or it's bug?

Increase app version with every git commit

I want assign the commit counts to patch number where:
git describe > v1.5.0-3-g41abd80
currently when running
php artisan version:show the result is: version 1.5.0 (build 41abd8)
I want the result to be version 1.5.3 (build 41abd8) where patch number equals to commit counts.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.