Skip to content

Fix rotate effect merging for OpenSwiftUI renderer #1394

Fix rotate effect merging for OpenSwiftUI renderer

Fix rotate effect merging for OpenSwiftUI renderer #1394

Workflow file for this run

name: UI Tests
on:
push:
branches: [main]
paths:
- 'Example/OpenSwiftUIUITests/**'
- '.github/workflows/uitests.yml'
- '.github/actions/uitests/action.yml'
workflow_dispatch:
inputs:
platform:
description: Platform to test
required: true
default: all
type: choice
options:
- all
- ios
- macos
update_reference:
description: Update reference images before running UI tests
required: false
default: false
type: boolean
issue_comment:
types: [created]
permissions:
contents: read
issues: read
pull-requests: read
statuses: write
jobs:
prepare_issue_comment:
name: Prepare issue comment UI tests
if: >-
github.event_name == 'issue_comment' &&
github.event.issue.pull_request &&
contains(fromJSON('["OWNER", "MEMBER", "COLLABORATOR"]'), github.event.comment.author_association) &&
(
github.event.comment.body == '/uitest' ||
startsWith(github.event.comment.body, '/uitest ')
)
runs-on: ubuntu-latest
outputs:
repository: ${{ steps.prepare.outputs.repository }}
ref: ${{ steps.prepare.outputs.ref }}
ios-requested: ${{ steps.prepare.outputs.ios-requested }}
macos-requested: ${{ steps.prepare.outputs.macos-requested }}
update-reference: ${{ steps.prepare.outputs.update-reference }}
status-enabled: ${{ steps.prepare.outputs.status-enabled }}
steps:
- name: Prepare PR commit statuses
id: prepare
uses: actions/github-script@v7
with:
script: |
const { owner, repo } = context.repo;
const pull_number = context.payload.issue.number;
const comment = context.payload.comment;
const body = comment.body.trim();
const allowedAssociations = new Set(["OWNER", "MEMBER", "COLLABORATOR"]);
const outputs = {
repository: "",
ref: "",
"ios-requested": "false",
"macos-requested": "false",
"update-reference": "false",
"status-enabled": "false",
};
const setOutputs = () => {
for (const [name, value] of Object.entries(outputs)) {
core.setOutput(name, value);
}
};
const args = body.split(/\s+/);
if (args[0] !== "/uitest" || !allowedAssociations.has(comment.author_association)) {
setOutputs();
return;
}
const updateRequested = args.slice(1).includes("update");
const platformArgs = args.slice(1).filter((arg) => arg !== "update");
if (platformArgs.length > 1) {
setOutputs();
return;
}
const requested = platformArgs[0] ?? "all";
const platforms =
requested === "all" ? ["ios", "macos"] :
requested === "ios" || requested === "macos" ? [requested] :
[];
if (platforms.length === 0) {
setOutputs();
return;
}
const { data: pull } = await github.rest.pulls.get({ owner, repo, pull_number });
outputs.repository = pull.head.repo.full_name;
outputs.ref = pull.head.sha;
outputs["ios-requested"] = String(platforms.includes("ios"));
outputs["macos-requested"] = String(platforms.includes("macos"));
outputs["update-reference"] = String(updateRequested);
const sameRepository = pull.head.repo.full_name === `${owner}/${repo}`;
if (!sameRepository) {
core.warning(`Skipping PR commit status creation for fork PR ${pull.head.repo.full_name}@${pull.head.sha}.`);
setOutputs();
return;
}
outputs["status-enabled"] = "true";
const details_url = `${process.env.GITHUB_SERVER_URL}/${owner}/${repo}/actions/runs/${context.runId}`;
const renderers = ["SwiftUI Renderer", "OpenSwiftUI Renderer"];
for (const platform of platforms) {
const label = platform === "ios" ? "iOS" : "macOS";
for (const renderer of renderers) {
const description = `Queued by @${comment.user.login} with ${body}.`.slice(0, 140);
await github.rest.repos.createCommitStatus({
owner,
repo,
sha: pull.head.sha,
state: "pending",
target_url: details_url,
description,
context: `UI Tests / ${label} / ${renderer}`,
});
}
}
setOutputs();
ios_uitest:
name: Execute UI tests on iOS (${{ matrix.renderer.name }})
needs: prepare_issue_comment
if: >-
always() && (
github.event_name == 'push' ||
(github.event_name == 'workflow_dispatch' && contains(fromJSON('["all", "ios"]'), inputs.platform)) ||
(
github.event_name == 'issue_comment' &&
needs.prepare_issue_comment.outputs.ios-requested == 'true'
)
)
strategy:
fail-fast: false
matrix:
os: [macos-15]
xcode-version: ["16.4"]
release: [2024]
ios-version: ["18.5"]
renderer:
- name: SwiftUI Renderer
swiftui_renderer: 1
artifact_suffix: swiftui-renderer
- name: OpenSwiftUI Renderer
swiftui_renderer: 0
artifact_suffix: openswiftui-renderer
include:
- ios-version: "18.5"
ios-simulator-name: "iPhone 16 Pro"
# Limit to self-hosted to reduce action cost
runs-on:
- self-hosted
- ${{ matrix.os }}
env:
STATUS_CONTEXT: UI Tests / iOS / ${{ matrix.renderer.name }}
STATUS_ENABLED: ${{ needs.prepare_issue_comment.outputs.status-enabled }}
STATUS_SHA: ${{ needs.prepare_issue_comment.outputs.ref }}
RENDERER_NAME: ${{ matrix.renderer.name }}
OPENSWIFTUI_WERROR: 0 # Disable it to avoid enable OAG's werror and hit conflicts
OPENSWIFTUI_OPENATTRIBUTESHIMS_ATTRIBUTEGRAPH: 1
OPENSWIFTUI_COMPATIBILITY_TEST: 0
OPENSWIFTUI_SWIFT_LOG: 0
OPENSWIFTUI_SWIFT_CRYPTO: 0
OPENSWIFTUI_TARGET_RELEASE: ${{ matrix.release }}
OPENSWIFTUI_USE_LOCAL_DEPS: 1
OPENSWIFTUI_LINK_TESTING: 0
OPENSWIFTUI_SWIFTUI_RENDERER: ${{ matrix.renderer.swiftui_renderer }}
GH_TOKEN: ${{ github.token }}
steps:
- name: Mark PR status running
if: github.event_name == 'issue_comment' && env.STATUS_ENABLED == 'true' && env.STATUS_SHA != ''
uses: actions/github-script@v7
with:
script: |
const { owner, repo } = context.repo;
await github.rest.repos.createCommitStatus({
owner,
repo,
sha: process.env.STATUS_SHA,
state: "pending",
target_url: `${process.env.GITHUB_SERVER_URL}/${owner}/${repo}/actions/runs/${context.runId}`,
description: `iOS UI tests (${process.env.RENDERER_NAME}) are running.`,
context: process.env.STATUS_CONTEXT,
});
- uses: actions/checkout@v4
with:
repository: ${{ needs.prepare_issue_comment.outputs.repository || github.repository }}
ref: ${{ needs.prepare_issue_comment.outputs.ref || github.sha }}
- name: Run UI Tests
id: run-tests
uses: ./.github/actions/uitests
with:
xcode-version: ${{ matrix.xcode-version }}
platform: ios
destination: "platform=iOS Simulator,OS=${{ matrix.ios-version }},name=${{ matrix.ios-simulator-name }}"
artifact-name: ios-uitest-snapshots-${{ matrix.ios-version }}-${{ matrix.renderer.artifact_suffix }}
update-reference: ${{ (github.event_name == 'workflow_dispatch' && inputs.update_reference) || needs.prepare_issue_comment.outputs.update-reference == 'true' }}
- name: Fail if tests failed
if: steps.run-tests.outputs.test-result == 'failure'
run: exit 1
- name: Complete PR status
if: always() && github.event_name == 'issue_comment' && env.STATUS_ENABLED == 'true' && env.STATUS_SHA != ''
uses: actions/github-script@v7
env:
JOB_STATUS: ${{ job.status }}
with:
script: |
const { owner, repo } = context.repo;
const state = process.env.JOB_STATUS === "success" ? "success" :
process.env.JOB_STATUS === "cancelled" ? "error" :
"failure";
const description = process.env.JOB_STATUS === "cancelled" ?
"iOS UI tests were cancelled." :
`iOS UI tests (${process.env.RENDERER_NAME}) completed with ${state}.`;
await github.rest.repos.createCommitStatus({
owner,
repo,
sha: process.env.STATUS_SHA,
state,
target_url: `${process.env.GITHUB_SERVER_URL}/${owner}/${repo}/actions/runs/${context.runId}`,
description,
context: process.env.STATUS_CONTEXT,
});
macos_uitest:
name: Execute UI tests on macOS (${{ matrix.renderer.name }})
needs: prepare_issue_comment
if: >-
always() && (
github.event_name == 'push' ||
(github.event_name == 'workflow_dispatch' && contains(fromJSON('["all", "macos"]'), inputs.platform)) ||
(
github.event_name == 'issue_comment' &&
needs.prepare_issue_comment.outputs.macos-requested == 'true'
)
)
strategy:
fail-fast: false
matrix:
os: [macos-15]
xcode-version: ["16.4"]
release: [2024]
renderer:
- name: SwiftUI Renderer
swiftui_renderer: 1
artifact_suffix: swiftui-renderer
- name: OpenSwiftUI Renderer
swiftui_renderer: 0
artifact_suffix: openswiftui-renderer
# Limit to self-hosted to reduce action cost
runs-on:
- self-hosted
- ${{ matrix.os }}
env:
STATUS_CONTEXT: UI Tests / macOS / ${{ matrix.renderer.name }}
STATUS_ENABLED: ${{ needs.prepare_issue_comment.outputs.status-enabled }}
STATUS_SHA: ${{ needs.prepare_issue_comment.outputs.ref }}
RENDERER_NAME: ${{ matrix.renderer.name }}
OPENSWIFTUI_WERROR: 0
OPENSWIFTUI_OPENATTRIBUTESHIMS_ATTRIBUTEGRAPH: 1
OPENSWIFTUI_COMPATIBILITY_TEST: 0
OPENSWIFTUI_SWIFT_LOG: 0
OPENSWIFTUI_SWIFT_CRYPTO: 0
OPENSWIFTUI_TARGET_RELEASE: ${{ matrix.release }}
OPENSWIFTUI_USE_LOCAL_DEPS: 1
OPENSWIFTUI_SWIFTUI_RENDERER: ${{ matrix.renderer.swiftui_renderer }}
GH_TOKEN: ${{ github.token }}
steps:
- name: Mark PR status running
if: github.event_name == 'issue_comment' && env.STATUS_ENABLED == 'true' && env.STATUS_SHA != ''
uses: actions/github-script@v7
with:
script: |
const { owner, repo } = context.repo;
await github.rest.repos.createCommitStatus({
owner,
repo,
sha: process.env.STATUS_SHA,
state: "pending",
target_url: `${process.env.GITHUB_SERVER_URL}/${owner}/${repo}/actions/runs/${context.runId}`,
description: `macOS UI tests (${process.env.RENDERER_NAME}) are running.`,
context: process.env.STATUS_CONTEXT,
});
- uses: actions/checkout@v4
with:
repository: ${{ needs.prepare_issue_comment.outputs.repository || github.repository }}
ref: ${{ needs.prepare_issue_comment.outputs.ref || github.sha }}
- name: Run UI Tests
id: run-tests
uses: ./.github/actions/uitests
with:
xcode-version: ${{ matrix.xcode-version }}
platform: macos
destination: "platform=macOS"
artifact-name: macos-uitest-snapshots-${{ matrix.renderer.artifact_suffix }}
update-reference: ${{ (github.event_name == 'workflow_dispatch' && inputs.update_reference) || needs.prepare_issue_comment.outputs.update-reference == 'true' }}
- name: Fail if tests failed
if: steps.run-tests.outputs.test-result == 'failure'
run: exit 1
- name: Complete PR status
if: always() && github.event_name == 'issue_comment' && env.STATUS_ENABLED == 'true' && env.STATUS_SHA != ''
uses: actions/github-script@v7
env:
JOB_STATUS: ${{ job.status }}
with:
script: |
const { owner, repo } = context.repo;
const state = process.env.JOB_STATUS === "success" ? "success" :
process.env.JOB_STATUS === "cancelled" ? "error" :
"failure";
const description = process.env.JOB_STATUS === "cancelled" ?
"macOS UI tests were cancelled." :
`macOS UI tests (${process.env.RENDERER_NAME}) completed with ${state}.`;
await github.rest.repos.createCommitStatus({
owner,
repo,
sha: process.env.STATUS_SHA,
state,
target_url: `${process.env.GITHUB_SERVER_URL}/${owner}/${repo}/actions/runs/${context.runId}`,
description,
context: process.env.STATUS_CONTEXT,
});