Skip to content

Commit e8afeb4

Browse files
[Docs] - Add page about running on GitHub CI
1 parent 35dad1c commit e8afeb4

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed

.github/workflows/pr_validation.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ jobs:
2020
# Run all tests
2121
- run: flutter test test_goldens
2222

23+
# Archive golden failures
24+
- uses: actions/upload-artifact@v4
25+
if: failure()
26+
with:
27+
name: golden-failures
28+
path: "**/failures/**/*.png"
29+
2330
build_website:
2431
runs-on: ubuntu-latest
2532
defaults:

doc/website/source/_data.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ navigation:
5353
tag: failure-scenes
5454
sortBy: navOrder
5555

56+
- title: Running Goldens
57+
tag: running-goldens
58+
sortBy: navOrder
59+
5660
- title: Reduce Flakiness
5761
tag: reduce-flakiness
5862
sortBy: navOrder
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tags: running-goldens
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
title: Running on GitHub
3+
description: How to run and manage golden tests on GitHub CI.
4+
navOrder: 10
5+
---
6+
GitHub is the most popular place to run tests, including golden tests, because its
7+
free, and GitHub is the place where almost everyone hosts their source code and
8+
reviews pull requests (PRs).
9+
10+
## Run Golden Tests on GitHub
11+
The following YAML configuration shows how to run Flutter golden tests in a GitHub
12+
Runner. This particular example is configured to run on every PR, but you can adjust
13+
it for other use-cases. Place this configuration in your project at `.github/workflows/pr_validation.yaml`.
14+
15+
```yaml
16+
name: PR Validation
17+
on:
18+
pull_request:
19+
20+
jobs:
21+
test_goldens:
22+
runs-on: ubuntu-latest
23+
steps:
24+
# Checkout the repository.
25+
- uses: actions/checkout@v3
26+
27+
# Setup Flutter environment.
28+
- uses: subosito/flutter-action@v2
29+
with:
30+
channel: "stable"
31+
32+
# Download all the packages that the app uses.
33+
- run: flutter pub get
34+
35+
# Run all golden tests (change for whatever directory you use).
36+
- run: flutter test test_goldens
37+
```
38+
39+
## Download Failures from GitHub
40+
By default, when running golden tests on GitHub CI, you can only see the terminal
41+
output for failures. It's often very helpful to be able to see the actual Failure
42+
Scenes, so that you can understand why your local tests passed, but GitHub failed.
43+
44+
To be able to download Failure Scene images, you must configure GitHub CI to upload
45+
those images within the job.
46+
47+
Assuming that all of your failure are stored within subdirectories called `failures`,
48+
adjust your GitHub CI configuration to place the following step at the end of your
49+
job. This typically follows immediately after `- run: flutter test test_goldens`.
50+
51+
```yaml
52+
# Archive golden failures
53+
- uses: actions/upload-artifact@v4
54+
if: failure()
55+
with:
56+
name: golden-failures
57+
path: "**/failures/**/*.png"
58+
```
59+
60+
Adjust the `path` for wherever/however you choose to store your failure images.

0 commit comments

Comments
 (0)