AgentSkillsCN

fetch-action-logs

获取并展示GitHub Actions运行的日志。当用户请求获取、检查或查看GitHub Actions运行的CI日志时,此方法可派上用场。

SKILL.md
--- frontmatter
name: fetch-action-logs
description: Fetch and display logs for a GitHub Actions run. Use when the user asks to get, check, or view CI logs for a GitHub Actions run.
allowed-tools: Bash(curl*), Bash(rm -rf /tmp/gh_logs*), Bash(unzip*), Bash(gh run list*), Bash(gh repo view*)

Fetch GitHub Actions Run Logs

Finding the run ID

If no run ID is provided, list recent runs:

bash
gh run list --limit 5

The run ID is the numeric ID in the output (second to last column).

Downloading logs

bash
REPO=$(gh repo view --json nameWithOwner -q .nameWithOwner)

curl -L \
  -H "Authorization: Bearer $GITHUB_TOKEN" \
  -H "Accept: application/vnd.github+json" \
  "https://api.github.com/repos/$REPO/actions/runs/<RUN_ID>/logs" \
  -o /tmp/gh_logs.zip

Extracting and displaying logs

bash
rm -rf /tmp/gh_logs && unzip -o /tmp/gh_logs.zip -d /tmp/gh_logs/

Then read the relevant log files from /tmp/gh_logs/ to show the user what happened.

Getting logs for a specific job

bash
curl -L \
  -H "Authorization: Bearer $GITHUB_TOKEN" \
  -H "Accept: application/vnd.github+json" \
  "https://api.github.com/repos/$REPO/actions/jobs/<JOB_ID>/logs" \
  -o /tmp/gh_job.log

The job endpoint returns plain text instead of a zip.