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

Add Swift Package Manager support #321

Merged
merged 14 commits into from
Nov 17, 2022
Merged

Conversation

crazytonyli
Copy link
Contributor

@crazytonyli crazytonyli commented Nov 15, 2022

Unlike similar PRs to other libraries, I didn't split this SPM support change into two PRs, because the complication of "WPAnalyticsTests". I can't get this test to compile in Swift Package Manager, due to we have to use Swift version of Quick and OCMock (which is Objective-C).

And, I ended up deleting this test case. 🥲

Can't get it to compile is the main reason of course, but also I don't see this test provides much value. I'm not familiar with OCMock, but just by reading the code, I think the verification logic (invoked from OCMock) seems all about "verifying a method is indeed called when a method is called".

  • Check if buildkite test collector continues to work

  • I have considered if this change warrants release notes and have added them to the appropriate section in the CHANGELOG.md if necessary.

@crazytonyli crazytonyli requested a review from a team November 15, 2022 01:57
@crazytonyli crazytonyli self-assigned this Nov 15, 2022
@crazytonyli crazytonyli changed the title Swift package folder structure Add Swift Package Manager support Nov 15, 2022
This additional step generate .swiftpm which hopefully resolves the
'could not generate PIF' issue.
@crazytonyli crazytonyli force-pushed the swift-package-folder-structure branch from eca447e to 2fe6d54 Compare November 15, 2022 07:36
mokagio added a commit that referenced this pull request Nov 15, 2022
This is mostly to see if the tooling issue seen in #321 disappears on
a newer Xcode version.
@mokagio mokagio mentioned this pull request Nov 15, 2022
1 task
mokagio added a commit that referenced this pull request Nov 15, 2022
It should be redundant, but #321 shows that we need to run it before the
tests. The previous commit upgrades CI to Xcode 14.1, hopefully that's
enough to get the build for this one to work.
################
########################
# Validate Swift Package
########################
- label: "🧪 Build and Test iOS"
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you decide to keep the label the same to avoid the GitHub checks dance we run into WordPressUI-iOS?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🙈 I forgot to change it actually... Addressed in 7615808

Comment on lines 10 to 12
################
# Build and Test
################
########################
# Validate Swift Package
########################
Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW, my two cents are that we can delete these headers.

Sources/WordPressShared/WordPressShared.swift Outdated Show resolved Hide resolved
Sources/WordPressSharedObjC/Views/WPStyleGuide.m Outdated Show resolved Hide resolved
Comment on lines +8 to +11
xcodebuild(
scheme: 'WordPressShared',
xcargs: '-resolvePackageDependencies'
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting... I assume the tests run didn't work without this.

Have you tried passing the xcargs option to run_tests?

The action has parameters such as disable_package_automatic_updates and skip_package_dependencies_resolution (both defaulting to false) which makes me think it should be able to handle this without a dedicated step.

Okay. Silly me, I should have done my reading before commenting 😓

I can see the error this addresses from the CI builds, e.g. this one.

[...] Cannot open "Documentation.docc" as a "Swift Package Folder" because it is already open as a "Folder"." 
[...]
[06:35:08]: ▸ ❌  error: Build service could not create build operation:
  internal error:
    could not generate PIF because the workspace has not finished loading or is still waiting for package resolution

Seems like a tooling bug to me. Worth adding a note in the code about it?

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like a tooling bug to me

I noticed CI for this project is on Xcode 14.0. I opened #323 to see if Xcode 14.1 solved the alleged tooling issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have seen similar error in Xcode 13 before, my guess is it's caused by some race condition within Xcode between creating the Swift Package's Xcode project and loading the project. But yeah, hopefully this is no longer an issue in Xcode 14.1.

Another thing is, if this issue continues to show up, it would be a good idea to move this additional command into bash-cache's validate_swift_package script. Also, it's probably also worth to make the script self contained, rather than relying on the projects to have a test lane.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, it's probably also worth to make the script self contained, rather than relying on the projects to have a test lane.

Great idea. In particular if we need additional setup.

@crazytonyli
Copy link
Contributor Author

If I understand it correctly, Test Analytics of this project is set to only collect test data of the trunk branch. I'll merge this PR and check out the trunk branch to make sure the Test Analytics set up is not broken.

@crazytonyli crazytonyli merged commit fb2b1ab into trunk Nov 17, 2022
@crazytonyli crazytonyli deleted the swift-package-folder-structure branch November 17, 2022 23:55
@crazytonyli
Copy link
Contributor Author

I'll merge this PR and check out the trunk branch to make sure the Test Analytics set up is not broken.

Yep, it's broken. 🤦‍♂️

I've opened an issue for it #324, and I'll look into it later.

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.

2 participants