Skip to content

Commit

Permalink
feat: add post-receive hook
Browse files Browse the repository at this point in the history
  • Loading branch information
aitemr committed Jan 13, 2019
1 parent 8e72e7f commit 9dddb32
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
24 changes: 24 additions & 0 deletions post-receive/README.md
@@ -0,0 +1,24 @@
## post-receive

This is run on the remote when pushing after the all refs have been updated. It does not take parameters, but receives info through stdin in the form of "<old-value> <new-value> <ref-name>". Because it is called after the updates, it cannot abort the process.

## invoked by

```bash
git-receive-pack
# on the remote repo
```

## post-receive git hooks for:

* [post-receive-specific-folder](https://github.com/aitemr/awesome-git-hooks/blob/master/post-receive/post-receive-specific-folder) - hook to deploy the code being pushed to production branch to a specific folder

## support

If you have a question, find a bug, or just want to say hi, please open an [issue on GitHub](https://github.com/aitemr/awesome-git-hooks/issues/new)

## license

[![CC0](http://mirrors.creativecommons.org/presskit/buttons/88x31/svg/cc-zero.svg)](https://creativecommons.org/publicdomain/zero/1.0/)

To the extent possible under law, [Islam Temirbek](https://aitemr.github.io) has waived all copyright and related or neighboring rights to this work.
22 changes: 22 additions & 0 deletions post-receive/post-receive-specific-folder
@@ -0,0 +1,22 @@
#!/bin/bash

target_branch="production"
working_tree="PATH_TO_DEPLOY"

while read oldrev newrev refname
do
branch=$(git rev-parse --symbolic --abbrev-ref $refname)
if [ -n "$branch" ] && [ "$target_branch" == "$branch" ]; then

GIT_WORK_TREE=$working_tree git checkout $target_branch -f
NOW=$(date +"%Y%m%d-%H%M")
git tag release_$NOW $target_branch

echo " /==============================="
echo " | DEPLOYMENT COMPLETED"
echo " | Target branch: $target_branch"
echo " | Target folder: $working_tree"
echo " | Tag name : release_$NOW"
echo " \=============================="
fi
done

0 comments on commit 9dddb32

Please sign in to comment.