GitHub Actions

GitHub Actions Core Concepts

Multi Line commands and Executing Third Party Libraries

In this guide, you’ll learn how to:

  • Chain multiple shell commands in a single GitHub Actions step
  • Install and invoke a third-party CLI tool (cowsay) on the Ubuntu runner

Why Combine Commands in One Step?

By default, each run step in a job runs in its own shell session. This can lead to redundant setup and slower workflows. Using YAML’s pipe syntax (|) lets you:

  • Share the same shell environment
  • Reduce runner overhead
  • Improve readability

Note

Every run step runs in a fresh shell. Use multi-line commands to keep related tasks together.

Separate run Steps Example

name: My First Workflow
on: push

jobs:
  first_job:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repo
        uses: actions/checkout@v4

      - name: Welcome message
        run: echo "My first GitHub Actions Job"

      - name: List files
        run: ls

      - name: Read file
        run: cat README.md

Single Multi-Line run Step

name: My First Workflow
on: push

jobs:
  first_job:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repo
        uses: actions/checkout@v4

      - name: List and Read files
        run: |
          echo "My first GitHub Actions Job"
          ls -ltra
          cat README.md

Executing a Third-Party CLI (cowsay)

Suppose you want to generate ASCII art using cowsay. Since it isn’t installed by default on the Ubuntu runner, invoking it directly will fail:

      - name: Generate ASCII Artwork
        run: cowsay -f dragon "Run for cover, I am a DRAGON....RAWR" >> dragon.txt

The image shows a GitHub Actions workflow interface with a job titled "first_job" that has failed. The steps include setting up the job, checking out the repository, listing and reading a file, generating ASCII artwork, and completing the job.

The error indicates that cowsay is not found.

Warning

Non-native tools must be installed before you can use them in your workflow.

Installing and Running cowsay

Add an installation step and then run the command:

name: My First Workflow
on: push

jobs:
  first_job:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repo
        uses: actions/checkout@v4

      - name: Install cowsay
        run: sudo apt-get update && sudo apt-get install -y cowsay

      - name: Generate ASCII Artwork
        run: |
          cowsay -f dragon "Run for cover, I am a DRAGON....RAWR" >> dragon.txt
          cat dragon.txt

Quick Reference Table

TaskCommand
Update package listssudo apt-get update
Install cowsaysudo apt-get install -y cowsay
Chain commands in one stepUse `run:
Invoke third-party CLI toolcowsay -f <file> "message" > output.txt

Watch Video

Watch video content

Previous
Configure Checkout Action