Skip to content

Instantly share code, notes, and snippets.

@Skeyelab
Created August 28, 2025 14:28
Show Gist options
  • Select an option

  • Save Skeyelab/ff64580756487e551b77f5318bdf0f4d to your computer and use it in GitHub Desktop.

Select an option

Save Skeyelab/ff64580756487e551b77f5318bdf0f4d to your computer and use it in GitHub Desktop.

Fetch CI Logs (Node.js Version)

A Node.js CLI tool to download GitHub Actions logs for CI workflows. This is a port of the Ruby Rake task to JavaScript/Node.js.

Installation

  1. Download fetch-ci-logs.js and package.json to your project
  2. Install dependencies:
    npm install

Or install globally:

npm install -g .

Usage

Direct Node Execution

# Download logs for the latest CI run
node fetch-ci-logs.js fetch-logs

# Download logs for a specific workflow
node fetch-ci-logs.js fetch-logs ci.yml

# Download logs for a specific run ID
node fetch-ci-logs.js fetch-logs ci.yml 123456789

# Download logs for a specific repository
node fetch-ci-logs.js fetch-logs ci.yml 123456789 myorg/myrepo

# Push current branch then wait for CI and download logs
node fetch-ci-logs.js after-push

# Push to a specific remote and branch
node fetch-ci-logs.js after-push upstream feature-branch

NPM Scripts (add to package.json)

{
  "scripts": {
    "ci:fetch-logs": "node fetch-ci-logs.js fetch-logs",
    "ci:after-push": "node fetch-ci-logs.js after-push"
  }
}

Then use:

npm run ci:fetch-logs
npm run ci:after-push

Environment Variables

Variable Description Default
GITHUB_TOKEN GitHub personal access token Required
GITHUB_REPO Repository in "owner/repo" format Auto-detected
CI_WORKFLOW Workflow file name ci.yml
RUN_ID Specific run ID to download Latest run
WAIT / WAIT_FOR_RUN Wait for workflow run to appear false
WAIT_FOR_COMPLETION Wait for run to complete false
WAIT_TIMEOUT Timeout in seconds 300
WAIT_INTERVAL Polling interval in seconds 5
SKIP_PUSH Skip git push in after-push false

Examples

Basic Usage

# Set your GitHub token
export GITHUB_TOKEN=your_github_token_here

# Download latest CI logs
node fetch-ci-logs.js fetch-logs

# Download logs for a specific repository
GITHUB_REPO=myorg/myrepo node fetch-ci-logs.js fetch-logs

Advanced Usage

# Wait for CI to complete and download logs
WAIT_FOR_COMPLETION=1 node fetch-ci-logs.js fetch-logs

# Download logs for a specific workflow with custom timeout
CI_WORKFLOW=deploy.yml WAIT_TIMEOUT=600 node fetch-ci-logs.js fetch-logs

# Push and wait for CI (useful for CI/CD pipelines)
node fetch-ci-logs.js after-push

CI/CD Integration

Add to your GitHub Actions workflow:

- name: Download CI Logs
  run: node fetch-ci-logs.js fetch-logs
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Output

The tool creates a directory structure like:

log/ci/
└── 123456789-abc1234/
    ├── run_123456789.zip          # Combined run logs
    ├── run_123456789_metadata.json # Run metadata
    ├── job_987654321_test.log     # Individual job logs
    └── job_987654322_build.log

Differences from Ruby Version

  • CLI Interface: Uses command-line arguments instead of Rake task arguments
  • Dependencies: Uses axios instead of faraday
  • Async/Await: Fully async instead of synchronous operations
  • Error Handling: More robust error handling with try/catch
  • File Operations: Uses Node.js fs.promises API
  • Git Operations: Uses child_process.execSync instead of Ruby backticks

Requirements

  • Node.js 14+
  • npm
  • Git
  • GitHub personal access token with Actions read permissions

License

MIT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment