You are currently viewing How To Create GitHub Actions Using API

How To Create GitHub Actions Using API

How To Create GitHub Actions Using API

Hello Everyone

Welcome to CloudAffaire and this is Debjeet.

You can implement CI/CD pipeline in your GitHub repository using GitHub Actions. In this blog post, we will discuss how to create GitHub actions using API. In a nutshell, GitHub actions is a set of instructions known as workflow that is triggered based on some events or schedule and perform some actions in the form of jobs which can have multiple steps in a shared or dedicated server know as GitHub runner.

GitHub Actions Components:

Workflows: Workflow is a file written in YAML which contains a set of instructions to be executed. Workflow contains all the configurations like when to trigger, where to trigger, what to trigger etc. for your GitHub CI/CD pipeline.

Events: Like any modern application, GitHub is also event driven and generates a event with respect to any change. GitHub generates an event whenever we perform a action on GitHub like pushing a change, creation of branch, pull requests etc. You can use these events to trigger the CI/CD pipeline (GitHub Actions).

Jobs: Jobs are the unit of action that you want to perform in your CI/CD pipeline. You can use a job to build, test or deploy your application. Jobs gets executed in the GitLab runner and you can execute multiple jobs at once or create a dependency chain on jobs like if the build job fails, your test and deploy job will be skipped.

Steps: Steps are individual task or command that you execute in a job. A job contains multiple steps which can be executed sequentially or parallelly. Each step on a job executes in the same runner and you can pass data (artifacts) from one step to another or from one job to another.

Actions: Actions are standalone commands that gets executed in a step. You can create your own actions or use GitHub provided action to execute a command in GitHub runner.

Runners: Runners are servers where your CI/CD pipeline gets executed. GitHub provides their own set of shared runners that you can integrate in your GitHub pipeline or you can build and integrate your own dedicated runner in GitHub.

How To Create GitHub Actions Using API

Next, we are going to create our first GitHub CI/CD pipeline.

How To Create GitHub Actions Using API


Step 1: Create a new GitHub repository for this demo.

Step 2: Create a workflow file that will contain your GitHub CI/CD configurations.

Step 3: Upload the workflow file in .github/workflow directory.

Note: This will trigger the CI/CD pipeline immediately as we have set “on[push]” in the workflow definition. We are using a GitHub provided shared runner with ubuntu OS “runs-on: ubuntu-latest”.

Please follow this blog series to get details on all the configuration options available in GitHub workflow.

Step 4: Get the workflow details.

You can also check the workflow execution status directly from GitHub.

How To Create GitHub Actions Using API

How To Create GitHub Actions Using API

Step 5: Delete the GitHub repository.

Hope you have enjoyed this article. To know more about GitHub, please refer below official documentation

Leave a Reply