Skip to content

Introduction to GitHub Actions

GitHub Actions automates your software development workflows directly in your GitHub repository. You can use it to run tests, deploy code, or execute any task when specific events occur.

GitHub Actions is a CI/CD platform that automates your build, test, and deployment pipeline. When you push code, tests run automatically. When you merge a pull request, your code can deploy to production automatically.

Here’s a basic “Hello World” example:

  1. Choose a repository: first, you need a GitHub repository. You can use an existing one or create a new one for practice. For this example, let’s assume you have a repository named hello-github-actions.

  2. Create a workflow file: GitHub Actions are defined by a workflow file written in YAML. This file specifies the events that trigger the actions and the jobs that should be executed.

    • Navigate to your repository on GitHub.
    • Go to the Actions tab.
    • Click on the New workflow button.
    • You’ll see a lot of pre-made workflows, but for now, let’s click on set up a workflow yourself at the top.
  3. Write your first workflow: you’ll be greeted with a default workflow template. Let’s modify it to create a simple “Hello World” action. Replace the content of the file with:

name: Hello World Workflow
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Print Hello World
run: echo "Hello World!"

This workflow is called “Hello World Workflow” and is triggered every time you push code to your repository. It has a single job called build, which runs on the latest Ubuntu environment (GitHub also provides MacOS and Windows runners). The job has one step, which prints “Hello World!” to the console.

  1. Commit your workflow: give your file a name like .github/workflows/hello_world.yml, and commit it directly to the main branch. GitHub Actions will automatically recognize and execute your workflow.

  2. See it in action: once committed, go back to the Actions tab in your repository. You’ll see your workflow running. Click on it to see the details and, voila, you’ll find the “Hello World!” message in the logs.

You’ve just created and executed your first GitHub Action workflow! This is just the tip of the iceberg. With GitHub Actions, you can automate virtually any aspect of your development workflow, making your development process more efficient and error-proof.

In upcoming articles, we’ll dive deeper into more complex workflows, including continuous integration, deployment, working with secrets, and much more. Stick around, and let’s automate all the things together!