Introduction to GitHub Actions

Tauqeer Ahmad
5 min readAug 25, 2022

Blog covering major topics for CI/CD using GitHub Actions, explaning workflows and deployment.

Lights! Camera And ACTIONS!

What is GitHub Actions?- A basic question aroused for handling the concept. It is a simple platform used to automate developer workflows.

Wait! then what about CI/CD? Actually CI/CD is one of the many workflows that we can automate using GitHub Actions.

Now what are workflows?

A workflow is the ‘thing’ (or all the things) which happen after a specific other ‘thing’ (ie. event) occurs.

GitHub Actions uses YAML syntax to define the workflow. Each workflow is stored as a separate YAML file in your code repository, in a directory named .github/workflows.

Simply- It will be an action or collections of actions that will be taken or trigerred when an event has occured.

For example — Let us consider a situation when you collect milk from the doorstep after being kept by milkman.

---
name: Milk Collection
on: [when kept on door by milkman]
jobs:
milkCollection:
runs-on: my-home
steps:
- uses: actions/checkout@v2
- name: milk-collector
uses: milk/action-KeepItInTheFridge@v3

Here, it can be understood that Milk Collection executor will be executed.

But when?
When it will be kept on the door by milkman.

Now it seems that an event has been trigerred making it to follow the jobs specified. Well there is one job which is specified, milkCollection.

Note: There can be multiple jobs which will be followed on creating their workflow.

milkCollection will be running however, here we specify the environment into which it should be running. Of-course!! quite possible it might start working for neighbor’s home, so precisely specifying my-home as the environment.

Also, specifying the environment helps the further steps to be executed as per the requirement, making the job to be finished properly.

Stating with the steps, there are several steps are considered into before doing any of work, so here we are going to collect milk from our doorstep, so before that we should be checking-out from our room, wearing slippers and then moving forward to gate and opening it.

Right? One reaching to gate and able to collect the milk, can now perform the action of keeping it into the fridge.

BOOOMMM!!

Milk succesfully kept into the fridge

Before moving ahead, we should be learning a bit about Events!

An event is something that happens in a GitHub repository.It includes things like opening an issue, creating a pull request, making a commit, merging a PR, or joining of a contributor.

So response of which automatic ACTIONS are executed.

But How GitHub Actions are taking part into this?

Let us build some pipeline and workflows in our repository to have a practical demonstration.

Situtation: We have a repository which is serving for open-source and there we wish to greet the every new contributors.

actions-opensource

Here we go with a repository, ready for open source contribution. People will be forking it to contribute into it so we are trying to setup a workflow into YAML file which will do the required actions.

For setting up a workflow file .yml extension, follow these steps —

Step 1: Click on the Actions tab, which in present in your repo.

Step 2: Simply go to ‘set up a workflow yourself’.

Creating workflow for greeting on PR and Issues

NOTE: GitHub will automatically create .github/workflows directory for handling the YAML files.

---
name: Greetings
on: [pull_request_target, issues]jobs:
greeting:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- uses: actions/first-interaction@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
issue-message: "You can be a problem solver! Go for it."
pr-message: "Congo for your PR! Your PR may create an
impact."

Here you can use this workflow for your own setup. You can understand it from here that for triggering the workflow, a pull_request_target or issues event should take place.

Point to note : actions/first-interaction@v1 is being used. ‘actions’ has its document which is a script helping in quickly writing a script in your workflow that uses the GitHub API and the workflow run context.

Read more about it from here : https://github.com/actions/github-script

Step 3: Making it available to public and being ready for a Pull Request.

Someone dropping a PR for contribution

Step 4: Wishing them using the workflow we have created. And it’s a success!!

Step 5: The Pull Request might be accepted or updated in accordance with the solution you have came up with.

Conclusion in some collections of words

  1. CI/CD is just a set of practices that application development teams use to deliver code changes more frequently and reliably.
  2. With GitHub Actions, you can trigger CI/CD workflows and pipelines of webhooks.
  3. Still for CI/CD a bunch of tools are available to configure and execute the workflows.
  4. There are several events defined by GitHub to trigger the workflow. They can be listed : https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows

References:

  1. Docs for GitHub Action : https://docs.github.com/en/actions/learn-github-actions/understanding-github-actions
  2. About workflows: https://docs.github.com/en/actions/using-workflows/about-workflows
  3. About CI/CD: https://www.redhat.com/en/topics/devops/what-cicd-pipeline

--

--

Tauqeer Ahmad

Hola everyone ! Currently a tech evangelist and learning lad making superb content on whatever I’ve learnt.