Beginner's guide to GitHub Actions
Tags: tutorial, actions, githubactions, beginners
Published: 2020-09-30 10:21:16

## Intro

This post covers the purpose of and basic terms around GH Actions, as well as links to workflows and actions for you to use.

If you know about it already and want to build a test and deploy pipeline right away, skip ahead to my other blog post:

- [CI/CD tutorial with GitHub Actions](https://dev.to/michaelcurrin/intro-tutorial-to-ci-cd-with-github-actions-2ba8)

You'll see some code snippets there and how to use them in a simple project.

Otherwise keep reading below for more concepts and less code.

## What is GitHub Actions? 👨‍🏫

GH Actions is a free service which can run on a repo if configured. It is similar to CircleCI, if you've heard of that.

GH Actions lets us:

- Run shell commands against our repo code (usually Bash on Ubuntu)
- Use GH's cloud infrastructure
- Trigger on an **event**, like a commit, a PR or on a schedule, even on a manual [button press](https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/) now.

Read about [GitHub Actions](https://github.com/features/actions) as a feature on the GitHub site.

## Why should I care? 🤷‍♀️

GH Actions takes out the **pain** of manually running commands on your machine and moves it to the cloud to automated runners. 

You don't have to touch your terminal but you'll get a log of steps which is centralized and public - nice to share across your team or open-source contributors. The job runs each pass and fail status and the corresponding commit - so you can track down a bug by seeing the first time your job switched from passing to failing state. 

You might use GH Actions to build and deploy your package or website, but only if all the safety checks you've setup are met. This builds confidence in getting a quality product delivered.

## Concepts 📚

### Workflow ♺

Your actions config is a "workflow" of **triggers** and **steps**. 

These steps which can be a mixture of:

- shell commands (like `pip install ...` or `npm run build`)
- external actions (covered below)

A workflow file is stored here as YAML file: `.github/workflows/main.yml`. 

### Job

A workflow is the config file.

The job is the what actually executes.

You can see a history of runs for a single job.

You can see runs for the "Node CI" job [here](https://github.com/MichaelCurrin/node-project-template/actions) in my Node.js quickstart repo.

### Action 🎬

You can find an action available in the Actions "marketplace" but really it is a repo that is published by the community and accepted by GH if it meets standards. 

An action is a packaged, reusable flow which you can use like a library or module. Use it to do more complex tasks in your workflow without writing the code yourself.

Note that you don't _have_ to use an action. You can build and test a Node.js app for example using just plain commands as steps.

But if you want more advanced functionality, an action is great:

- Installing and building against using **multiple version** of your runtime e.g. Node 10, 12 and 14. Or Python 3.8 and 3.9.
- Posting to [Slack](https://github.com/marketplace/actions/slack-notify) or Twitter
- Building a Jekyll site or Node web app to a `gh-pages` branch to serve on GH Pages. See my [vue-quickstart](https://github.com/MichaelCurrin/react-quickstart/blob/master/.github/workflows/main.yml) workflow.

## Resources

### Find actions 🛍

There are plenty of actions in the [GitHub Actions marketplace](https://github.com/marketplace). A lot of them do similar things so you'll have to compare them.

An action is written in JavaScript/TypeScript or as a Dockerfile.

If you want to make your own action as a standalone for you and others to use, see this guide:

- [Creating Actions](https://docs.github.com/en/free-pro-team@latest/actions/creating-actions) on GH's docs

### Sample workflows 📒

When you create a new workflow under _Actions_ tab of your repo, you'll also get a choice of start workflows which typically use actions.

See the [actions/starter-workflows](https://github.com/actions/starter-workflows) repo.

I have collected workflow files from all over GH repos and the GH docs and writing my own. I use this central collection regularly when I need to see what pattern I or others typically follow. 

Feel free to copy and paste part or all of a workflow you like to your project. See the [Workflows](https://github.com/MichaelCurrin/code-cookbook/tree/master/recipes/ci-cd/github-actions/workflows) in my Code Cookbook.


## Conclusion 😁

That's my quickstart for GH Actions. Let me know if you need more info.

For interest, check the [#ActionsHackathon](https://dev.to/t/actionshackathon) tag on _dev.to_.


## Credits 📷

Cover image by [@jakobowens1](https://unsplash.com/photos/CiUR8zISX60) on UnSplash and customized with [Google Jamboard](https://jamboard.google.com/).