GitHub Actions by Example: Hello World

GitHub Actions is configured by writing “workflows”. Workflows define sequences of commands written in YAML and must be located under the directory .github/workflows/ at the root of your repository.

This example workflow prints “Hello world”, followed by “Step 1…”, “Step 2…”, “Step 3…”, and finally “Goodbye”.

name: hello-world-example

We must specify what events trigger the workflow to run. In this case we run it every time someone pushes to the repo.

on:
  push:
jobs:

A job specifies a sequence of commands. We named this job say-hello.

  say-hello:

jobs can run on different machines.

    runs-on: ubuntu-latest

steps is a list of commands to run.

    steps:
      -
        name: Say Hello

Finally, do stuff! Run a command using the operating system’s shell.

        run: echo "Hello world!"
      -
        name: Do stuff

Use the pipe, |, to start a multiline string in yaml. This allows us to write easily readable multistep code

        run: |
          echo "Step 1..."
          echo "Step 2..."
          echo "Step 3..."          
      -
        name: Say Goodbye
        run: echo "Goodbye!"

Next example: Event Triggers