Understanding GitHub Actions and github workflow


GitHub actions are automated tools that can run some user-specified tasks based on some event that triggers those tasks. So in simple words, a specific event triggers a workflow which then runs some job that consists of a couple of functions written in a .yaml file. An action is a custom application for the GitHub Actions platform that performs a complex but frequently repeated task. The job runs on a server called a runner.
You can create workflows that build and test every pull request to your repository, or deploy merged pull requests to production.
GitHub requires the user to place the action file (.yml file) in a specific directory (.github\workflows) of the repository. This file (.yml) runs the tasks specified inside the file.
So to understand GitHub actions we must learn about (events, workflow, jobs, runner, yaml files)

An event is a specific activity in a repository that triggers a workflow run. This is what initiates the GitHub actions.
For example, an activity can originate from GitHub when someone creates a pull request, push to any specific branch, opens an issue, or pushes a commit to a repository.
A workflow is an automated process that you can set up to run one or more tasks. It is configured using a YAML file in your repository. **Workflows **can be triggered by events like a push to your repository, manually by a user, or even on a scheduled basis.
A job is a set of steps in a workflow that is executed on the same runner. Each step is either a shell script that will be executed or an action that will be run. Steps are executed in order and are dependent on each other.
A runner is a server that runs your workflows when they're triggered. Each runner can run a single job at a time. GitHub provides Ubuntu Linux, Microsoft Windows, and macOS runners to run your workflows. Each workflow run executes in a fresh, newly-provisioned virtual machine.
YAML, originally known as Yet Another Markup Language, was created in 2001 but now stands for YAML Ain't Markup Language. A yml is just like a JSON file but more human-readable in nature. YAML can do everything that JSON can and more.
.github folder in the root of your project (This is a required step and the folder name must be .github) workflows inside the .github folder (This is a required step and the folder name must be .github) *.yml file, you can name it anything you wish Hello World workflow, you can copy/ paste the code into your .yml filename: Hello World Workflow
 on:
     push:
         branches:
             - main
     pull_request:
         branches:
             - main
     workflow_dispatch:
 jobs:
     hello:
         runs-on: ubuntu-latest
         steps:
             - uses: actions/checkout@v2
             - name: hello world
               run: echo "Hello World"
               shell: bash
     thankyou:
         runs-on: ubuntu-latest
         steps:
             - name: thank you
               run: echo "Thank you"
               shell: bashAs I told you before everything onIndentation, space, tab are very cruical in .yml file. So formate the code as is.
this file is very readable except the actions/checkout@v2 may be. Here we have used one action that is already available in the GitHub marketplace, we can write our own action too but for this simple example let’s use what is already available to usactions/checkout@v2
Checkout is an action that is available to us on the GitHub marketplace.
https://github.com/actions/checkout
https://github.com/marketplace/actions/checkoutWe can write our actions too. Commit and push the code to the Github
After you commit and push the changes to GitHub you can notice a dark yellow circle which means the workflow is running.
Let’s navigate to the Actions tab
Inside the Actions tab, you can notice the workflow is already added as we named earlier in our yml file **Hello World Workflow. **Let’s navigate to the **Update sitemap.xml **task that is already completed and marked as a dark green checked mark
You can notice now that both job is completed here too
We can navigate to each job and see that our command ran successfully
If we take a look even further, we can notice the actions that we specified were downloaded at first. Then rest of our code executed