DEV Community

Cover image for Github Actions Basics
DHRUV TRIVEDI
DHRUV TRIVEDI

Posted on

Github Actions Basics

Github Actions are used to automate project management tasks by using workflows.

  • Each Workflow contains a series of tasks, which are implemented or run automatically everytime when the workflow runs.

Github Action is a CI/CD(Continuous Integration and Continuous Delivery) platform that allows you to automate your build, test and deployment pipelines

The Components of Github Actions:

1.Workflow:

  • Workflow is a configurable automated process that will run one or more jobs,
  • defined by a YAML file/Syntax,
  • and it's placed inside .github/workflows path

2.Events:

  • it is Something that triggers Workflows

3.Jobs:

  • Job is a set of steps in a workflow, each step is either a Shell script or an action
  • Steps are executed in order, and are dependent on each other.
  • Data Sharing mechanism is integrated into the steps, since they are dependent on each other

4.Actions:

  • Custom application for the Github Actions platform that performs a complex but frequently repeated tasks

5.Runners:

  • is a server that runs your workflow when they are triggered.

Let us Understand the Workflow file(YAML):

name: learn-github-actions
Enter fullscreen mode Exit fullscreen mode
  • it will appear in the 'Actions' tab of the Github Repository
  • it is an optional step
run-name: ${{github.actor}} is learning Github actions
Enter fullscreen mode Exit fullscreen mode
  • it specifies the name of workflow run, that will appear in the list of workflow runs on 'Actions' Tab
on: [push]
Enter fullscreen mode Exit fullscreen mode
  • specifies the trigger for the Workflow
jobs:
Enter fullscreen mode Exit fullscreen mode
  • Groups all the jobs that run in the learn-github-action workflow
check-bats-version:
Enter fullscreen mode Exit fullscreen mode
  • Defines a job named check-bats-version. The child keys will define properties of the job.
runs-on: ubuntu-latest
Enter fullscreen mode Exit fullscreen mode
  • configures the job to run on the latest version of the Ubuntu Linux runner(Fresh virtual machine hosted by Github)
steps:
Enter fullscreen mode Exit fullscreen mode
  • groups together all the steps that runs in this job. Each item nested under this section is a separate action or a shell script.
-uses: actions/checkout@v4
Enter fullscreen mode Exit fullscreen mode
  • The uses keyword specifies that this step will run v4 of the actions/checkout action.
  • This actions checks out your repository onto the runner, allowing you to run scripts or other actions against your code.
-uses: actions/setup-node@v3
 with:
    node-version: '14'
Enter fullscreen mode Exit fullscreen mode
  • This step uses the actions/setup-node@v3 action to install the specified version of the Node that will be used for the project
  • This puts both the node & npm commands in your Path
-run: npm install -g bats
Enter fullscreen mode Exit fullscreen mode
  • The run keyword tells the job to execute a command on the Runner.
  • In this case, you're using npm to install bats software testing package.
-run:bats-v
Enter fullscreen mode Exit fullscreen mode
  • Finally you'll run the bats command with a parameter that outputs the software version.

Thanks for reading the tutorial!

Top comments (0)