Steps: Actions and Run Commands
What you'll learn: How to structure individual job steps using both marketplace actions and shell commands to execute tasks within your GitHub Actions workflows.
What Are Steps?
Steps are the individual building blocks within a job that execute sequentially on the same runner. Think of steps like a recipe's instructions—each step performs one discrete task, and they run in order from top to bottom. A step can do one of two things: run a shell command directly or invoke a pre-built action.
Run Commands: Direct Execution
Use run to execute shell commands directly on the runner. This is perfect for simple tasks like installing dependencies, running tests, or printing output:
- name: Check Node version
run: node --version
- name: Run tests
run: npm test
You can execute multi-line scripts by using the pipe character:
- name: Build and test
run: |
npm install
npm run build
npm test
Using Actions: Pre-built Modules
Use uses to invoke marketplace actions—reusable modules created by GitHub or the community. Actions handle complex tasks like checking out code or setting up environments:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
Combining Both
Most real workflows mix both approaches—actions for common setup tasks, run commands for project-specific logic:
steps:
- uses: actions/checkout@v3
- run: npm install
- run: npm test
Key Takeaway: Steps structure your job's execution through either run (shell commands) or uses (marketplace actions), letting you combine simple scripts with powerful pre-built functionality in a sequential flow.