Skip to content

Allow CircleCI to generate new test snapshots#1561

Closed
joshdholtz wants to merge 1 commit into
mainfrom
cirlceci-make-snapshot-tests
Closed

Allow CircleCI to generate new test snapshots#1561
joshdholtz wants to merge 1 commit into
mainfrom
cirlceci-make-snapshot-tests

Conversation

@joshdholtz

@joshdholtz joshdholtz commented May 11, 2022

Copy link
Copy Markdown
Member

Depends on #1589

Motivation

Our snapshot testing sometimes needs regeneration and it requires regeneration of iOS 12. iOS 12 simulators only run on Intel machines and not all of us have them.

This PR will allow a CircleCI job to be manually triggered to regenerate snapshot tests

Description

Step 1: Trigger CircleCI workflow

Run bundle exec fastlane generate_snapshots

Step 2: Run CircleCI workflow with generate snapshots

This will start a series of jobs on CircleCI that will have the CIRCLECI_TESTS_GENERATE_SNAPSHOTS set to true that will regenerate new/updated snapshot test assets.

Screen Shot 2022-05-12 at 9 02 43 PM

Step 3: Create pull requests

If there are any files changed, a new PR will be created against the base branch (set earlier in the generate_snapshots lane)

Example PR 👉 #1578

Screen Shot 2022-05-12 at 8 57 46 PM

@joshdholtz joshdholtz force-pushed the cirlceci-make-snapshot-tests branch 2 times, most recently from e146fbf to e0bf949 Compare May 11, 2022 02:44
@joshdholtz joshdholtz changed the title Allow CircleCI to generate new test snapshots [WIP] Allow CircleCI to generate new test snapshots May 11, 2022
@joshdholtz joshdholtz force-pushed the cirlceci-make-snapshot-tests branch 4 times, most recently from 242dd2e to 696d98e Compare May 11, 2022 15:11
@joshdholtz joshdholtz changed the title [WIP] Allow CircleCI to generate new test snapshots Allow CircleCI to generate new test snapshots May 13, 2022
@joshdholtz joshdholtz requested review from a team and NachoSoto May 13, 2022 02:06

@NachoSoto NachoSoto left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome this looks ready! Amazing job.

The only think I don't understand is what's happening with the iOS 12 snapshots generated. They're way too many. Could you invoke a test run with raw output? I think something is happening with those requests that's making them retry many times for some reason.

Comment thread .circleci/config.yml Outdated
steps:
- run:
name: Run create_snapshot_pr
command: bundle exec fastlane create_snapshot_pr version:"tvos"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't actually need this one. tvOS tests use the equivalent version (so tvOS 15 uses iOS 15 snapshots). Could it be removed?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed!

Comment thread fastlane/Fastfile
branch_name = "generated_snapshots/#{base_branch}-#{version}"
sh("git", "checkout", "-b", branch_name)

sh("git", "add", "../Tests")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

@joshdholtz

Copy link
Copy Markdown
Member Author

@NachoSoto Pushed a commit where no Xcode formatter (raw output) will be used when generating snapshots!

@joshdholtz joshdholtz force-pushed the cirlceci-make-snapshot-tests branch 2 times, most recently from 6b6b552 to 5c5b7c5 Compare May 20, 2022 18:08
@joshdholtz joshdholtz changed the base branch from main to any-decodable-ios-12-test May 20, 2022 18:08
@NachoSoto NachoSoto force-pushed the any-decodable-ios-12-test branch from 60df869 to 6823c7e Compare May 20, 2022 18:29
@joshdholtz joshdholtz force-pushed the cirlceci-make-snapshot-tests branch from 5c5b7c5 to 21c5086 Compare May 20, 2022 18:33
@NachoSoto

Copy link
Copy Markdown
Contributor

Looks like this is working 🎉
Screen Shot 2022-05-20 at 11 33 21

But let's run it against #1560 to see if it generates the new ones correctly too.

Comment thread fastlane/Fastfile
prelaunch_simulator: true,
output_types: 'junit',
number_of_retries: 5,
number_of_retries: generate_snapshots ? 0 : 5,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome.

Base automatically changed from any-decodable-ios-12-test to main May 24, 2022 17:11
@aboedo

aboedo commented May 26, 2022

Copy link
Copy Markdown
Member

what's the status of this one?

@NachoSoto

Copy link
Copy Markdown
Contributor

Should we close this for now?

@joshdholtz

Copy link
Copy Markdown
Member Author

Ahhh... this one was super frustrating! CircleCI wasn't generating the things properly even though it should have. Probably should close it 😬

@NachoSoto

Copy link
Copy Markdown
Contributor

We can pair to finish it, I'm sure it's almost ready?

@joshdholtz

Copy link
Copy Markdown
Member Author

I'd be down to pair sometime 😊

Fixes https://app.circleci.com/pipelines/github/RevenueCat/purchases-ios/6737/workflows/b945f5f6-6f31-4716-b1ac-6e16e3848c7e/jobs/26321

For some reason, on iOS 12.x only, this:
```swift
JSONDecoder.default.decode(jsonData: "null".data(using: .utf8)!)
```

Fails:
```
dataCorrupted(Swift.DecodingError.Context(codingPath: [], debugDescription: "The given data was not valid JSON.", underlyingError: Optional(Error Domain=NSCocoaErrorDomain Code=3840 "JSON text did not start with array or object and option to allow fragments not set." UserInfo={NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.})))
```

We don't rely on decoding fragments, so I just updated the test to check `.null` within a dictionary instead.

`Snapshotting.formattedData`: use `JSONEncoder.OutputFormatting.withoutEscapingSlashes` if available

This was removed after a [PR review comment](#1366 (comment))
because it would have lead to different snapshots in iOS 12.

However, since #1504 we have separate snapshots for each iOS version, so this cleans up the output when possible.

```diff
-    "url" : "https:\/\/api.revenuecat.com\/v1\/subscribers\/user\/alias"
+    "url" : "https://api.revenuecat.com/v1/subscribers/user/alias"
```

Update CircleCI config to use pipeline parameters to set generate snapshots env

Run all in one serially

Split OS version into their own jobs

Create PR from all os version jobs

This is the one

Added requestby user in body

Fix for pr actually creating

Reordered some things

Remove tvos from generated jobs

Raw output when generating snapshots

Don't retry tests when generating snapshots

Maybe this will make the PRs

Maybe this

This is it
@joshdholtz joshdholtz force-pushed the cirlceci-make-snapshot-tests branch from 835a255 to 5fb1433 Compare May 12, 2023 15:07
@NachoSoto

Copy link
Copy Markdown
Contributor

Closing in favor of #2472.

@NachoSoto NachoSoto closed this May 12, 2023
@NachoSoto NachoSoto deleted the cirlceci-make-snapshot-tests branch May 12, 2023 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants