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

Reduce workflow time by caching dependencies and build inputs.

Cache npm dependencies with setup-node

Use built-in npm cache support.

yamlANYcachenpmsetup-node
yaml
- uses: actions/setup-node@v4
  with:
    node-version: 20
    cache: npm

Prefer first-party built-in caching support when available.

Cache arbitrary paths

Use `actions/cache` for custom cache paths.

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

Choose keys that change when dependencies change, and use restore keys for partial hits.

Artifacts and GitHub CLI

Store outputs and interact with workflows using `gh`.

Upload build output as an artifact

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

yamlANYupload-artifactartifacts
yaml
- uses: actions/upload-artifact@v4
  with:
    name: build-output
    path: dist/

Artifacts are great for test reports, build outputs, logs, and release bundles.

Download a prior artifact

Fetch an artifact in a later job.

yamlANYdownload-artifactartifacts
yaml
- uses: actions/download-artifact@v4
  with:
    name: build-output
    path: ./artifacts

Artifacts are a common way to hand off generated files between jobs.

List workflows with GitHub CLI

Inspect workflows from the terminal.

bashANYghworkflowlist
bash
gh workflow list

Useful for debugging and automating workflow management from a terminal or script.

Trigger a workflow manually with gh

Dispatch a workflow file from the CLI.

bashANYghworkflowrun
bash
gh workflow run deploy.yml -f environment=staging

The target workflow must define the `workflow_dispatch` trigger and compatible inputs.

Watch a workflow run

Stream progress of the latest run in the terminal.

bashANYghrunwatch
bash
gh run watch

Helpful when you want live feedback without keeping the GitHub Actions page open.

Download workflow artifacts with gh

Fetch artifacts from a completed workflow run.

bashANYghrundownloadartifacts
bash
gh run download RUN_ID -n build-output

Great for pulling logs or build output from CI to your local machine.

Recommended next

No recommendations yet.