Webhook to auto-deploy on git push to Github

What is a webhook? A webhook is an endpoint on your server which allows you to execute a particular task. Webhooks are usually triggered by some event. A good use-case for a webhook is running tests on a dedicated test server or deploying your latest master branch to staging/production. Github / Gitlab / Bitbucket allow you to specify a webhook URL in your repository settings. Github triggers the webhook which sends the event data on every push. Webhook server Webhook is a very useful golang project which runs any script you specify when a particular endpoint is hit. Download and extract the binary for your operating system from the releases page. For Linux, it is here. The program takes as config a hooks.json file: [ { "id": "hello-world", "execute-command": "/home/user/scripts/hello.sh", "command-working-directory": "/home/user/webhook" } ] Replace user with the username of your linux user. The hello.sh script. #!/bin/bash echo 'Hello!' Make the script executable by running chmod +x hello.sh Start webhook server as webhook -hooks hooks.json -hotreload -logfile webhooks.log. The server will run on port 9000 by default. You can check if everything is working by running curl http://localhost:9000/hooks/hello-world. This will print “Hello!” in the log file. ...

May 25 2020 · 3 min · Raunak

Git Tagging Tutorial

I read a post on dev.to which shows how to create git tags using GUI-based git clients. I think that tags are useful to know even when using the git cli. What are tags Tags are specific points in your code history which are useful to re-visit later e.g you just released a new version of your app. You can tag the commit as v1.0 using git tag v1.0. Anytime you want to reproduce bugs encountered on that version, simply do git checkout v1.0 and investigate. How to use git tag better Checkout code to the tag The tag is linked to the specific commit and not to a branch. When you checkout the tag, git tells you that you are in “detached HEAD” state. Do not worry, all it means is that you need to create a new branch if you want to retain any changes you make after checking out the tag. Create a new branch exactly at the commit of the tag using git checkout -b BRANCH_NAME TAG_NAME ...

November 22 2018 · 3 min · Raunak

Git: How to keep your fork updated with remote repository

This is useful when you have forked a repository (repo), cloned it to your local machine and want to keep it in sync with the original repo. Adding the remote repo We can list the remote repositories for our repo with git remote -v and add the original repo as follows: git remote add upstream LINK_TO_ORIGINAL_REPO Note that it is merely a convention to call it upstream. You can give any name you want. Check that the repo is added to your remote using git remote -v. Sync with remote Check if there are any changes in remote not on your fork using git fetch upstream Checkout whichever branch you are interested ( git checkout $BRANCH) Merge with upstream using: git merge upstream/$BRANCH Push your changes to origin if needed: git push origin $BRANCH Removing the remote repo If you no longer want to get changes from the remote repo, it is easy to remove it using git remote remove upstream ...

November 9 2018 · 1 min · Raunak