GitHub Actions -- Basic Building Blocks and components

 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

 

 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

 Module Introduction

  • Understanding the Key elements .
  • Work with workflow , Jobs and Steps
  • Building an example workflow

Key Components , Workflow, Jobs and Steps 

  • You need to have a code repository .
  • Workflows are attached to the github repository. 
  • Add workflows to your github repositories and you can add as many repositories as you want.
  • The workflow is the first thing you create when setting up the automation process.
  • Now such a workflow includes or more jobs and that's is the next important building block. And now the job contains one or more steps and will be executed in the order in which it is specified and these steps are the actual things that shall be done for example 
  1. download the code interface 
  2. Install dependencies in the second step
  3. Run automated tests in the third step 

 


Workflows are attached to github repositories and they contain one of more jobs. Now what is important though is that you build your workflows with those jobs to setup some automated process which should be executed but of course it should not be executed all the time . But in fact with GitHub actions you setup some events or triggers to your workflows. 

These Events define when the given workflow will be executed. For example you can add an event which requires manual activation of a workflow . But you can also add an event that triggers and executed a workflow whenever a new commit is pushed to a certain branch .

Now Jobs are the things inside of the events that contains the steps that will be executed.

Every jobs defines so called runner which is simply the execution environment. The machine and the operating system that will be used for executing these steps. And with GitHub actions these runners can  be runner either per-defined by git hub .They offer runners  MacOS and windows .

But you can configure your own runners.

  • The jobs in parallel, but you can also configure them to run in sequential order. 
  • You can also set conditional jobs which will not always run but it needs certain condition to be met
  • Now where the actual work happens is precisely the steps.

A step is either a shell script , a command in a command line or an Action

Actions in the context of GitHub Action are pre-defined scripts that perform a certain task . You can build your own Actions or use third party Actions . But for small action you can execute a command from the command line. And you will see all these action through out the course of course.

35. GitHub Actions: Availability & Pricing


He creates a New GitHub repo.

This is the place where you can view and define actions. 


Here you can create your workflows that belong to your repository.

To start off we need to click the simple workflow template.



When this workflow must be executed and you do this by specifying the "on" key.

One event: workflow_dispatcher -- This trigger make sure we can manually trigger this workflow

 It waits for the user to manually start this workflow.

 -- The work is defined by the "jobs" key

first-job  -- is an identifier of our choice -- we need to define the runner to execute the first step .

runs-on -- reserved name

If you search for github action runners -- runner is a machine in which it will execute the different steps.

37. Running the first workflow

Running Multi-Line Shell Commands

Thus far, you learned how to run simple shell commands like echo "Something" via run: echo "Something".

If you need to run multiple shell commands (or multi-line commands, e.g., for readability), you can easily do so by adding the pipe symbol (|) as a value after the run: key.

Like this:

This will run both commands in one step.

-- 

Whenever we push a new commit to our new repository. And therefore we can simply write push here.


Get code ,will down load the repo that you want to the ubuntu server on which the jobs runs.

41. Using Actions in workflow.

Action : A (custom) application that performs a typically complex task frequently repeated task such as downloading a code from the GitHub repository.



When you want to use an Action use the : uses key word that is the key word used when you want to run an action.

Next step you simply identify the identifyer of the action. 


And you can find this identifier in this action page.

https://github.com/actions/checkout


To make sure your workflow suddenly doesn't start doing things that you don't want to or may be breaks you should lock in a certain version to make sure your workflow always uses that version till you are ready to update.


Some actions require some configurations and that could be provided with the "with" key word.  which belong to the uses keyword in the end. 

This with keyword then takes various keywords to configure the action. 

"In GitHub Actions, the actions/checkout is a pre-defined action that allows you to check out the source code of a repository in your GitHub Actions workflow. It is commonly used as a first step in a workflow to retrieve the source code that the workflow will operate on. "


43. Configuring Actions :

Next we need to Install NodeJS, since we are using Ubuntu-Latest --NodeJS is already installed. -- How do we know . Github publishes on what is preinstalled on its runners .

runners mean the the machine or box on which the workflow runs.

In case if you may need to installnodeJS .


44. Adding more workflow steps :


Installing dependency can have an action you can search for . But all you need to do is
run : npm install / npm ci any of these commands .


46 : Adding Multiple Jobs :

47 : Jobs in Parallel and Sequentially:

needs key word which explicitly specifies that this jobs needs to be finished successfully for this job to resume.


with needs you can point to the identifier of another job that must finish successfully before this job can be triggered.

If there are multiple jobs to be finished 

>>> needs; [ job1, job2 ]

48. Using Multiple trigger Events :

 Currently we only have Push - trigger , 

- workflow_dispatch -- allows to manually trigger the job as well.


49. Expressions & Context Objects :

Meta Information collectively called context.

"${{toJSON(github) }}"  -- this is called expression

This outputs the result in the Github


50 : Module Summary






Comments

Popular posts from this blog

Know -- What is GitHub Actions