Skip to content

Commit

Permalink
Nest screenshot tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TWiStErRob committed Sep 14, 2023
1 parent 01843c3 commit 925b8d5
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 31 deletions.
1 change: 0 additions & 1 deletion .github/workflows/CI-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ on:
jobs:

build:
name: "🔨 Build & Verifx"
runs-on: ubuntu-latest
# A local build took 20 seconds, CI takes 3 minutes with setup.
# Because it's cloud, give it a bit of a buffer and constrain.
Expand Down
13 changes: 12 additions & 1 deletion .github/workflows/CI-pr.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
name: "Find PR"

on:
workflow_call
workflow_call:
outputs:
found:
value: ${{ jobs.pull_request.outputs.found }}
base_ref:
value: ${{ jobs.pull_request.outputs.base_ref }}
base_sha:
value: ${{ jobs.pull_request.outputs.base_sha }}
head_ref:
value: ${{ jobs.pull_request.outputs.head_ref }}
head_sha:
value: ${{ jobs.pull_request.outputs.head_sha }}

jobs:

Expand Down
17 changes: 11 additions & 6 deletions .github/workflows/CI-screenshot-record.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
name: "📸 Screenshot Tests / Record"
name: "📷 Screenshot Tests / 📸 Record"

on:
workflow_call
workflow_call:
inputs:
ref:
description: "The base branch to compare against."
type: string
required: true
default: "main"

jobs:

record:
name: "Record"
runs-on: ubuntu-latest
timeout-minutes: 20

Expand All @@ -32,12 +37,12 @@ jobs:
echo sdkmanager --install "platforms;android-34"
sdkmanager --install "platforms;android-34"
- name: "Checkout ${{ needs.pull_request.outputs.base_ref }} branch in ${{ github.repository }} repository."
- name: "Checkout ${{ inputs.ref }} branch in ${{ github.repository }} repository."
uses: actions/checkout@v4
with:
ref: ${{ format('refs/heads/{0}', needs.pull_request.outputs.base_ref) }}
ref: ${{ format('refs/heads/{0}', inputs.ref) }}

- name: "Record screenshots golden values for ${{ needs.pull_request.outputs.base_ref }}."
- name: "Record screenshots golden values for ${{ inputs.ref }}."
id: gradle
run: >
./gradlew
Expand Down
27 changes: 19 additions & 8 deletions .github/workflows/CI-screenshot-verify.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
name: "🧪 Screenshot Tests / Verify"
name: "📷 Screenshot Tests / 🧪 Verify"

on:
workflow_call
workflow_call:
inputs:
ref:
description: "The head branch to verify against base."
type: string
required: true

golden_artifact:
description: "The name of the artifact containing the golden values for all modules."
type: string
required: false
default: 'Screenshot Golden Values'

jobs:

verify:
name: "Verify"
name: "🧪 Verify"
runs-on: ubuntu-latest
timeout-minutes: 20

Expand All @@ -32,17 +43,17 @@ jobs:
echo sdkmanager --install "platforms;android-34"
sdkmanager --install "platforms;android-34"
- name: "Checkout ${{ needs.pull_request.outputs.head_ref }} branch in ${{ github.repository }} repository."
- name: "Checkout ${{ inputs.ref }} branch in ${{ github.repository }} repository."
uses: actions/checkout@v4
with:
ref: ${{ format('refs/heads/{0}', needs.pull_request.outputs.head_ref) }}
ref: ${{ format('refs/heads/{0}', inputs.ref) }}

- name: "Download 'Screenshot Golden Values' artifact."
- name: "Download '${{ inputs.golden_artifact }}' artifact."
uses: actions/download-artifact@v3
with:
name: 'Screenshot Golden Values'
name: '${{ inputs.golden_artifact }}'

- name: "Run screenshot tests to verify ${{ needs.pull_request.outputs.head_ref }}."
- name: "Run screenshot tests to verify ${{ inputs.ref }}."
id: gradle
run: >
./gradlew
Expand Down
33 changes: 33 additions & 0 deletions .github/workflows/CI-screenshot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: "📷 Screenshot Tests"

on:
workflow_call:
inputs:

base_ref:
description: "The base branch to compare against."
type: string
required: true
default: "main"

head_ref:
description: "The head branch to verify against base."
type: string
required: true
default: "main"

jobs:

record:
name: "📸 Record"
uses: ./.github/workflows/CI-screenshot-record.yml
with:
ref: ${{ inputs.base_ref }}

verify:
name: "🧪 Verify"
uses: ./.github/workflows/CI-screenshot-verify.yml
with:
ref: ${{ inputs.head_ref }}
needs:
- record
22 changes: 7 additions & 15 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
uses: TWiStErRob/github-workflows/.github/workflows/validate.yml@v1

build:
name: "🔨 Build & Verifz"
name: "🔨 Build & Verify"
uses: ./.github/workflows/CI-build.yml
needs:
- validate
Expand All @@ -25,22 +25,14 @@ jobs:
# Don't execute on main, it'll never be PR'd.
if: github.ref != 'refs/heads/main' && (success() || failure())

record-base:
screenshot:
name: "📸 Screenshot Tests"
uses: ./.github/workflows/CI-screenshot-record.yml
uses: ./.github/workflows/CI-screenshot.yml
with:
base_ref: ${{ needs.pull_request.outputs.base_ref }}
head_ref: ${{ needs.pull_request.outputs.head_ref }}
needs:
- validate
- pull_request
# Don't execute on main, as it'll just verify against itself.
if: github.ref != 'refs/heads/main' && needs.pull_request.outputs.found == 'true'

verify-pr:
name: "📸 Screenshot Tests"
uses: ./.github/workflows/CI-screenshot-verify.yml
needs:
- validate
# If build fails, there's not much point in running screenshot tests.
- build
# Need to run after recording base branch golden values to compare against them.
- record-base
- pull_request
if: needs.pull_request.outputs.found == 'true'

0 comments on commit 925b8d5

Please sign in to comment.