mcpField
G
github-actions-2025

github-actions-2025

github.com/josiahsiegel云与 DevOps59162 次安装19 周前更新
代码仓库

关于 github-actions-2025

面向维护 GitHub Actions 工作流的团队,汇总 2025 年运行器、发布、运行时、安全和制品变化,并提供迁移示例,帮助调整自动化与 CI/CD 配置。

主要功能

  1. 011 vCPU 运行器使用指南
  2. 02不可变发布实践
  3. 03Node24 迁移步骤
  4. 04环境保护规则
  5. 05限制并固定 Action 版本
  6. 06制品 Action 迁移

适用场景

  1. 01为轻量自动化选择运行器
  2. 02将生产发布设为不可变
  3. 03让自定义 Action 迁移到 Node24
  4. 04限制并固定工作流 Action

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/josiahsiegel/claude-plugin-marketplace --skill github-actions-2025

安装后在 Claude Code 中输入/github-actions-2025确认已加载。

详细介绍

GitHub Actions 2025 年功能

1 vCPU Linux 运行器(2025 年 10 月 — 公开预览)

内容: 新增轻量级运行器,针对自动化任务进行了优化,成本更低。

规格:

  • 1 vCPU
  • 5 GB RAM
  • 作业时限为 15 分钟
  • 针对短时运行任务进行了优化
何时使用 1 vCPU 运行器

适用于:

  • Issue 分类自动化
  • 标签管理
  • PR 评论自动化
  • 状态检查
  • 轻量级脚本
  • Git 操作(检出、打标签、提交)
  • 通知任务

不适用于:

  • 构建操作
  • 测试套件
  • 复杂的 CI/CD 管道
  • 资源密集型操作
用法
# .github/workflows/automation.yml
name: Lightweight Automation

on:
  issues:
    types: [opened, labeled]

jobs:
  triage:
    runs-on: ubuntu-latest-1-core  # New 1 vCPU runner
    timeout-minutes: 10  # Max 15 minutes
    steps:
      - name: Triage Issue
        run: |
          echo "Triaging issue..."
          gh issue edit ${{ github.event.issue.number }} --add-label "needs-review"
成本节省示例
# Before: Using 2 vCPU runner for simple task
jobs:
  label:
    runs-on: ubuntu-latest  # 2 vCPU, higher cost
    steps:
      - name: Add label
        run: gh pr edit ${{ github.event.number }} --add-label "reviewed"

# After: Using 1 vCPU runner (lower cost)
jobs:
  label:
    runs-on: ubuntu-latest-1-core  # 1 vCPU, 50% cost reduction
    timeout-minutes: 5
    steps:
      - name: Add label
        run: gh pr edit ${{ github.event.number }} --add-label "reviewed"

不可变发布(2025 年 8 月)

内容: 现在可以将发布标记为不可变——发布后,资产和 Git 标签都无法更改或删除。

优点:

  • 供应链安全
  • 满足审计要求
  • 防止篡改
  • 增强对发布构件的信任
创建不可变发布
# Using GitHub CLI
gh release create v1.0.0 \
  dist/*.zip \
  --title "Version 1.0.0" \
  --notes-file CHANGELOG.md \
  --immutable

# Verify immutability
gh release view v1.0.0 --json isImmutable
GitHub Actions 工作流
# .github/workflows/release.yml
name: Create Immutable Release

on:
  push:
    tags:
      - 'v*'

jobs:
  release:
    runs-on: ubuntu-latest
    permissions:
      contents: write

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Build artifacts
        run: npm run build

      - name: Create Immutable Release
        uses: actions/github-script@v7
        with:
          script: |
            const fs = require('fs');
            const tag = context.ref.replace('refs/tags/', '');

            await github.rest.repos.createRelease({
              owner: context.repo.owner,
              repo: context.repo.repo,
              tag_name: tag,
              name: `Release ${tag}`,
              body: fs.readFileSync('CHANGELOG.md', 'utf8'),
              draft: false,
              prerelease: false,
              make_immutable: true  # Mark as immutable
            });

      - name: Upload Release Assets
        run: gh release upload ${{ github.ref_name }} dist/*.zip --clobber
不可变发布策略
# Organizational policy for immutable releases
name: Enforce Immutable Releases

on:
  release:
    types: [created]

jobs:
  enforce-immutability:
    runs-on: ubuntu-latest
    if: "!github.event.release.immutable && startsWith(github.event.release.tag_name, 'v')"

    steps:
      - name: Fail if not immutable
        run: |
          echo "ERROR: Production releases must be immutable"
          exit 1

Node24 迁移(2025 年 9 月)

内容: GitHub Actions 将于 2025 年秋季从 Node20 迁移到 Node24。

时间表:

  • 2025 年 9 月:新增 Node24 支持
  • 2025 年 10 月:发布 Node20 弃用通知
  • 2025 年 11 月:开始逐步淘汰 Node20
  • 2025 年 12 月:全面迁移到 Node24
更新你的 Actions

检查 Actions 中的 Node 版本:

# Old - Node20
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/setup-node@v3
        with:
          node-version: '20'  # Update to 24

# New - Node24
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/setup-node@v4
        with:
          node-version: '24'  # Current LTS
运行器版本兼容性
# Ensure runner supports Node24
jobs:
  test:
    runs-on: ubuntu-latest  # Runner v2.328.0+ supports Node24

    steps:
      - name: Verify Node version
        run: node --version  # Should show v24.x.x
自定义 Actions 迁移

如果你维护自定义 Actions:

// action.yml
runs:
  using: 'node24'  // Updated from 'node20'
  main: 'index.js'
# Update dependencies
npm install @actions/core@latest
npm install @actions/github@latest

# Test with Node24
node --version  # Ensure 24.x
npm test

Actions 环境变量(2025 年 5 月)

内容: 现在所有套餐均可使用 Actions 环境(适用于公开和私有仓库)。

环境保护规则
# .github/workflows/deploy.yml
name: Deploy to Production

on:
  push:
    branches: [main]

jobs:
  deploy:
    runs-on: ubuntu-latest
    environment:
      name: production
      url: https://app.example.com

    steps:
      - name: Deploy
        run: |
          echo "Deploying to ${{ vars.DEPLOY_URL }}"
          # Deployment steps...

环境配置:

  • Settings → Environments → production
  • 添加保护规则:
    • 必需的审核者
    • 等待计时器
    • 部署分支(仅限 main)

允许的 Actions 策略更新(2025 年 8 月)

内容: 通过显式阻止和 SHA 固定增强治理能力。

阻止特定 Actions
# .github/workflows/policy.yml
# Repository or organization settings
allowed-actions:
  verified-only: true

  # Explicitly block actions
  blocked-actions:
    - 'untrusted/action@*'
    - 'deprecated-org/*'

  # Require SHA pinning for security
  require-sha-pinning: true
通过 SHA 固定增强安全性
# Before: Version pinning (can be changed by action maintainer)
- uses: actions/checkout@v4

# After: SHA pinning (immutable)
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11  # v4.1.1
生成 SHA 固定的 Actions
# Get commit SHA for specific version
gh api repos/actions/checkout/commits/v4.1.1 --jq '.sha'

# Or use action-security tool
npx pin-github-action actions/checkout@v4
# Output: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11

Copilot 触发的工作流(2025 年 4 月)

内容: 由 Copilot 编写的事件触发的工作流现在需要明确批准。

配置 Copilot 工作流审批
# .github/workflows/copilot-automation.yml
name: Copilot PR Automation

on:
  pull_request:
    types: [opened]

jobs:
  copilot-review:
    runs-on: ubuntu-latest

    # Copilot-generated PRs require approval
    if: github.event.pull_request.user.login != 'github-copilot[bot]'

    steps:
      - name: Auto-review
        run: gh pr review --approve

Copilot PR 需要手动批准(机制与来自 fork 的 PR 相同)。

构件存储架构(2025 年 2 月)

内容: 构件于 2025 年 2 月 1 日迁移到新架构。

重大变更:

  • actions/upload-artifact@v1-v2 于 2025 年 3 月 1 日停用
  • 必须使用 actions/upload-artifact@v4+
迁移
# Old (Retired)
- uses: actions/upload-artifact@v2
  with:
    name: build-artifacts
    path: dist/

# New (Required)
- uses: actions/upload-artifact@v4
  with:
    name: build-artifacts
    path: dist/
    retention-days: 30

Windows Server 2019 停用(2025 年 6 月)

内容: windows-2019 运行器映像于 2025 年 6 月 30 日完全停用。

迁移
# Old
jobs:
  build:
    runs-on: windows-2019  # Retired

# New
jobs:
  build:
    runs-on: windows-2022  # Current
    # Or windows-latest (recommended)

自托管运行器的 Meta API(2025 年 5 月)

内容: Meta API 新增 actions_inbound 部分,用于网络配置。

# Get network requirements for self-hosted runners
curl https://api.github.com/meta | jq '.actions_inbound'

# Configure firewall rules based on response
{
  "domains": [
    "*.actions.githubusercontent.com",
    "*.pkg.github.com"
  ],
  "ip_ranges": [
    "140.82.112.0/20",
    "143.55.64.0/20"
  ]
}

2025 年最佳实践

1. 使用合适的运行器
# Use 1 vCPU for lightweight tasks
jobs:
  label-management:
    runs-on: ubuntu-latest-1-core
    timeout-minutes: 5

  # Use standard runners for builds/tests
  build:
    runs-on: ubuntu-latest
2. 在生产环境中使用不可变发布
# Always mark production releases as immutable
- name: Create Release
  run: gh release create $TAG --immutable
3. 通过 SHA 固定增强安全性
# Pin actions to SHA, not tags
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8
4. 更新到 Node24
# Use latest Node version
- uses: actions/setup-node@v4
  with:
    node-version: '24'
5. 环境保护
# Use environments for deployments
jobs:
  deploy:
    environment: production
    # Requires approval, wait timer, branch restrictions

故障排查

1 vCPU 运行器超时:

# Ensure task completes within 15 minutes
jobs:
  task:
    runs-on: ubuntu-latest-1-core
    timeout-minutes: 10  # Safety margin

Node24 兼容性问题:

# Test locally with Node24
nvm install 24
nvm use 24
npm test

构件上传失败:

# Use v4 of artifact actions
- uses: actions/upload-artifact@v4  # Not v1/v2

资源

评论

支持 Markdown