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 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
Task | Command |
---|---|
Update package lists | sudo apt-get update |
Install cowsay | sudo apt-get install -y cowsay |
Chain commands in one step | Use `run: |
Invoke third-party CLI tool | cowsay -f <file> "message" > output.txt |
Links and References
Watch Video
Watch video content