跳至内容

使用 CI 工作流

以下 GitHub Actions 需要添加到.github/workflows 目录下,文件名格式为 {filename}.yaml。此 GitHub Actions 工作流自动化执行 Ansible 内容开发中的一系列任务,包括变更日志生成、代码检查、集成测试、完整性检查和单元测试。all_green 作业用于验证所有先前任务的成功完成。

文件名: test.yaml

---
name: "CI"

concurrency:
  group: ${{ github.head_ref || github.run_id }}
  cancel-in-progress: true

on:
  pull_request:
    branches: [main]
  workflow_dispatch:
  schedule:
    - cron: '0 0 * * *'

jobs:
  changelog:
    uses: ansible/ansible-content-actions/.github/workflows/changelog.yaml@main
    if: github.event_name == 'pull_request'
  ansible-lint:
    uses: ansible/ansible-content-actions/.github/workflows/ansible_lint.yaml@main
  sanity:
    uses: ansible/ansible-content-actions/.github/workflows/sanity.yaml@main
  unit-galaxy:
    uses: ansible/ansible-content-actions/.github/workflows/unit.yaml@main
  integration:
    uses: ansible/ansible-content-actions/.github/workflows/integration.yaml@main
  all_green:
    if: ${{ always() }}
    needs:
      - changelog
      - sanity
      - integration
      - unit-galaxy
      - ansible-lint
    runs-on: ubuntu-24.04
    steps:
      - run: >-
          python -c "assert 'failure' not in
          set([
          '${{ needs.changelog.result }}',
          '${{ needs.integration.result }}',
          '${{ needs.sanity.result }}',
          '${{ needs.unit-galaxy.result }}',
          '${{ needs.ansible-lint.result }}'
          ])"

工作流运行结果 -

Alt text

工作流使用 tox-ansible 和 pytest-ansible 生成矩阵,用于运行单元测试、完整性测试和集成测试。

请参考 tox-ansible 文档 查看更多选项。