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?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
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):
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
From this answer:
You can get close with SVN Keywords. Add $Revision$ where you want the revision to show, but that will only show the last revision that particular file was changed, so you would have to make a change to the file each time. Getting the global revision number isn't possible without some sort of external script, or a post-commit hook.
The easiest way is to use the Subversion "Keyword Substitution". There is a guide here in the SVN book (Version Control with Subversion).
You'll basically just have to add the text $Rev$ somewhere in your file. Then enable the keyword in your repository. On checkout SVN will substitute the revision number into the file.
If performance is an issue, then you could do:
This of course depends on your having done a checkout, and the presence of the svn command.
You could also do it like this: