跳转到主要内容

CI 工作流程

您可以使用 CI 工作流程运行端到端测试,这允许您持续检查中断。我们建议您使用以下 GitHub 工作流程在您的 GitHub 仓库中的每个 PR 上运行针对各种 Grafana 版本的端到端测试。

注意

这些是基于前端和后端插件的通用示例。在使用之前,您可能需要修改或删除 playwright-tests 作业中的某些步骤。

后端插件工作流程

.github/workflows/e2e.yml
name: E2E tests
on:
pull_request:
schedule:
- cron: '0 11 * * *' #Run e2e tests once a day at 11 UTC

permissions:
contents: read
id-token: write

jobs:
resolve-versions:
name: Resolve Grafana images
runs-on: ubuntu-latest
timeout-minutes: 3
outputs:
matrix: ${{ steps.resolve-versions.outputs.matrix }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Resolve Grafana E2E versions
id: resolve-versions
uses: grafana/plugin-actions/e2e-version@main

playwright-tests:
needs: resolve-versions
timeout-minutes: 60
strategy:
fail-fast: false
matrix:
GRAFANA_IMAGE: ${{fromJson(needs.resolve-versions.outputs.matrix)}}
name: e2e ${{ matrix.GRAFANA_IMAGE.name }}@${{ matrix.GRAFANA_IMAGE.VERSION }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc

- name: Install npm dependencies
run: npm ci

- name: Install Mage
uses: magefile/mage-action@v3
with:
install-only: true

- name: Build binaries
run: mage -v build:linux

- name: Build frontend
run: npm run build

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

- name: Start Grafana
run: |
docker compose pull
GRAFANA_VERSION=${{ matrix.GRAFANA_IMAGE.VERSION }} GRAFANA_IMAGE=${{ matrix.GRAFANA_IMAGE.NAME }} docker compose up -d

- name: Wait for grafana server
uses: grafana/plugin-actions/wait-for-grafana@main

- name: Run Playwright tests
id: run-tests
run: npx playwright test

# Uncomment this step to upload the Playwright report to Github artifacts.
# If your repository is public, the report will be public on the Internet so beware not to expose sensitive information.
# - name: Upload artifacts
# uses: actions/upload-artifact@v4
# if: ${{ (always() && steps.run-tests.outcome == 'success') || (failure() && steps.run-tests.outcome == 'failure') }}
# with:
# name: playwright-report-${{ matrix.GRAFANA_IMAGE.NAME }}-v${{ matrix.GRAFANA_IMAGE.VERSION }}-${{github.run_id}}
# path: playwright-report/
# retention-days: 30

前端插件工作流程

.github/workflows/e2e.yml
name: E2E tests
on:
pull_request:
schedule:
- cron: '0 11 * * *' #Run e2e tests once a day at 11 UTC

permissions:
contents: read
id-token: write

jobs:
resolve-versions:
name: Resolve Grafana images
runs-on: ubuntu-latest
timeout-minutes: 3
outputs:
matrix: ${{ steps.resolve-versions.outputs.matrix }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Resolve Grafana E2E versions
id: resolve-versions
uses: grafana/plugin-actions/e2e-version@main

playwright-tests:
needs: resolve-versions
timeout-minutes: 60
strategy:
fail-fast: false
matrix:
GRAFANA_IMAGE: ${{fromJson(needs.resolve-versions.outputs.matrix)}}
name: e2e ${{ matrix.GRAFANA_IMAGE.name }}@${{ matrix.GRAFANA_IMAGE.VERSION }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc

- name: Install npm dependencies
run: npm ci

- name: Build frontend
run: npm run build

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

- name: Start Grafana
run: |
docker compose pull
GRAFANA_VERSION=${{ matrix.GRAFANA_IMAGE.VERSION }} GRAFANA_IMAGE=${{ matrix.GRAFANA_IMAGE.NAME }} docker compose up -d

- name: Wait for grafana server
uses: grafana/plugin-actions/wait-for-grafana@main

- name: Run Playwright tests
id: run-tests
run: npx playwright test

# Uncomment this step to upload the Playwright report to Github artifacts.
# If your repository is public, the report will be public on the Internet so beware not to expose sensitive information.
# - name: Upload artifacts
# uses: actions/upload-artifact@v4
# if: ${{ (always() && steps.run-tests.outcome == 'success') || (failure() && steps.run-tests.outcome == 'failure') }}
# with:
# name: playwright-report-${{ matrix.GRAFANA_IMAGE.NAME }}-v${{ matrix.GRAFANA_IMAGE.VERSION }}-${{github.run_id}}
# path: playwright-report/
# retention-days: 30

端到端版本 Action

这些示例工作流程中有一个名为 Resolve Grafana images 的作业,它使用 e2e-version Action 来解析 Grafana 图像列表。对于返回的每个图像,都会启动一个新的作业来构建插件,启动 Grafana 并运行端到端测试。

该 Action 支持两种模式

  • plugin-grafana-dependency
  • version-support-policy.

使用插件-grafana-dependency 模式

默认情况下是 plugin-grafana-dependency 模式,因此如果您未指定 version-resolver-type 输入参数的值,则将使用此解析器。

此模式返回最新的 grafana-dev 镜像。此外,它还返回自 grafanaDependencyplugin.json 中指定的版本以来的 Grafana Enterprise 的所有最新补丁版本。为了避免启动过多的作业,输出版本数限制为 6 个。

plugin-grafana-dependency mode
plugin-grafana-dependency 模式

使用版本支持策略模式

除了解决最新的 grafana-dev 镜像外,version-support-policy 模式根据 Grafana 的插件兼容性支持策略解决版本。具体来说,它会检索 Grafana 当前主版本中每个次版本的最新补丁版本。此外,它还包括上一主版本最新次版本的最新版本。

Grafana version support policy
Grafana 版本支持策略

要使用 version-support-policy 模式,您需要指定类似于以下示例中的 version-resolver-type 输入参数

- name: Resolve Grafana E2E versions
id: resolve-versions
uses: grafana/plugin-actions/e2e-version
with:
version-resolver-type: version-support-policy

Playwright 报告

端到端工具为每个正在测试的 Grafana 版本生成 Playwright HTML 测试报告。如果任何测试失败,还会生成与报告一起的 Playwright 跟踪查看器。示例工作流程中的 上传工件 步骤将报告作为工件上传到 GitHub。

有关下载和查看报告的信息,请参阅 Playwright 文档