IS IT POSSIBLE TO RUN GITHUB ACTIONS LOCALLY ?

Manali Jain
8 min readFeb 19, 2023

--

Is it possible to run git-actions locally or you need to commit/push each fix every time and then run git-actions to see whether the fix is good to go or not ?

Before starting let’s see #What is git-actions?

GIT_ACTIONS

“Git Actions” likely refers to GitHub Actions, which is a feature of the Git version control system provided by GitHub.

GitHub Actions is a continuous integration and continuous delivery (CI/CD) platform which allows you to automate tasks, build, test, and deploy your code directly from GitHub. You can create workflows, which are defined in a YAML file, that specify a series of steps to run in response to specific events, such as when code is pushed to a repository, a pull request is created, or a release is published.

Workflows can be used to do things like run tests on your code, deploy your application to a production environment, and notify your team when certain events occur. GitHub provides a variety of pre-built actions that you can use in your workflows, or you can create your own custom actions.

GitHub Actions can help you to save time and improve the quality of your code by automating repetitive tasks and catching errors early in the development process.

GitHub Actions is a powerful tool for streamlining your development process, and it is integrated directly into the GitHub platform, making it easy to use and accessible to all GitHub users.

GitHub Actions can be used for a wide variety of tasks related to the software development workflow. Some common use cases include:

  1. Continuous Integration (CI): GitHub Actions can be used to run automated tests and checks whenever changes are made to the codebase. This helps to catch errors early in the development process and ensures that the code is always in a working state.
  2. Continuous Deployment (CD): GitHub Actions can be used to automate the process of deploying code to production environments, making it faster and more reliable.You can use Actions to automate tasks such as building Docker images, deploying to cloud platforms like AWS or Azure, and managing serverless functions.
  3. Code Quality: GitHub Actions can be used to perform code analysis and quality checks, such as linting, code coverage, and security scanning.You can use pre-built actions or create your own custom actions to perform these checks, and set up workflows to ensure that they are run automatically on every pull request or commit.
  4. Issue Management: GitHub Actions can be used to automate the process of triaging and managing issues, such as assigning issues to team members and sending notifications when new issues are created.
  5. Release Management: GitHub Actions can be used to automate the process of creating and publishing releases, including generating release notes and notifying users when new releases are available.
  6. ChatOps: GitHub Actions can be used to integrate with chat platforms like Slack or Microsoft Teams, allowing team members to trigger actions and receive notifications directly in their chat channels.

These are just a few examples of the many ways that GitHub Actions can be used to automate and streamline the software development workflow. With its flexibility and extensibility, GitHub Actions can be customised to meet the specific needs of your project and team.

FEATURES OF GIT-ACTIONS

“Git Actions” is not a common term or feature in the Git version control system. It is possible that you meant to ask about “GitHub Actions,” which is a feature of the GitHub platform. Here are some key features of GitHub Actions:

  1. Continuous Integration (CI) and Continuous Deployment (CD): GitHub Actions allows you to automate the process of building, testing, and deploying your code. Workflows can be triggered by events such as pushing code to a repository or creating a pull request.
  2. Customizable workflows: GitHub Actions provides a YAML-based syntax for defining workflows, which can be customised to meet the specific needs of your project and team.
  3. Pre-built actions: GitHub provides a variety of pre-built actions that can be used in your workflows, such as running tests, building Docker images, and deploying to cloud platforms.
  4. Custom actions: You can create your own custom actions using Docker containers, JavaScript, or any executable file format.
  5. Event-driven automation: GitHub Actions allows you to trigger workflows in response to a wide range of events, such as new issues or pull requests, code pushes, or scheduled events.
  6. Integrated with GitHub: GitHub Actions is fully integrated with the GitHub platform, making it easy to use and accessible to all GitHub users.
  7. Multi-platform support: GitHub Actions supports running workflows on multiple platforms, such as Linux, macOS, and Windows, as well as cloud platforms like AWS and Google Cloud Platform.
  8. Secure and private: GitHub Actions runs in isolated virtual environments, and all data is encrypted in transit and at rest.

These are just some of the key features of GitHub Actions. With its flexibility, customization options, and integration with GitHub, GitHub Actions can be a powerful tool for automating and streamlining the software development workflow.

USAGE OF GIT-ACTIONS

Here’s an example of how Git Actions can be used to implement a CI/CD pipeline for a web application hosted on GitHub:

  1. Whenever code is pushed to the main(default) branch of the repository, a Git Actions workflow is triggered.
  2. The workflow uses a pre-built Docker image to build the application, run tests, and generate code coverage reports.
  3. If the tests pass and the code coverage meets a minimum threshold, the workflow proceeds to the deployment stage.
  4. The deployment stage uses another pre-built Docker image to package the application and deploy it to a cloud platform like AWS or Google Cloud Platform.
  5. Finally, the workflow sends a notification to a Slack channel or email address to inform the team that the deployment was successful.

This is just a simple example of how Git Actions can be used to automate a CI/CD pipeline for a web application. In practice, the workflow can be customised and extended to meet the specific needs of your project and team.

🤔 IS THIS THE WAY I WISHED TO RUN GIT-ACTIONS LOCALLY ?

Git Actions is a feature of GitHub, and it is not designed to be run locally. Git Actions workflows are executed on GitHub servers, triggered by events such as a push to a repository or the creation of a pull request.

If you want to test your Git Actions workflows locally before committing and pushing your changes to your repository, there are a few options:

  1. GitHub Actions Toolkit: The GitHub Actions Toolkit is an open-source package that provides a set of libraries and tools to help you test your workflows locally. You can install the toolkit in your local development environment and use it to run your workflows and test the behaviour of your Actions.
  2. Docker: If your workflow involves building Docker images, you can use Docker to test your workflow locally. You can build and run Docker containers on your local machine to test your workflow steps and make sure they work as expected.
  3. Unit testing: You can write unit tests for your custom Actions using a testing framework like Jest or Mocha. This allows you to test the behaviour of your Actions in isolation, without relying on the full GitHub Actions environment.

Note that while these methods can help you test the behaviour of your workflows locally, they may not be able to replicate the full environment and behaviour of GitHub Actions. It is still important to test your workflows on the GitHub platform to ensure that they work correctly in the actual production environment.

THE ABOVE WAYS ARE NOT THE ONE I WISHED FOR !!

😎 LET’s SEE ANOTHER WAY …

RUN GIT-ACTIONS LOCALLY

Let’s see the steps -

INSTALL DOCKER

For MacOS

  1. Click on the link .
  2. Install Docker Desktop — Click on Docker Desktop for Mac with Apple silicon

3. Drag the Docker to Applications

4. Click on Docker Icon present in Finder and accept the terms and conditions to complete the installation.

5. Run docker -v on terminal to check it is installed

For Ubuntu

  1. Use this script to install docker .

bash install-docker.sh

NEKTOS/ACT TOOL

1. The Tool that is being used here is act by nektos/act. Run the command for install act.

curl -s https://raw.githubusercontent.com/nektos/act/master/install.sh | sudo bash

2. check by below command act is installed -

./bin/act

ACT COMMANDS

  1. check the list of all git-actions present in your repository

2. Get the list of workflow_dispatch or pull_request type git-actions

3. list the git-action on the basis of job name

Here my job name is golang

When i searched different name job golang11 which is actually not present then it showed nothing — GREAT

4. Run the default push events by using command ./bin/act -P test=catthehacker/ubuntu:act-18.04

Que) Why am I using the test after -P ?

Ans) My runner’s name in github actions is test.

5. Run the pull_request events by using command ./bin/act pull_request -P test=catthehacker/ubuntu:act-18.04

6. Run the pull_request events by using command ./bin/act workflow_dispatch -P test=catthehacker/ubuntu:act-18.04

7. Run Specific Job by using command ./bin/act -j pullrequest -P test=catthehacker/ubuntu:act-18.04

8. Run Particular git-action by using command ./bin/act -W .github/workflows/main.yaml -P test=catthehacker/ubuntu:act-18.04

RECHECK

Whenever I trigger git-action, in backend it launch docker container till the time git-action is running

Github Code — https://github.com/manali1230/run-git-actions-localy

Thank you so much for giving it ☝️ a read !!

--

--

Manali Jain
Manali Jain

Written by Manali Jain

You are the only one person who can Change Yourself…

No responses yet