GitHub Actions: Caching, Artifacts, and GitHub CLI Workflows

Cache dependencies, upload and download artifacts, and drive workflows with GitHub CLI commands in GitHub Actions.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## Caching dependencies
Cache npm dependencies with setup-node
- uses: actions/setup-node@v4
  with:
    node-version: 20
    cache: npm

# Use built-in npm cache support.

Cache arbitrary paths
- uses: actions/cache@v4
  with:
    path: |
      ~/.cache/pip
      .venv
    key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
    restore-keys: |
      ${{ runner.os }}-pip-

# Use `actions/cache` for custom cache paths.

## Artifacts and GitHub CLI
Upload build output as an artifact
- uses: actions/upload-artifact@v4
  with:
    name: build-output
    path: dist/

# Save files from the workflow run for later download or later jobs.

Download a prior artifact
- uses: actions/download-artifact@v4
  with:
    name: build-output
    path: ./artifacts

# Fetch an artifact in a later job.

List workflows with GitHub CLI
gh workflow list

# Inspect workflows from the terminal.

Trigger a workflow manually with gh
gh workflow run deploy.yml -f environment=staging

# Dispatch a workflow file from the CLI.

Watch a workflow run
gh run watch

# Stream progress of the latest run in the terminal.

Download workflow artifacts with gh
gh run download RUN_ID -n build-output

# Fetch artifacts from a completed workflow run.

Recommended next

No recommendations yet.