Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
March 22, 2022 03:27 pm GMT

What are GitHub actions and how to use it?

GitHub Actions

Recently I was working on building a simple blackjack game using JavaScript. After I completed it, I straightly uploaded it on GitHub. I saw tons of people contributing to my repository of the blackjack game. I thought there must be a system to greet those who are making the project better. So, I used GitHub Actions to do the same with the help of it, I can circulate messages that I want to all those lovely people who are contributing to the project.
Now you might be wondering what GitHub action is so let's find out.

So technically, GitHub Actions is a continuous integration and continuous delivery (CI/CD) platform that allows you to automate your build, test, and deployment pipeline. You can create workflows that build and test every pull request to your repository or deploy merged pull requests to production.

Lets try to break this jargon into simple understanding. GitHub action is a platform to automate developer flows. We talk about such developer flows when we are concerning our thoughts about Pull Request, an issue created in a setup, PR merge, etc.
To Automate these, we use GitHub action (this is one of the many issues solved by GitHub Actions). What GitHub Actions do is they Listen to an event say a PR, or an issue or a PR merge or so, and respond to such actions (Trigger Workflow). For example, for an issue, a GitHub action might sort it or label it or assign it to someone else.
Let us discuss more what CI/CD pipeline is

CI/CD Pipeline

CI/CD pipeline in simple words is a process through which developers can commit changes, test, build and finally deploy a product at a single stage. Let us understand this through an example if I want to build a Docker Image and push without the help of GitHub, I will need to download a different software's to deploy it but with GitHub actions, I can have access to all at a single stage.

Deployment Options
As you can clearly see tons of deployment services are available through GitHub actions

By this time you might be clear with what GitHub Actions is and its theoretical knowledge lets quickly jump to a practical Example.
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 called .github/workflows.
You can create an example workflow in your repository that automatically triggers a series of commands whenever code is pushed. In this workflow, GitHub Actions checks out the pushed code, installs the software dependencies, and runs bats -v.

Step 1: In your repository, create the .github/workflows/ directory to store your workflow files.
Step 2: In the .github/workflows/ directory, create a new file called learn-github-actions.yml and add the following code.

required code

Step 3:Commit these changes and push them to your GitHub repository.
Your new GitHub Actions workflow file is now installed in your repository and will run automatically each time someone pushes a change to the repository.

Understanding the workflow

  1. name: learn-github-actions
    The name of the workflow as it will appear in the Actions tab of the GitHub repository.

  2. on: [push]
    Specifies the trigger for this workflow

  3. Jobs
    Groups together all the jobs that run in the learn-github-actions workflow.

  4. Check-bats-version:
    Defines a job named check-bats-version. The child keys will define properties of the job.

  5. runs-on: ubuntu-latest
    Configures the job to run on the latest version of an Ubuntu Linux runner.
    (if its windows write windows-latest)

  6. steps:
    Groups together all the steps that run in the check-bats-version job. Each item nested under this section is a separate action or shell script.

7.-uses: actions/checkout@v2
The uses keyword specifies that this step will run v2 of the actions/checkout action. This is an action that checks out your repository onto the runner, allowing you to run scripts or other actions against your code (such as build and test tools).

8.- uses: actions/setup-node@v2
with:
node-version: '14'

This step uses the actions/setup-node@v2 action to install the specified version of the Node.js (this example uses v14). This puts both the node and npm commands in your PATH.

9.-run: npm install -g bats
The run keyword tells the job to execute a command on the runner. In this case, you are using npm to install the bats software testing package.

  1. - run: bats -vFinally, you'll run the bats command with a parameter that outputs the software version.

Mine looked like this

after running code
The more you use GitHub Actions the more you will be comfortable with it. Thanks for reading and I am sharing some resources to do check them out
Till then SEE a <3

Resources

  1. https://youtu.be/F3wZTDmHCFA
  2. https://www.youtube.com/watch?v=rgxbeIvQj0Q&t=4s3.https://docs.github.com/en/actions/learn-github-actions/understanding-github-actions
  3. GitHub Actions Tutorial - Basic Concepts and CI/CD Pipeline with Docker

Original Link: https://dev.to/vinayak27raw/what-are-github-actions-and-how-to-use-it-3eol

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To