Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the Subversion revision number in PHP?

Tags:

php

svn

revision

I want to have my PHP application labeled with the revision number which it uses, but I don't want to use CruiseControl or update a file and upload it every time. How should I do it?

like image 425
Thomaschaaf Avatar asked Sep 21 '08 17:09

Thomaschaaf


People also ask

How do I find my svn revision number?

"svn info --show-item revision" will give the current revision to which the current directory is updated.

How do I find my svn revision history?

To find information about the history of a file or directory, use the svn log command. svn log will provide you with a record of who made changes to a file or directory, at what revision it changed, the time and date of that revision, and, if it was provided, the log message that accompanied the commit.

How do I find my svn revision number in Jenkins?

1 Answer. "http://your-jenkins-host/env-vars.html/" and you'd find a constant called "SVN_REVISION" Each job build will keep the SVN revision in the given variable.

How does svn revision number work?

Each time the repository accepts a commit, this creates a new state of the filesystem tree, called a revision. Each revision is assigned a unique natural number, one greater than the number assigned to the previous revision.


1 Answers

SVN keywords is not a good solution. As others pointed out adding $Revision$ in a file only affects the specific file, which may not change for a long time.

Remembering to "edit" a file (by adding or removing a blank line) before every commit is pointless. You could as well just type the revision by hand.

One good way to do it (that I know of) is to have an automated deployment process (which is always a good thing) and using the command svnversion. Here is what I do:

Wherever I need the revision I do an include: <?php include 'version.php'; ?>. This "version.php" file only has the revision number. Moreover it is not part of the repository (it set to be ignored). Here is how I create it:

1) On projects where SVN is installed on the server, I also use it for deployment. Getting the latest version to the server I have a script that among other things does the following (it runs on the server):

cd /var/www/project svn update rm version.php svnversion > version.php 

2) On projects where SVN is not installed my deployment script is more complex: it creates the version.php file locally, zips the code, uploads and extracts it

like image 157
daremon Avatar answered Sep 19 '22 22:09

daremon