![Github]()
What is GitHub?
GitHub is a web-based platform that helps developers store, manage, and collaborate on code using Git version control. It allows multiple developers to work on a project simultaneously, Also it elps to track changes, and maintain code history.
What are GitHub Actions?
GitHub Actions is an automation tool that allows developers to create CI/CD (Continuous Integration/Continuous Deployment) pipelines. It helps automate various development tasks like testing, building, and deploying applications.
What is a GitHub Workflow?
A GitHub Workflow is a set of automated tasks defined in a YAML file. It runs when triggered by specific events, such as pushing code to a repository, creating a pull request, or setting up a schedule. Workflows help in automating repetitive tasks like testing, code analysis, and deployment.
What is a GitHub Runner?
A GitHub Runner is a virtual machine that executes jobs specified in a GitHub Actions workflow. GitHub provides both hosted runners (free-tier available) and self-hosted runners (custom machines for private execution).
If you want to learn more about GitHub Action then please check out the official documentation.
Why Use GitHub Actions and Workflows?
GitHub Actions and Workflows help automate software development, making the process faster and easier. Here’s why they are useful.
- Saves Time: Runs tests, builds, and deploys applications automatically.
- Boosts Productivity: Reduces manual work, so developers can focus on coding.
- Improves Teamwork: Helps teams work together smoothly without conflicts.
- Flexible & Scalable: Can be customized to work with cloud platforms like Azure, AWS, and Google Cloud.
Step-by-Step Guide to Setting Up a GitHub Action with a Runner
Step 1. Create a GitHub Repository.
- Go to GitHub and log in.
- Click on New Repository.
- Enter a name (e.g., github-actions-demo).
- Select Public or Private, and click Create Repository.
![Create Repository]()
![Name]()
Step 2. You need the host to deploy and run the GitHub Runner which is needed to execute the jobs of our workflow. So, for that,t we gonna create a new VM for the same.
Create an Azure Virtual Machine (VM)
- Go to Azure Portal → Virtual Machines → Click Create → Virtual Machine.
- Choose Basic Configuration.
![Basic Configuration]()
![Create VM]()
![VM Config]()
![VM Name]()
- Click Review + Create → Create.
Connect to the VM
Click on the VM instance in azure and there in the side navbar you can see connect option. So, using that option to connect with your VM.
Step 3. Set Up a GitHub Self-Hosted Runner.
By default, GitHub provides free hosted runners, but here we'll set up a self-hosted runner on your local machine.
1. Navigate to Runner Settings
- Go to GitHub Repository → Settings → Actions → Runners.
- Click New self-hosted runner.
![Hosted runner]()
![Runners]()
2. Choose the Operating System
Select your OS (Windows, macOS, or Linux).
3. Download and Configure the Runner
To download and configure the GitHub Runner. First, you have to connect with the VM that we created previously and once the connection is successful then you can execute the commands which are visible on the runner creation page.
Follow the provided commands.
mkdir actions-runner && cd actions-runner
curl -o actions-runner-linux-x64.tar.gz -L \
https://github.com/actions/runner/releases/download/v2.308.0/actions-runner-linux-x64-2.308.0.tar.gz
tar xzf ./actions-runner-linux-x64.tar.gz
4. Configure the Runner
Use the provided command with your repository’s token:
./config.sh --url https://github.com/your-username/github-actions-demo --token YOUR_TOKEN
5. Start the Runner
./run.sh
![Start the Runner]()
Your self-hosted runner is now active and ready!
Step 4. Set Up GitHub Actions Workflow.
In your GitHub repository, create a file.
.github/workflows/test-runner.yml
Add this simple workflow to verify the runner.
name: Test Self-Hosted Runner
on:
- push
jobs:
test:
runs-on: self-hosted
steps:
- name: Print Hello
run: echo "Hello from Azure VM Runner!"
Push a change to your repository and check the Actions tab in GitHub.
You should see the job running on your Azure VM!
Note. You might get some errors initially in the workflow due unavailability of node js and a few other things. So, please installed that on by one on your VM.
![Azure VM]()
![Create test runner]()
![Print]()
Conclusion
GitHub Actions and Workflows provide a seamless way to automate software development processes, reducing manual effort and improving efficiency. By using self-hosted runners, developers can execute workflows on their own infrastructure, ensuring better control over resources. With GitHub Actions, teams can enhance collaboration, streamline CI/CD pipelines, and deploy software with greater reliability and security.