Elysia Tools

在一个清晰的工作台里浏览工具、案例、可视化和主题指南。

热门分类

专题

语言
ZHESPTRUFRDEEN

Elysia Tools

导航

测试

GitHub Actions 分支过滤、矩阵行与条件 | Elysia Tools

用明确输入与可独立核对的结果,完成三个范围有限的 GitHub Actions 练习。

案例

这个案例集合中的条目

代码text简单

GitHub Actions 基础测试设置

完整的 GitHub Actions 测试设置,包含基础工作流、测试执行、报告和 CI/CD 集成

难度

3/10

预计时间

40 min

标签

github actions, ci cd, setup, workflows

前置条件

Git basics, CI/CD concepts, YAML, JavaScript/TypeScript

text
# GitHub Actions Testing - Basic Setup and Configuration

# 1. .github/workflows/test.yml - Basic Testing Workflow
name: Tests

on:
  push:
    branches: [ main, develop ]
  pull_request:
    branches: [ main ]

env:
  NODE_VERSION: '18'
  NODE_OPTIONS: '--max-old-space-size=4096'

jobs:
  # Unit Tests
  unit-tests:
    name: Unit Tests
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [16, 18, 20]

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

      - name: Setup Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node-version }}
          cache: 'npm'

      - name: Install dependencies
        run: npm ci

      - name: Run unit tests
        run: npm run test:unit

      - name: Upload coverage reports
        if: matrix.node-version == '18'
        uses: codecov/codecov-action@v3
        with:
          file: ./coverage/lcov.info
          flags: unittests
          name: codecov-umbrella

  # Integration Tests
  integration-tests:
    name: Integration Tests
    runs-on: ubuntu-latest

    services:
      postgres:
        image: postgres:15
        env:
          POSTGRES_PASSWORD: postgres
          POSTGRES_DB: test_db
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5
        ports:
          - 5432:5432

      redis:
        image: redis:7
        options: >-
          --health-cmd "redis-cli ping"
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5
        ports:
          - 6379:6379

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

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: ${{ env.NODE_VERSION }}
          cache: 'npm'

      - name: Install dependencies
        run: npm ci

      - name: Setup test environment
        run: |
          cp .env.test .env
          npm run db:migrate

      - name: Run integration tests
        run: npm run test:integration
        env:
          DATABASE_URL: postgresql://postgres:postgres@localhost:5432/test_db
          REDIS_URL: redis://localhost:6379

  # End-to-End Tests
  e2e-tests:
    name: E2E Tests
    runs-on: ubuntu-latest

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

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: ${{ env.NODE_VERSION }}
          cache: 'npm'

      - name: Install dependencies
        run: npm ci

      - name: Install Playwright browsers
        run: npx playwright install --with-deps

      - name: Build application
        run: npm run build

      - name: Run E2E tests
        run: npm run test:e2e

      - name: Upload test results
        uses: actions/upload-artifact@v3
        if: always()
        with:
          name: playwright-report
          path: playwright-report/

# 2. .github/workflows/quality.yml - Code Quality Checks
name: Code Quality

on:
  pull_request:
    branches: [ main ]

jobs:
  lint:
    name: Lint Code
    runs-on: ubuntu-latest

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

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: ${{ env.NODE_VERSION }}
          cache: 'npm'

      - name: Install dependencies
        run: npm ci

      - name: Run ESLint
        run: npm run lint

      - name: Run Prettier check
        run: npm run format:check

      - name: Type checking
        run: npm run type-check

  security:
    name: Security Audit
    runs-on: ubuntu-latest

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

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: ${{ env.NODE_VERSION }}
          cache: 'npm'

      - name: Run security audit
        run: npm audit --audit-level=moderate

      - name: Run Snyk security scan
        uses: snyk/actions/node@master
        env:
          SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}

# 3. .github/workflows/performance.yml - Performance Testing
name: Performance Tests

on:
  schedule:
    - cron: '0 2 * * *'  # Run daily at 2 AM UTC
  workflow_dispatch:

jobs:
  lighthouse:
    name: Lighthouse Performance Test
    runs-on: ubuntu-latest

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

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: ${{ env.NODE_VERSION }}
          cache: 'npm'

      - name: Install dependencies
        run: npm ci

      - name: Build application
        run: npm run build

      - name: Run Lighthouse CI
        run: |
          npm install -g @lhci/cli@0.12.x
          lhci autorun
        env:
          LHCI_GITHUB_APP_TOKEN: ${{ secrets.LHCI_GITHUB_APP_TOKEN }}

  load-testing:
    name: Load Testing
    runs-on: ubuntu-latest

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

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: ${{ env.NODE_VERSION }}

      - name: Install k6
        run: |
          sudo gpg -k
          sudo gpg --no-default-keyring --keyring /usr/share/keyrings/k6-archive-keyring.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C5AD17C747E3415A3642D57D77C6C491D6AC1D69
          echo "deb [signed-by=/usr/share/keyrings/k6-archive-keyring.gpg] https://dl.k6.io/deb stable main" | sudo tee /etc/apt/sources.list.d/k6.list
          sudo apt-get update
          sudo apt-get install k6

      - name: Run load tests
        run: k6 run --out json=results.json tests/performance/load-test.js

      - name: Upload results
        uses: actions/upload-artifact@v3
        with:
          name: load-test-results
          path: results.json

# 4. package.json scripts configuration
{
  "name": "example-project",
  "version": "1.0.0",
  "scripts": {
    "test": "npm run test:unit && npm run test:integration && npm run test:e2e",
    "test:unit": "jest",
    "test:unit:watch": "jest --watch",
    "test:unit:coverage": "jest --coverage",
    "test:integration": "jest --config=jest.integration.config.js",
    "test:e2e": "playwright test",
    "test:e2e:headed": "playwright test --headed",
    "test:e2e:debug": "playwright test --debug",
    "lint": "eslint src/**/*.js tests/**/*.js",
    "lint:fix": "eslint src/**/*.js tests/**/*.js --fix",
    "format": "prettier --write src/**/* tests/**/*",
    "format:check": "prettier --check src/**/* tests/**/*",
    "type-check": "tsc --noEmit",
    "build": "tsc && npm run build:assets",
    "build:assets": "cp -r src/public dist/",
    "dev": "npm run build && node dist/index.js",
    "db:migrate": "sequelize-cli db:migrate",
    "db:seed": "sequelize-cli db:seed:all"
  },
  "devDependencies": {
    "@playwright/test": "^1.40.0",
    "@lhci/cli": "^0.12.0",
    "eslint": "^8.55.0",
    "prettier": "^3.1.0",
    "jest": "^29.7.0",
    "jest-environment-node": "^29.7.0",
    "snyk": "^1.1291.0"
  }
}

# 5. .github/workflows/notify.yml - Test Result Notifications
name: Test Notifications

on:
  workflow_run:
    workflows: ["Tests"]
    types:
      - completed

jobs:
  notify:
    name: Send Notifications
    runs-on: ubuntu-latest
    if: ${{ github.event.workflow_run.conclusion == 'failure' }}

    steps:
      - name: Send Slack notification
        uses: 8398a7/action-slack@v3
        with:
          status: failure
          channel: '#dev-alerts'
          webhook_url: ${{ secrets.SLACK_WEBHOOK }}
          text: |
            Tests failed for ${{ github.repository }}
            Branch: ${{ github.ref }}
            Commit: ${{ github.sha }}
            View details: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}

      - name: Send email notification
        uses: dawidd6/action-send-mail@v3
        with:
          server_address: smtp.gmail.com
          server_port: 587
          username: ${{ secrets.EMAIL_USERNAME }}
          password: ${{ secrets.EMAIL_PASSWORD }}
          subject: "Test Failed - ${{ github.repository }}"
          body: |
            Tests failed for ${{ github.repository }}

            Branch: ${{ github.ref }}
            Commit: ${{ github.sha }}
            Author: ${{ github.event.head_commit.author.name }}

            View details: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
          to: ${{ secrets.NOTIFICATION_EMAIL }}
          from: GitHub Actions

# 6. .github/workflows/release.yml - Release Testing
name: Release

on:
  release:
    types: [published]

jobs:
  release-tests:
    name: Pre-release Testing
    runs-on: ubuntu-latest

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

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: ${{ env.NODE_VERSION }}
          cache: 'npm'

      - name: Install dependencies
        run: npm ci

      - name: Run full test suite
        run: npm run test

      - name: Build release
        run: npm run build

      - name: Run smoke tests
        run: npm run test:smoke

      - name: Upload release artifacts
        uses: actions/upload-release-asset@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          upload_url: ${{ github.event.release.upload_url }}
          asset_path: ./dist/app.zip
          asset_name: app-v${{ github.event.release.tag_name }}.zip
          asset_content_type: application/zip

# 7. jest.config.js - Jest Configuration for CI
module.exports = {
  preset: 'ts-jest',
  testEnvironment: 'node',
  roots: ['<rootDir>/src', '<rootDir>/tests'],
  testMatch: [
    '**/__tests__/**/*.+(ts|tsx|js)',
    '**/*.(test|spec).+(ts|tsx|js)'
  ],
  transform: {
    '^.+\.(ts|tsx)$': 'ts-jest',
  },
  collectCoverageFrom: [
    'src/**/*.{ts,tsx}',
    '!src/**/*.d.ts',
    '!src/index.ts',
  ],
  coverageDirectory: 'coverage',
  coverageReporters: [
    'text',
    'lcov',
    'html',
    'json'
  ],
  coverageThreshold: {
    global: {
      branches: 80,
      functions: 80,
      lines: 80,
      statements: 80
    }
  },
  setupFilesAfterEnv: ['<rootDir>/tests/setup.ts'],
  testTimeout: 30000,
};
代码text复杂

高级 GitHub Actions 测试模式

复杂的 CI/CD 模式,包括矩阵构建、缓存策略、测试并行化、条件执行和企业级工作流优化

难度

8/10

预计时间

90 min

标签

github actions, advanced, matrix, caching, optimization

前置条件

GitHub Actions basics, CI/CD advanced, YAML, DevOps concepts

text
# GitHub Actions Advanced Testing Patterns

# 1. .github/workflows/matrix-testing.yml - Advanced Matrix Strategy
name: Matrix Testing

on:
  push:
    branches: [ main, develop ]
  pull_request:
    branches: [ main ]

env:
  REGISTRY: ghcr.io
  IMAGE_NAME: ${{ github.repository }}

jobs:
  # Matrix strategy for multiple environments
  test-matrix:
    name: Test (${{ matrix.os }}, Node ${{ matrix.node-version }})
    runs-on: ${{ matrix.os }}

    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]
        node-version: [16, 18, 20]
        include:
          - os: ubuntu-latest
            node-version: 20
            coverage: true
          - os: windows-latest
            node-version: 18
            edge-cases: true
          - os: macos-latest
            node-version: 16
            browser-tests: true
        exclude:
          - os: windows-latest
            node-version: 16

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

      - name: Setup Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node-version }}
          cache: 'npm'

      - name: Install dependencies
        run: npm ci

      - name: Cache node modules
        uses: actions/cache@v3
        with:
          path: ~/.npm
          key: ${{ runner.os }}-node-${{ matrix.node-version }}-${{ hashFiles('**/package-lock.json') }}
          restore-keys: |
            ${{ runner.os }}-node-${{ matrix.node-version }}-

      - name: Install browsers
        if: matrix.browser-tests
        run: npx playwright install chromium firefox webkit

      - name: Run unit tests
        run: npm run test:unit

      - name: Run tests with coverage
        if: matrix.coverage
        run: npm run test:coverage

      - name: Run edge case tests
        if: matrix.edge-cases
        run: npm run test:edge-cases

      - name: Run browser tests
        if: matrix.browser-tests
        run: npm run test:browser

      - name: Upload coverage to Codecov
        if: matrix.coverage && matrix.os == 'ubuntu-latest'
        uses: codecov/codecov-action@v3
        with:
          file: ./coverage/lcov.info
          flags: ${{ matrix.os }}-node${{ matrix.node-version }}
          name: codecov-${{ matrix.os }}-${{ matrix.node-version }}

  # Parallel execution with test splitting
  parallel-tests:
    name: Parallel Tests (Shard ${{ matrix.shard }}/${{ strategy.job-total }})
    runs-on: ubuntu-latest

    strategy:
      matrix:
        shard: [1, 2, 3, 4]

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

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '18'
          cache: 'npm'

      - name: Install dependencies
        run: npm ci

      - name: Split tests
        id: split-tests
        run: |
          # Get total number of tests and split them
          TEST_FILES=$(npm run test:list 2>/dev/null | grep -E "\.test\.|\.spec\." | wc -l)
          echo "total-tests=$TEST_FILES" >> $GITHUB_OUTPUT

          # Calculate which tests to run for this shard
          SHARD_SIZE=$((TEST_FILES / 4 + 1))
          START=$(((matrix.shard - 1) * SHARD_SIZE + 1))
          END=$((matrix.shard * SHARD_SIZE))

          echo "start=$START" >> $GITHUB_OUTPUT
          echo "end=$END" >> $GITHUB_OUTPUT

      - name: Run shard tests
        run: |
          npm run test:shard -- --shard=${{ matrix.shard }}/4

      - name: Upload test results
        uses: actions/upload-artifact@v3
        with:
          name: test-results-shard-${{ matrix.shard }}
          path: test-results/

# 2. .github/workflows/conditional-testing.yml - Conditional Execution
name: Conditional Testing

on:
  push:
    branches: [ main ]
  pull_request:
    types: [opened, synchronize, reopened]

jobs:
  detect-changes:
    name: Detect Changes
    runs-on: ubuntu-latest
    outputs:
      backend-changed: ${{ steps.changes.outputs.backend }}
      frontend-changed: ${{ steps.changes.outputs.frontend }}
      docs-changed: ${{ steps.changes.outputs.docs }}
      all-changed: ${{ steps.changes.outputs.all }}

    steps:
      - name: Checkout code
        uses: actions/checkout@v4
        with:
          fetch-depth: 2

      - name: Detect file changes
        id: changes
        uses: dorny/paths-filter@v2
        with:
          filters: |
            backend:
              - 'src/backend/**'
              - 'package.json'
            frontend:
              - 'src/frontend/**'
              - 'public/**'
            docs:
              - 'docs/**'
              - '**/*.md'
            all:
              - '**'

  # Conditional job execution
  backend-tests:
    name: Backend Tests
    needs: detect-changes
    if: needs.detect-changes.outputs.backend-changed == 'true'
    runs-on: ubuntu-latest

    services:
      postgres:
        image: postgres:15
        env:
          POSTGRES_PASSWORD: postgres
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5
        ports:
          - 5432:5432

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

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '18'
          cache: 'npm'

      - name: Install dependencies
        run: npm ci

      - name: Run backend tests
        run: |
          npm run test:backend
          npm run test:api

      - name: Run integration tests
        run: npm run test:integration

  frontend-tests:
    name: Frontend Tests
    needs: detect-changes
    if: needs.detect-changes.outputs.frontend-changed == 'true'
    runs-on: ubuntu-latest

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

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '18'
          cache: 'npm'

      - name: Install dependencies
        run: npm ci

      - name: Install Playwright browsers
        run: npx playwright install --with-deps

      - name: Build application
        run: npm run build:frontend

      - name: Run frontend tests
        run: npm run test:frontend

      - name: Run E2E tests
        run: npm run test:e2e

  full-suite:
    name: Full Test Suite
    needs: detect-changes
    if: |
      needs.detect-changes.outputs.all-changed == 'true' ||
      github.event_name == 'schedule' ||
      contains(github.event.head_commit.message, '[full-test]')
    runs-on: ubuntu-latest

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

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '18'
          cache: 'npm'

      - name: Install dependencies
        run: npm ci

      - name: Run complete test suite
        run: npm run test:all

# 3. .github/workflows/caching-optimization.yml - Advanced Caching
name: Optimized Testing with Caching

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  test-with-caching:
    name: Tests with Advanced Caching
    runs-on: ubuntu-latest

    env:
      CACHE_VERSION: v2

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

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '18'

      - name: Cache node modules
        id: cache-node
        uses: actions/cache@v3
        with:
          path: |
            ~/.npm
            node_modules
          key: ${{ env.CACHE_VERSION }}-npm-${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}
          restore-keys: |
            ${{ env.CACHE_VERSION }}-npm-${{ runner.os }}-

      - name: Install dependencies
        if: steps.cache-node.outputs.cache-hit != 'true'
        run: npm ci

      - name: Cache build artifacts
        id: cache-build
        uses: actions/cache@v3
        with:
          path: |
            dist/
            .next/
            build/
          key: ${{ env.CACHE_VERSION }}-build-${{ github.sha }}
          restore-keys: |
            ${{ env.CACHE_VERSION }}-build-

      - name: Build application
        if: steps.cache-build.outputs.cache-hit != 'true'
        run: npm run build

      - name: Cache Playwright browsers
        uses: actions/cache@v3
        with:
          path: ~/.cache/ms-playwright
          key: ${{ env.CACHE_VERSION }}-playwright-${{ runner.os }}-${{ hashFiles('package-lock.json') }}

      - name: Install Playwright browsers
        run: npx playwright install --with-deps

      - name: Cache test database
        uses: actions/cache@v3
        with:
          path: |
            test-data/
            fixtures/
          key: ${{ env.CACHE_VERSION }}-test-data-${{ hashFiles('test-data/**') }}

      - name: Setup test database
        run: |
          npm run db:setup
          npm run db:seed

      - name: Run tests
        run: npm run test

      - name: Cache test results
        uses: actions/cache@v3
        with:
          path: |
            coverage/
            test-results/
            playwright-report/
          key: ${{ env.CACHE_VERSION }}-test-results-${{ github.sha }}

# 4. .github/workflows/reusable-workflows.yml - Reusable Workflows
# This file defines reusable workflows that can be called from other workflows

# .github/workflows/test-reusable.yml
name: Reusable Test Workflow

on:
  workflow_call:
    inputs:
      node-version:
        required: false
        type: string
        default: '18'
      test-type:
        required: false
        type: string
        default: 'all'
      cache-key:
        required: false
        type: string
        default: 'default'
    secrets:
      NPM_TOKEN:
        required: false
      CODECOV_TOKEN:
        required: false

jobs:
  run-tests:
    name: Tests (${{ inputs.test-type }})
    runs-on: ubuntu-latest

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

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: ${{ inputs.node-version }}
          cache: 'npm'

      - name: Install dependencies
        run: npm ci

      - name: Configure private registry
        if: secrets.NPM_TOKEN
        run: |
          echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" >> ~/.npmrc
          echo "@example:registry=https://npm.example.com" >> ~/.npmrc

      - name: Run tests based on type
        run: |
          case "${{ inputs.test-type }}" in
            "unit")
              npm run test:unit
              ;;
            "integration")
              npm run test:integration
              ;;
            "e2e")
              npm run test:e2e
              ;;
            "all")
              npm run test
              ;;
          esac

      - name: Upload coverage
        if: inputs.test-type != 'e2e' && secrets.CODECOV_TOKEN
        uses: codecov/codecov-action@v3
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
          flags: ${{ inputs.test-type }}

# .github/workflows/main.yml - Using reusable workflow
name: Main Testing Pipeline

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  unit-tests:
    uses: ./.github/workflows/test-reusable.yml
    with:
      node-version: '18'
      test-type: 'unit'
      cache-key: 'unit-tests'

  integration-tests:
    uses: ./.github/workflows/test-reusable.yml
    with:
      node-version: '18'
      test-type: 'integration'
      cache-key: 'integration-tests'
    secrets:
      NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
      CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

  e2e-tests:
    uses: ./.github/workflows/test-reusable.yml
    with:
      node-version: '20'
      test-type: 'e2e'
      cache-key: 'e2e-tests'

# 5. .github/workflows/test-metrics.yml - Test Metrics and Reporting
name: Test Metrics and Reporting

on:
  workflow_run:
    workflows: ["Tests"]
    types:
      - completed

jobs:
  generate-report:
    name: Generate Test Report
    runs-on: ubuntu-latest
    if: ${{ github.event.workflow_run.conclusion != 'skipped' }}

    steps:
      - name: Download artifacts
        uses: actions/download-artifact@v3
        with:
          name: test-results
          path: ./test-results

      - name: Generate test report
        run: |
          # Create comprehensive test report
          node scripts/generate-test-report.js

      - name: Update PR comment with results
        if: github.event_name == 'pull_request'
        uses: actions/github-script@v6
        with:
          script: |
            const fs = require('fs');
            const report = JSON.parse(fs.readFileSync('./test-report.json', 'utf8'));

            const comment = `## Test Results

            **Total Tests:** ${report.total}
            **Passed:** ${report.passed} ✅
            **Failed:** ${report.failed} ❌
            **Skipped:** ${report.skipped} ⏭️
            **Coverage:** ${report.coverage}%

            [View detailed report](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
            `;

            github.rest.issues.createComment({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              body: comment
            });

      - name: Update test metrics
        run: |
          # Update metrics in external system
          node scripts/update-metrics.js

      - name: Create test summary
        id: test-summary
        run: |
          # Create markdown summary
          echo "summary<<EOF" >> $GITHUB_OUTPUT
          cat test-summary.md >> $GITHUB_OUTPUT
          echo "EOF" >> $GITHUB_OUTPUT

      - name: Comment on PR
        uses: peter-evans/create-or-update-comment@v3
        if: github.event_name == 'pull_request'
        with:
          issue-number: ${{ github.event.pull_request.number }}
          body: ${{ steps.test-summary.outputs.summary }}

工具

经常与该案例搭配使用的工具

相关内容

相关案例集合

相关内容

相关专题

工具使用指南

帮助搜索与理解工作流的案例说明

概览

以下练习使用「GitHub Actions 基础测试设置」,只追踪指定代码块;其他卡片涉及不同语言功能和依赖。

选择最小示例

Node 版本与 action 修订是历史样本值,不是当前支持建议。不触发工作流、服务容器、下载或报告上传。

使用方式

  1. 1阅读指定卡片,追踪声明的值。样本页面展示代码,不会替你执行这种语言。

常见失败与 edge cases

  • 结果范围

    下面是从源码推导的预期结果,不是编译器或运行时实测输出。交互输入、时钟、文件、线程、外部服务和框架配置不在这些练习范围内。

示例

1. 追踪 Tests: on.push / on.pull_request

如何使用

在「GitHub Actions 基础测试设置」找到 Tests: on.push / on.pull_request,使用 push main;push develop;pull_request target main;pull_request target develop,只依次追踪指定操作,不改变顺序。

结果

预期:included;included;included;not selected by this filter。拉取请求的分支过滤针对目标分支,而非来源分支。

2. 追踪 unit-tests.strategy.matrix

如何使用

在「GitHub Actions 基础测试设置」找到 unit-tests.strategy.matrix,使用 node-version=[16,18,20],只依次追踪指定操作,不改变顺序。

结果

预期:3 combinations。一维矩阵有三个值,声明三个组合,不代表三个任务成功。

3. 追踪 Upload coverage reports: if condition

如何使用

在「GitHub Actions 基础测试设置」找到 Upload coverage reports: if condition,使用 synthetic matrix.node-version=16;18;20,只依次追踪指定操作,不改变顺序。

结果

预期:condition=false;true;false。只有 18 对应的行符合声明的比较;不上传覆盖率。

专题

结构与逻辑图生成器

从文本、JSON、集合定义或日志生成流程图、思维导图、组织架构图、树状图、韦恩图、ASCII 目录树与时序图。

专题

SVG 图标集打包与前端集成验收

清理已批准的 SVG 图标,选择内联或外部引用模式,在真实页面核对标识符、几何和着色,并导出单图标位图回退。

专题

音频测试信号制作、复核与交接

按测试目标制作扫频、双声道或测量激励素材,检查格式和预期信号表现,连同参数、复核证据及文件哈希交接,不把生成激励冒充实测声学响应。

专题

播客单集发布前音频与 RSS 一致性检查

将已完成的播客单集与 RSS 条目对照,核验最终文件字节数、类型及声明时长,再单独实测公开媒体地址与播放器表现。

首页
工具3216
案例593
可视化473
文件查看器103
专题239
标签333
图像、音频与视频657

图像、音频、视频处理、转换与优化工具

数学、日期与金融647

计算器、数值计算、日期逻辑、统计与金融工具

设计与颜色298

颜色、版式、图形、视觉样式与设计辅助工具

文本与写作209

写作、清洗、格式化、提取与文本分析工具

开发与 Web194

开发者工具、网络处理、Web 调试与自动化辅助工具

转换与编码175

格式、文件、压缩包、单位与编码转换工具

潜客测验发布与联系人交接
讣告、悼词与纪念卡的家属复核及交付
本地习惯记录的备份、恢复演练与分享前检查
长文改编 X 串文与 LinkedIn 帖子的事实复核与交付
Markdown 互动课件审校、离线演示与交付

© 2026 Elysia Tools. 保留所有权利。

文档价格关于我们服务条款隐私政策Cookie 政策联系我们

Development

GitHub 主页美化生成器

一键生成完整 GitHub 个人主页 README——横幅、统计磁贴、贡献热力图、3D 贡献天际线、项目卡片——一次性烘焙为静态、可换主题的 SVG 资产。不依赖任何会挂掉的徽章服务;把 SVG 提交到仓库,主页永不破图。

Document Tools

GitHub README转PDF

获取GitHub README并渲染为带样式的PDF

Development

正则表达式解释器

使用 AI 将正则表达式分解为可读的解释

Development

变更记录提取器

解析并从多种格式的变更记录和发行说明中提取结构化数据

Development

Glob转正则

将文件匹配模式 (Glob) 转换为正则表达式

Development

多规则批量匹配

一次性对文本执行多个正则表达式模式匹配

Development

命名分组测试器

解析并显示正则表达式中的命名捕获组

Development

正则替换预览器

实时预览正则替换,显示详细差异和统计

测试

Jest 测试框架

全面的Jest测试示例,包括单元测试、集成测试、模拟、异步测试和JavaScript/TypeScript应用的高级模式

测试

Playwright E2E 测试框架

全面的Playwright测试示例,包括跨浏览器自动化、API测试、移动端测试、视觉回归测试和现代Web应用的高级E2E模式

区块链

Hardhat 开发框架示例

Hardhat 以太坊开发环境示例,包括智能合约、测试、部署、脚本、插件和开发工作流

区块链

Truffle 开发套件示例

Truffle 以太坊开发框架示例,包括智能合约、测试、部署、迁移、调试和开发工作流

测试

BDD with Cucumber - 行为驱动开发实践

全面的 Cucumber BDD 示例,包括功能文件、步骤定义、数据表格、钩子和高级 BDD 模式,用于协作开发

测试

K6 现代性能测试工具

全面的 K6 性能测试示例,包括负载测试、压力测试、API性能测试和现代应用程序的高级测试模式