GitHub Actions is a CI/CD and automation tool built into GitHub. Workflows allow you to automate tasks like testing, building, deploying, or managing your code lifecycle.
1 | name: <Workflow Name> # Name shown in GitHub Actions UI |
on:
)push
Run workflow when code is pushed:
1 | on: |
pull_request
Trigger on PR events like opened, closed, or synchronized:
1 | on: |
workflow_dispatch
Enable manual runs from GitHub UI (with optional input parameters):
1 | on: |
inputs.version
: Define a custom input for the workflow. You can access it via ${{ github.event.inputs.version }}
You can trigger this from API using a POST request to:
1 | POST https://api.github.com/repos/OWNER/REPO/actions/workflows/WORKFLOW_ID/dispatches |
With body:
1 | { |
schedule
Run on a fixed schedule (UTC cron syntax):
1 | on: |
job
runs independently unless defined in needs:
1 | jobs: |
1 | jobs: |
Every action you reference must be either a local action (./.github/actions/
) or from GitHub Marketplace.
Syntax: uses: owner/repo@version
Tip: Always pin to a specific
@version
instead of@latest
to avoid future breaking changes.
uses:
ActionsAction | Description |
---|---|
actions/checkout@v4 |
Checks out your code |
actions/setup-node@v4 |
Setup Node.js runtime |
docker/build-push-action@v5 |
Build and push Docker images |
actions/upload-artifact@v4 |
Upload files (artifacts) between jobs |
actions/download-artifact@v4 |
Download artifacts uploaded from another job |
with:
Supplies Inputs to ActionsMany actions take arguments via with:
:
1 | - uses: actions/setup-node@v4 |
You can do the same with your custom composite actions or when using marketplace actions.
${{ secrets.MY_SECRET }}
${{ vars.MY_VARIABLE }}
1 | env: |
run:
Usage1 | - name: Install dependencies |
Multi-line commands use the pipe |
symbol.
1 | on: |
Access it in run:
:
1 | ${{ github.event.inputs.environment }} |
Use workflow_dispatch
with the GitHub REST API:
1 | curl -X POST \ |
1 | jobs: |
In GitHub Actions workflows, each job runs in its own isolated environment (runner). This means files created or modified in one job are not automatically available in another job.
Artifacts are files or directories that you explicitly upload from one job and then download in another job within the same workflow run. GitHub stores these files temporarily in a central storage location called artifact storage.
name
: Logical identifier for this artifact
path
: File or folder path on the runner to upload
1 | - uses: actions/upload-artifact@v4 |
1 | - uses: actions/download-artifact@v4 |
Files uploaded are stored in GitHub’s artifact storage and can be downloaded in later jobs, or even after the workflow finishes.
Each step:
can use either uses:
(for reusable actions) or run:
(for custom shell commands), not both.
Use env:
at job or step level to avoid repeating variables.
Use matrix builds for multiple versions or environments.
Use artifacts to share outputs
Avoid exposing secrets via echo
Prefer workflow_dispatch
for production deploys
Use matrix:
for multi-version testing