Have you ever wondered how non-tech guys have such impressive contribution stats on their Github profiles? Yes, they have set up a GitHub bot that uploads the same file over and over again to the GitHub repo.
This piece of content is a part of my “automation” manifesto, which I declare here: I would automate everything with Python from now on.
- Create git repository on GitHub
- VPS with Git init folder to the remote repository
- GitHub ssh key set up
- Proper crontab job for your bot
Bot consists of 2 files, the main file on Python, which generate the file(will be uploaded to GitHub) and the bash file, which will run this python script and execute the “git commands”(git commit, git push to the remote origin)
How to Create an SSH Key
To use an SSH key with Git, you must first create the key on your computer. If you already have an SSH key, you can skip these steps. To check if you have a key, you can run this command:
bro@server# ssh-add -l
Follow along with the steps below to create the key and copy its contents. You will need to open your computer’s default terminal application.
- Open the terminal app on your computer.
- Enter the following command, substituting firstname.lastname@example.org with your email address:
bro@server# ssh-keygen -t rsa -b 4096 -C "email@example.com"
- Press Enter to accept the default file location.
- Enter a secure passphrase.
- Press Enter.
- Enter this command to display the contents of your public key:
bro@server# cat .ssh/id_rsa.pub
- Copy the contents of your key to your clipboard (we will need it later).
It’s important to remember that the SSH key has two parts: a private key and a public key. As the name suggests, the private key is only for private use. Never share your private key with anyone (with exceptions made for your system administrator or other trusted people within your organization). This will be important later.
Init your folder on the VPS with git
First, you create a repository in the GitHub profile, then switch to your VPS, select a folder and init it.
How to init a folder on remote VPS:
To set a crontab job you can use those commands: crontab -e or nano /etc/crontab
this is my command from the crontab, each hour on 11 minutes – cron will run rand_gen.sh script, that script will execute python code from rand_gen.py and after git adds/ git commit/ git push to the origin repository.
11 * * * * root /bin/sh /home/pythonscripts/9autocommit/rand_gen.sh
GitHub repo with python and bash code: https://github.com/webprice/9autocommit
Github Gist with code: https://gist.github.com/webprice/faeffaae5d7d01747a3cd6a12171d60c