Skip to content

Instantly share code, notes, and snippets.

@mike-boddin
Last active December 16, 2015 10:40
Show Gist options
  • Select an option

  • Save mike-boddin/e323916cd34c280a54b2 to your computer and use it in GitHub Desktop.

Select an option

Save mike-boddin/e323916cd34c280a54b2 to your computer and use it in GitHub Desktop.

Revisions

  1. mike-boddin revised this gist Dec 16, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion post-receive
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    #!/bin/bash
    # post-receive

    ### STEP 1: Load some convinient functions ####################################
    ### STEP 1: Load some convenient functions ####################################

    # import base_functions
    # it provides: log, print_baseline, quit
  2. mike-boddin created this gist Dec 16, 2015.
    19 changes: 19 additions & 0 deletions base_functions
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    #!/bin/bash
    # base_functions

    function print_baseline {
    echo "#"
    echo "########################################################################"
    echo "#"
    }

    function log {
    echo "# $@"
    }

    function quit {
    print_baseline
    exit 0
    }

    print_baseline
    52 changes: 52 additions & 0 deletions post-receive
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,52 @@
    #!/bin/bash
    # post-receive

    ### STEP 1: Load some convinient functions ####################################

    # import base_functions
    # it provides: log, print_baseline, quit
    source `pwd`/${0%/*}/base_functions


    ### STEP 2: Set params ########################################################

    # production-path to copy content to
    PRODUCTION_PATH=~/html

    # read stdin into an arry, split by whitespace
    IFS=' ' read -a INPUT

    #previous commit id
    ID_BEFORE=${INPUT[0]}
    # new commit id
    ID_AFTER=${INPUT[1]}
    # branch
    BRANCH=${INPUT[2]}
    # the version we want to print to the version-file
    VERSION=${ID_AFTER:0:7}
    # the version-file
    VERSION_FILE=version.txt


    ### STEP 3: check the branch (we only want to process the master-branch) ######

    # if not the master-branch was pushed --> exit
    if ! [[ $BRANCH == *master ]] ; then
    log this is the ${BRANCH##*/}-branch, no additional action
    log if you want to deploy to production, please push to the master-branch
    quit
    else
    log push to master, the content will be deployed to production
    fi


    ### STEP 4: copy over the content #############################################

    # copy over content to production
    export GIT_WORK_TREE=$PRODUCTION_PATH
    git checkout -f
    # add version information
    echo $VERSION > $PRODUCTION_PATH/$VERSION_FILE

    log production updated to version $VERSION
    quit