Setting version number automatically

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Setting version number automatically

Post 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?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Setting version number automatically

Post by Christopher »

What kind of 'repository' are you using?
(#10850)
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Setting version number automatically

Post by Benjamin »

I'm using SVN.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Setting version number automatically

Post by Christopher »

I think most projects put the version number in the branch name.
(#10850)
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Setting version number automatically

Post 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.
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Re: Setting version number automatically

Post 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 :lol: )

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
Last edited by Zoxive on Thu Feb 14, 2008 5:40 pm, edited 1 time in total.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Setting version number automatically

Post by Benjamin »

Awesome, I'll do some digging around and see if I can do that from within Eclipse then.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Setting version number automatically

Post 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.
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Re: Setting version number automatically

Post 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.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Setting version number automatically

Post 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.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Setting version number automatically

Post 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:

Code: Select all

phing package
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...
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Setting version number automatically

Post 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.
phaitour
Forum Newbie
Posts: 3
Joined: Tue Feb 19, 2008 2:40 am

Re: Setting version number automatically

Post 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!
vain
Forum Newbie
Posts: 3
Joined: Tue Feb 19, 2008 5:04 pm

Re: Setting version number automatically

Post 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.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: Setting version number automatically

Post by Chris Corbyn »

Are svn revision numbers really that useful in public versioning? They're quite monstrous numbers ;)
Post Reply