AI Hints
Home›CI/CD with GitHub Actions Tutorial›Events, Jobs and Steps
CI/CD with GitHub Actions · Lesson 21 of 138

Steps with run

Shell commands.

⏱ 2 min read▶ Video at 23:44🎓 Free
Watch this lesson in the CI/CD with GitHub Actions courseWatch on YouTube ↗Full CI/CD with GitHub Actions course

Most steps do one thing. They run shell commands. On Ubuntu, that's bash, the same shell you use in a terminal. Anything you can type in a terminal, you can put in a run step.

Steps with run
From the video: Steps with run
  • Steps run commands
  • bash on Ubuntu
  • Anything you can type

Run steps

A step can have a name, which appears in the log. If it doesn't, GitHub uses the command itself. A pipe lets one step run several commands. And if any command fails, the step fails, and by default, the rest of the job is skipped.

steps.ymlyaml
steps:
  - name: Show the files
    run: ls
  - run: echo "No name, so the command is the title"
  - name: Several commands
    run: |
      python3 --version
      wc -l app.py test_app.py
  - name: This one fails
    run: grep "missing" app.py
  - name: Never runs
    run: echo "skipped"

Watching it run

Here's the log. Each step appears with a tick or a cross. The grep step finds no match, so it exits with code one, and gets a cross. The last step never runs, and the job fails. That's the fail fast behaviour we want in a pipeline.

Terminal
run-steps .github/workflows/steps.yml | tail -n +2
Job: demo
  ✓ Show the files
      README.md
      app.py
      requirements.txt
      test_app.py
  ✓ Run echo "No name, so the command is the title"
      No name, so the command is the title
  ✓ Several commands
      Python 3.12.3
        8 app.py
       15 test_app.py
       23 total
  ✗ This one fails
      Error: Process completed with exit code 1.
  Job failed

Summary

Run steps execute shell commands. A failing command fails the step, and stops the job. Next, steps that use actions.

Key takeaways
  • run: one command
  • run: | several
  • Fail stops the job
Next up: Actions with uses — reusable steps