对于从 SVN 进行部署并自动将版本号写入我的代码有什么建议吗?

发布于 2024-07-06 07:14:13 字数 96 浏览 12 评论 0原文

我已经习惯了 SVN,现在我需要一种方法来更轻松地将代码部署到临时服务器或实时服务器。 我还想要一些方法将构建信息放入该网站的页脚中以帮助测试。 站点是 PHP/MySQL。

I've gotten comfy with SVN, and now I need a way to deploy my code to staging or live servers more easily. I'd also like some method for putting build info in the footer of this site to aid in testing. Site is PHP/MySQL.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

梅倚清风 2024-07-13 07:14:13

首先为您希望存储修订信息的文件启用关键字替换:

svn propset svn:keywords "Rev" file.txt

添加到您希望存储修订信息的文件:

$Rev$

进一步阅读:http://svnbook.red-bean.com/en/1.4/svn.advanced.props.special.keywords.html< /a>

First enable keyword substitution for a file where you wish to have the revision info:

svn propset svn:keywords "Rev" file.txt

The add to the file where you want the Revision info stored:

$Rev$

Further readings: http://svnbook.red-bean.com/en/1.4/svn.advanced.props.special.keywords.html

此岸叶落 2024-07-13 07:14:13

属性方法只会为您提供包含该属性的文件的最后修订版本号,而不是整个存储库的头部修订版本(如 Stack Overflow 页脚)。 如果您想要的话,您需要使用 svn版本

我最近开始在一个项目中使用 Capistrano,它非常棒,非常灵活和强大。 我最终偏离了它的正常用法,但它使一键式部署变得更加容易。

The properties methods will only give you the last revision number of the file you have the property in, not the head revision of the whole repository (a la the Stack Overflow footer). If you are wanting that, you'll need to use svnversion.

I recently started using Capistrano on a project and it superb and very flexible and powerful. I ended up deviating quite far from its normal usage, but it makes one "click" deployment much easier.

苍景流年 2024-07-13 07:14:13

如果您想更新项目 AssemblyInfo.cs 中的版本号,您可能对本文感兴趣:

CodeProject:在 Visual Studio 项目中使用 Subversion 修订版号

如果您启用 SVN 关键字,那么每次您签入项目时,Subversion 都会扫描您的文件以查找某些“关键字”,并用一些信息替换关键字。

例如,在源文件的顶部,我将创建一个包含以下关键字的标头:

'$作者:$
'$Id:$
'$Rev:$

当我将此文件签入 Subversion 时,这些关键字将替换为以下内容:

'$作者:paulbetridge$
'$Id: myfile.vb 145 2008-07-16 15:24:29Z 保罗贝特里奇 $
'$Rev: 145 $

If you want to update the version number in a projects AssemblyInfo.cs you may be interested in this article:

CodeProject: Use Subversion Revision numbers in your Visual Studio Projects

If you enable SVN Keywords then every time you check in the project Subversion scans your files for certain "keywords" and replaces the keywords with some information.

For example, At the top of my source files I would create a header contain the following keywords:

'$Author:$
'$Id:$
'$Rev:$

When I check this file into Subversion these keywords are replaced with the following:

'$Author: paulbetteridge $
'$Id: myfile.vb 145 2008-07-16 15:24:29Z paulbetteridge $
'$Rev: 145 $

从来不烧饼 2024-07-13 07:14:13

根据需要进行 svn 更新的脚本。

SVN 支持关键字。 您可以将要扩展的关键字添加到 keywords 属性,然后 SVN 将扩展。 请参阅 $Id$ 或 $Rev$,或 SVN 书中描述的关键字。

A script to svn update on an as needed basis.

SVN supports keywords. You can add which keywords you want to expand to the keywords property, and SVN will expand then. See $Id$ or $Rev$, or keywords described in the SVN book.

复古式 2024-07-13 07:14:13

我喜欢使用 capistrano 进行推送。 请参阅此处

您可以使用 SVN $Rev$ 属性将修订号放入页脚中。

I'm a fan of using capistrano for pushes. Refer to here.

You could use the SVN $Rev$ property to get the revision number into your footer.

末が日狂欢 2024-07-13 07:14:13

管理此问题的一个非常简单的方法是通过以下方式设置您的应用程序:

只需将您的部署应用程序制作为主干的工作副本(svn co 项目到您的 /www 根目录),然后运行通过 ssh 控制台 svn up (ssh [email  protected] svn up /path/to/project) 当您需要更新时。 您还可以使用适当的签出机制进行回滚。 这很重要:如果您这样做,请将 RewriteRules (或等效项)添加到您的 .htaccess (或等效项)以禁止访问 .svn 目录。 如果您无法执行上述操作,请改为通过 ssh 运行 svn export (因此它不会是“工作副本”),但这自然会比执行 up 慢

另外,您可以查看 Ruby on Rails 与 Capistrano 的功能。它的基本概念相同,但如果更新在中间出错,则通过将每个签出存储在单独的文件夹中并将“最新”符号链接到您的 /www 来支持事务备份目录。

A really simple way to manage this is to setup your app in the following way:

Simply make your deployment app a working copy of your trunk (svn co the project to your /www root) and you run an svn up through an ssh console (ssh [email protected] svn up /path/to/project) when you need to update. You can also rollback with the appropriate checkout mechanisms. This is important: if you do this, add RewriteRules (or equivalent) to your .htaccess (or equivalent) to disallow access to .svn directories. If you can't do the above, run an svn export through ssh instead (so it won't be a 'working copy'), but this will naturally be slower than doing an up.

Also, you can look at what Ruby on Rails does with Capistrano.. it's the same basic concept but supports transactional backups if the update goes wrong in the middle by storing each checkout in a separate folder and symlinking the "latest" to your /www directory.

似狗非友 2024-07-13 07:14:13

在很多情况下,关键字内容都会失败 - 例如,如果您在部署之前修改了源代码,或者如果您从项目中的一个目录签入,那么同一项目中的不同目录将具有不同的修订号。 仔细检查文档,确保关键字符合您的预期。

更好的方法是使用 svnversion 程序来生成有关您的信息在编译或部署时检出目录。 svnversion 将显示有关所有目录的版本的信息,并标记源是否在本地修改。

The keywords stuff will fail in plenty of cases -- like if you've modified the source before deploying, or if you check in from one directory in your project then a different directory in the same project will have different revision numbers. Check the docs carefully to make sure the keywords do what you think they do.

The better way is to use the svnversion program to generate information about your checked out directories at compile or deployment time. Svnversion will show information about the version of ALL of your directories as well as flagging whether or not the source was locally modified.

第几種人 2024-07-13 07:14:13

我为我的 php 项目提出的方法可能不是最好的方法,但经过一段时间的搜索似乎确实是最好的方法,即进行结帐,运行版本检查,清除 .svn 文件夹,然后继续。 这是我编写的 shell 脚本的一部分:(

首先,您需要该脚本来签出您的存储库)

# get the svn revision number and create a RELEASE file
svnvers=`svnversion .`
echo "version: $svnvers"
echo "<release><development>0</development><revision>$svnvers</revision></release>" > RELEASE

# remove all .svn directories
find . -name .svn -exec rm -rf {} \;

The method I've come up for my php projects, may not be the best method but after some time searching certainly seems to be, is to do a checkout, run a version check, wipe out the .svn folders, and move on. Here is a portion of shell script I've written:

(first, you need the script the checkout your repo)

# get the svn revision number and create a RELEASE file
svnvers=`svnversion .`
echo "version: $svnvers"
echo "<release><development>0</development><revision>$svnvers</revision></release>" > RELEASE

# remove all .svn directories
find . -name .svn -exec rm -rf {} \;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文