跳至主要内容

GitHub Actions 助手

生成并改进 GitHub Actions 工作流。

注意

  • 本库中的示例旨在提供灵感——我们鼓励您根据自己的项目、语言和团队流程进行更具体的调整。
  • 欲查看社区贡献的针对特定语言和场景的自定义指令示例,请参阅 超赞的 GitHub Copilot 定制 仓库。
  • 您可以根据创建自定义指令的平台或 IDE,在不同范围内应用它们。如需了解更多信息,请参阅“关于定制 GitHub Copilot 响应”。

以下示例展示了一个特定路径的 actions.instructions.md 文件,仅适用于仓库中的 GitHub Actions 工作流文件,使用 applyTo 字段。欲了解有关特定路径指令文件的更多信息,请参阅 为 GitHub Copilot 添加仓库自定义指令

Text
---
applyTo: ".github/workflows/**/*.yml"
---

When generating or improving GitHub Actions workflows:

## Security First
- Use GitHub secrets for sensitive data, never hardcode credentials
- Pin third-party actions to specific commits by using the SHA value (e.g., `- uses: owner/some-action@a824008085750b8e136effc585c3cd6082bd575f`)
- Configure minimal permissions for GITHUB_TOKEN required for the workflow

## Performance Essentials
- Cache dependencies with `actions/cache` or built-in cache options
- Add `timeout-minutes` to prevent hung workflows
- Use matrix strategies for multi-environment testing

## Best Practices
- Use descriptive names for workflows, jobs, and steps
- Include appropriate triggers: `push`, `pull_request`, `workflow_dispatch`
- Add `if: always()` for cleanup steps that must run regardless of failure

## Example Pattern
```yaml
name: CI
on: [push, pull_request]

jobs:
  test:
    runs-on: ubuntu-latest
    timeout-minutes: 10
    steps:
      - uses: actions/checkout@v5
      - uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: npm
      - run: npm ci
      - run: npm test
```

延伸阅读

© . This site is unofficial and not affiliated with GitHub, Inc.