github-actions
Write and debug GitHub Actions workflows. Use when the user says "create CI pipeline", "github actions", "workflow not working", "fix CI", "automate with github", or asks about GitHub Actions.
安装与使用
请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。
查看来源 ↗使用指南技能说明
GitHub Actions
Create and troubleshoot GitHub Actions workflows for CI/CD pipelines.
Instructions
When writing:
- Understand the pipeline requirements
- Check existing workflows in
.github/workflows/ - Write workflow following best practices below
- Validate with
actionlintif available
When debugging:
- Read the workflow file
- Check recent runs:
gh run list - View run logs:
gh run view <run-id> --log-failed - Identify and fix issues
Workflow structure
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "npm"
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test
Best practices
- MUST pin actions to full SHA:
uses: actions/checkout@abc123... - MUST set minimal
permissions:(not defaults) - MUST use
npm cinotnpm installfor reproducibility - Use caching for dependencies
- Use matrix builds for multiple versions
- Use job dependencies with
needs: - Use concurrency to cancel outdated runs
- Store secrets in GitHub Secrets, reference with
${{ secrets.NAME }}
Security
permissions:
contents: read # Minimal permissions
env:
API_KEY: ${{ secrets.API_KEY }} # Never hardcode
Common patterns
# Caching
- uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
# Matrix
strategy:
matrix:
node: [18, 20, 22]
os: [ubuntu-latest, macos-latest]
# Concurrency
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
# Conditional
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
Debug commands
gh run list --limit 10
gh run view <run-id>
gh run view <run-id> --log-failed
gh run rerun <run-id>
Rules
- MUST use pinned action versions (SHA or version tag)
- MUST set explicit permissions
- Never hardcode secrets in workflow files
- Never use
pull_request_targetwith checkout of PR code - Always test workflows in a branch first
使用示例
查看来源仓库中的使用示例与配置说明。
查看来源 ↗来源历史
- 收录时间
- 2026-01-20
- 索引更新时间
- 2026-01-26
- Branch
- main
收录与同步日期属于本站记录。源码修改历史请查看来源仓库。
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!