GitHub Actions – Command - snir1551/DevOps-Linux GitHub Wiki
name
What it does: Defines the name of the workflow, job, or step.
Example:
name: CI Pipeline
on
What it does: Defines when the workflow will run.
Example:
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
jobs
What it does: Defines a list of jobs that will run as part of the workflow.
Example:
jobs:
build:
runs-on: ubuntu-latest
steps:
- run: echo "Build started"
runs-on
What it does: Specifies the OS/environment the job should run on.
Example:
runs-on: ubuntu-latest
steps
What it does: A list of steps to execute within a job.
Example:
steps:
- name: Hello step
run: echo "Hello World!"
uses
What it does: Uses an external GitHub Action from the marketplace.
Example:
- name: Checkout repository
uses: actions/checkout@v4
run
What it does: Executes shell commands.
Example:
- name: Install packages
run: npm install
with
What it does: Passes input parameters to an action.
Example:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
env
What it does: Declares environment variables.
Example:
env:
NODE_ENV: production
strategy.matrix
What it does: Runs the job multiple times with different values (e.g., Node versions).
Example:
strategy:
matrix:
node-version: [18, 20]
Used like this in steps:
with:
node-version: ${{ matrix.node-version }}
needs
What it does: Makes one job depend on another.
Example:
jobs:
test:
...
build:
needs: test
...
if
What it does: Adds conditional logic to steps or jobs.
Example:
- name: Upload only if tests pass
if: ${{ success() }}
run: echo "Tests passed"
timeout-minutes
What it does: Limits the job execution time.
Example:
timeout-minutes: 10
continue-on-error
What it does: Allows the workflow to continue even if a step fails.
Example:
- name: Try something risky
run: ./maybe-fail.sh
continue-on-error: true
outputs
What it does: Defines output values from jobs or steps.
Example:
jobs:
compute:
outputs:
result: ${{ steps.calc.outputs.value }}
steps:
- id: calc
run: echo "value=42" >> $GITHUB_OUTPUT
permissions
What it does: Controls what the workflow is allowed to do.
Example:
permissions:
contents: write
concurrency
What it does: Prevents concurrent runs of the same workflow.
Example:
concurrency:
group: deploy
cancel-in-progress: true
container
What it does: Runs the job in a Docker container.
Example:
container:
image: node:20
services
What it does: Starts additional services like databases for testing.
Example:
services:
redis:
image: redis
ports:
- 6379:6379
defaults
What it does: Sets default values for all steps.
Example:
defaults:
run:
shell: bash