使用post-receive hook创建一个zip

时间:2012-12-18 11:18:16

标签: git git-bash git-post-receive

我一直在玩钩子一段时间,但我似乎无法让post-receive钩子以我需要的方式工作。

我试图让post-receive挂钩创建一个zip文件夹,并在我将更改推送到存储库后将其放在git存储库文件夹之外的某个位置。

1 个答案:

答案 0 :(得分:7)

您有一个很好的例子,可以通过this article Daniel Byrne中的git archive --format=zip部署邮政收款钩:

我们的想法是使用 {{3}}

#!/bin/bash
#
# A post commit hook that takes any updates pushed to the 'release' branch
# and creates a release directory for the new version under the webroot.
# Live site is then symlinked to this new release directory.

oldrev=$1
newrev=$2
branch=$3

# this is the root of the website (a symlink to a release directory)
webroot=/var/www/danielbyrne.net/www

if [ "$branch" == "release" ]
then

    # create a release directory to extract files into
    target=/var/www/danielbyrne.net/releases/$2/
    mkdir $target

    echo "Making target directory: $target"

    # create an archive in the webroot of danielbyrne.net
    /usr/bin/git archive master --format zip --output $target/deploy.zip

    echo "unzipping archive..."

    # extract the archive
    unzip -o -q $target/deploy.zip -d $target

    echo "removing deployment archive"

    # remove the archive file
    rm $target/deploy.zip

    echo "switching symbolic link to $target"

    # now switch the live site to point to the new release
    ln -nsf $target $webroot

    echo "done";
fi