Page 1 of 2
Setting version number automatically
Posted: Thu Feb 14, 2008 4:52 pm
by Benjamin
I have been defining the version number for applications that I write as a constant. Whenever I commit changes to the repository I increment the version number manually.
Is there a way to do this automatically?
Re: Setting version number automatically
Posted: Thu Feb 14, 2008 4:54 pm
by Christopher
What kind of 'repository' are you using?
Re: Setting version number automatically
Posted: Thu Feb 14, 2008 4:56 pm
by Benjamin
I'm using SVN.
Re: Setting version number automatically
Posted: Thu Feb 14, 2008 5:19 pm
by Christopher
I think most projects put the version number in the branch name.
Re: Setting version number automatically
Posted: Thu Feb 14, 2008 5:28 pm
by Benjamin
Yeah that makes sense. I'm guessing there isn't a way to have it auto update the version number inside the code then.
Re: Setting version number automatically
Posted: Thu Feb 14, 2008 5:36 pm
by Zoxive
astions wrote:Yeah that makes sense. I'm guessing there isn't a way to have it auto update the version number inside the code then.
Oh there is. There is a lot of information that can be updated with SVN. (You can even set your own custom Keywords)
Code: Select all
svn propset --recursive svn:keywords 'URL HeadURL Author Id Revision LastChangedBy Date' .
Is the command i normally use, which sets all files with the keywords in the quotation marks. (I have it as a cronjob, as well as generate tags every 10 minutes so it updates the files im working on

)
You can then put $Revision$ In your code on the page(s) that you set the properties on, and it will change every time it is commited.
But it sounds like you would just like
Code: Select all
svn propset svn:keywords 'Revision' index.php
Re: Setting version number automatically
Posted: Thu Feb 14, 2008 5:40 pm
by Benjamin
Awesome, I'll do some digging around and see if I can do that from within Eclipse then.
Re: Setting version number automatically
Posted: Fri Feb 15, 2008 12:54 am
by Chris Corbyn
I'm actually thinking of using Ant to manage my project. You could certainly do it with that. But it's a bit overkill. the main reason I'll be using it is because I want to have targets to generate documentation, run tests prior to packaging, and most importantly, bundle up a bunch of classes from various repositories (== pain the but).
I'd use Phing, but I already know how to use Ant and don't really have the time to spend learning what is probably less powerful.
Re: Setting version number automatically
Posted: Fri Feb 15, 2008 3:04 am
by Maugrim_The_Reaper
I am hurt at the lack of affection for Phing. Bad Chris!
At the moment I use Phing for nearly all my PHP projects. I got a few documentation tasks for the current version patched by the Phing team so I can now generate Docbook XHTML documentation from source completely in PHP without a single system call. That's how it's done for
the PHPSpec Manual for example.
Re: Setting version number automatically
Posted: Fri Feb 15, 2008 3:13 am
by Benjamin
I'm not familiar with Phing. Guess I'll check out the Phing. I've already got all my codebases in SVN though. I don't think I'd want to move everything over, especially if I lost the revision &|| history.
Re: Setting version number automatically
Posted: Fri Feb 15, 2008 8:34 pm
by Chris Corbyn
Sorry Pádraic, I'll check it out... it's just when you already know how to use something else which is bascially intended for the same task you'll generally just stick with that
~astions, Phing and Ant are much the same thing. They are used to manage projects... packaging up files, running tests, compiling source code etc. They're a bit like GNU "./configure + make" bundled into something much easier to use. Ant is not intended for use with PHP (it's for Java projects so knows how to compile Java code), whereas Phing was written for just that.
They're entirely independent of where you store your code so there would be no need to stop using SVN. You can probably even get Phing to checkout the code from SVN prior to packing (I know ant can).
Typically you have some build script which defines targets for "test", "compile", "package" etc and you just run:
Or something to that effect.
With ant you'll generally do something like:
Code: Select all
ant compile test #build source files and run tests
The idea behind both projects is that you define how files are bundled, where they come from etc...
Re: Setting version number automatically
Posted: Fri Feb 15, 2008 8:57 pm
by Benjamin
Ah ok, thanks for the clarification. At this point I don't think that is something I would need, although I can see how it would be useful.
Re: Setting version number automatically
Posted: Tue Feb 19, 2008 2:44 am
by phaitour
Hi Zoxive,
Thank you for your reply to this thread! You're introduction to svn:keywords have been most helpful!
I'm curious about two things:
1) How do you define your own (custom) keywords?
2) Can you describe in more detail what your script does? The one that you described, which helps update the file you're updating every ten minutes.
The reason why I ask is because I'm looking for a way to dynamically add the subversion HEAD revision number to a particular file (as opposed to the current revision number of the file, which is what the $Revision$ does). Do you know of a way to do this?
Thanks in advance!
Re: Setting version number automatically
Posted: Tue Feb 19, 2008 5:23 pm
by vain
Hello phaitour,
the number of keywords SVN understands is limited, afaik.
So you simply can't define your own (custom) keywords.
When you want to dynamically add the subversion HEAD revision number to a particular file, you could use the command "svn log -q -v -rHEAD <URI>" and perform grep or some regexp's on the informations given.
And there is also Phings SvnLastRevisionTask to get the Revision Number into a property, for further processing.
Re: Setting version number automatically
Posted: Tue Feb 19, 2008 8:18 pm
by Chris Corbyn
Are svn revision numbers really that useful in public versioning? They're quite monstrous numbers
