Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Record snapshots on CI #392

Merged
merged 2 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions .github/workflows/smoke-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ on:
# - '!main' TODO: commented until `develop` branch is in place

workflow_dispatch:
inputs:
snapshots:
description: 'Should Snapshots be recorded on CI?'
type: boolean
required: false
default: false

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand All @@ -23,7 +29,7 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_PR_NUM: ${{ github.event.number }}
if: ${{ github.event_name != 'push' }}
if: ${{ github.event_name != 'push' && github.event.inputs.snapshots != 'true' }}
steps:
- uses: actions/[email protected]
- uses: ./.github/actions/bootstrap
Expand Down Expand Up @@ -69,15 +75,16 @@ jobs:
- uses: ./.github/actions/bootstrap
- uses: ./.github/actions/python-cache
- name: Run UI Tests (Debug)
run: bundle exec fastlane test_ui device:"${{ env.IOS_SIMULATOR_DEVICE }}" skip_build:true
timeout-minutes: 40
run: bundle exec fastlane test_ui device:"${{ env.IOS_SIMULATOR_DEVICE }}" skip_build:true record:${{ github.event.inputs.snapshots }}
timeout-minutes: 60
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.CI_BOT_GITHUB_TOKEN }} # to open a PR
GITHUB_PR_NUM: ${{ github.event.number }}
- name: Get branch name
id: get_branch_name
run: echo "branch=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT
- name: Run Sonar analysis
if: ${{ github.event.inputs.snapshots != 'true' }}
run: bundle exec fastlane sonar_upload
env:
BRANCH_NAME: ${{ steps.get_branch_name.outputs.branch }}
Expand Down Expand Up @@ -110,7 +117,7 @@ jobs:
test-e2e-debug:
name: Test E2E UI (Debug)
runs-on: macos-13
if: ${{ github.event_name != 'push' }}
if: ${{ github.event_name != 'push' && github.event.inputs.snapshots != 'true' }}
needs:
- allure_testops_launch
- build-test-app-and-frameworks
Expand Down Expand Up @@ -165,7 +172,7 @@ jobs:
allure_testops_launch:
name: Launch Allure TestOps
runs-on: macos-13
if: ${{ github.event_name != 'push' }}
if: ${{ github.event_name != 'push' && github.event.inputs.snapshots != 'true' }}
outputs:
launch_id: ${{ steps.get_launch_id.outputs.launch_id }}
steps:
Expand All @@ -185,7 +192,7 @@ jobs:
name: Build Demo App
runs-on: macos-13
needs: build-test-app-and-frameworks
if: ${{ github.event_name != 'push' }}
if: ${{ github.event_name != 'push' && github.event.inputs.snapshots != 'true' }}
steps:
- uses: actions/[email protected]
- uses: actions/download-artifact@v3
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Diff not rendered.
70 changes: 64 additions & 6 deletions fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ desc 'Runs tests in Debug config'
lane :test_ui do |options|
next unless is_check_required(sources: sources_matrix[:ui], force_check: @force_check)

remove_snapshots if options[:record]
remove_snapshots unless options[:record].to_s.empty?

update_testplan_on_ci(path: 'StreamChatSwiftUITests/Tests/StreamChatSwiftUI.xctestplan')

Expand All @@ -140,9 +140,31 @@ lane :test_ui do |options|
devices: options[:device],
build_for_testing: options[:build_for_testing],
skip_build: options[:skip_build],
number_of_retries: 1,
xcargs: buildcache_xcargs
number_of_retries: options[:record].to_s.empty? ? 1 : nil,
xcargs: buildcache_xcargs,
fail_build: options[:record].to_s.empty?
)

if options[:record] && is_ci
png_files = git_status(ext: '.png').map { |_, png| png }.flatten
next if png_files.empty?

title = "[CI] Snapshots"
base = current_branch
head = "#{base}-snapshots"
sh("git checkout -b #{head}")
png_files.each { |png| sh("git add #{png}") || true }
sh("git commit -m '#{title}'")
push_to_git_remote(tags: false)
create_pull_request(
api_token: ENV.fetch('GITHUB_TOKEN', nil),
repo: github_repo,
title: title,
head: head,
base: base,
body: 'This PR was created automatically by CI.'
)
end
end

lane :build_test_app_and_frameworks do
Expand Down Expand Up @@ -336,9 +358,16 @@ lane :install_sim do |options|
end
end

desc 'Remove UI snapshots'
private_lane :remove_snapshots do
Dir.glob('../StreamChatSwiftUITests/**/__Snapshots__/**/*.png').select { |file| File.delete(file) }
desc 'Remove UI Snapshots'
lane :remove_snapshots do |options|
snapshots_path = "../StreamChatSwiftUITests/**/__Snapshots__/**/*.png"
if options[:only_unchanged]
pnf_files = git_status(ext: '.png')
changed_snapshots = (pnf_files[:a] + pnf_files[:m]).map { |f| File.expand_path(f) }
Dir.glob(snapshots_path).select { |f| File.delete(f) unless changed_snapshots.include?(File.expand_path(f)) }
else
Dir.glob(snapshots_path).select { |f| File.delete(f) }
end
end

lane :sources_matrix do
Expand All @@ -353,3 +382,32 @@ end
private_lane :current_branch do
ENV['BRANCH_NAME'] || git_branch
end

private_lane :git_status do |options|
UI.user_error!('Extension should be provided') unless options[:ext]

untracked_files = sh('git status -s', log: false).split("\n").map(&:strip)
UI.important("Git Status: #{untracked_files}")

deleted_files = select_files_from(files: untracked_files, with_extension: options[:ext], that_start_with: 'D')
added_files = select_files_from(files: untracked_files, with_extension: options[:ext], that_start_with: ['A', '??'])
renamed_files = select_files_from(files: untracked_files, with_extension: options[:ext], that_start_with: 'R')
modified_files = select_files_from(files: untracked_files, with_extension: options[:ext], that_start_with: 'M')

renamed_files.each do |renamed_file|
content = renamed_file.split.drop(1).join.split('->').map(&:strip)
deleted_files << content.first
added_files << content.last
end
{ a: added_files, d: deleted_files, m: modified_files }
end

def select_files_from(files:, with_extension:, that_start_with:)
files.select do |f|
f.start_with?(*that_start_with)
end.map do |f|
f.split.drop(1).join(' ')
end.select do |f|
f.gsub(/['"]/, '').end_with?(with_extension)
end
end
Loading