关于 github-actions-cicd
github-actions-cicd 是一项 GitHub Actions CI/CD 技能,提供自动测试、安全扫描和部署流水线的规则。它强调最小权限、密钥保护和生产部署审批。
主要功能
- 01规划代码质量检查
- 02加入安全扫描与性能审计
- 03构建和压缩项目
- 04配置带审批的生产部署
- 05应用密钥与权限安全规则
适用场景
- 01设计 GitHub Actions CI/CD 流水线
- 02为工作流配置 AWS OIDC 身份验证
- 03检查 Action 版本固定与令牌权限
- 04规划生产发布审批
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ hack23/ homepage --skill github-actions-cicd安装后在 Claude Code 中输入/github-actions-cicd确认已加载。
详细介绍
GitHub Actions CI/CD 技能
目的
使用 GitHub Actions 定义 CI/CD 流水线最佳实践,用于自动化测试、安全扫描和部署。
规则
工作流结构
必须包含:
- 代码质量检查(lint、格式化)
- 安全扫描(CodeQL、Dependabot、ZAP)
- 性能审计(Lighthouse)
- 构建和压缩
- 部署(生产环境部署需审批)
工作流示例:
name: CI/CD Pipeline
on:
push:
branches: [main]
pull_request:
branches: [main]
permissions:
contents: read
security-events: write
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Validate HTML
run: npm run validate:html
- name: Lint CSS
run: npm run lint:css
security-scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
- name: ZAP Baseline Scan
uses: zaproxy/[email protected]
with:
target: 'https://www.hack23.com'
lighthouse:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run Lighthouse
uses: treosh/lighthouse-ci-action@v10
with:
urls: |
https://www.hack23.com/
https://www.hack23.com/services.html
budgetPath: ./budget.json
uploadArtifacts: true
deploy:
needs: [validate, security-scan, lighthouse]
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: us-east-1
- name: Sync to S3
run: aws s3 sync . s3://${{ secrets.S3_BUCKET }} --delete
- name: Invalidate CloudFront
run: aws cloudfront create-invalidation --distribution-id ${{ secrets.CF_DIST_ID }} --paths "/*"
安全最佳实践
必须:
- 使用 OIDC 进行 AWS 身份验证(不使用长期密钥)
- 将密钥存储在 GitHub Secrets 中
- 使用权限最小化的 IAM 角色
- 使用完整提交 SHA 固定 Action 版本
- 启用 Dependabot 以更新 Action
- 使用
permissions键尽量缩小令牌权限范围
禁止:
- 将密钥提交到代码仓库
- 在工作流中使用个人访问令牌
- 授予过于宽泛的权限
相关文档
评论
支持 Markdown