Skip to content

Conversation

@mokagio
Copy link
Contributor

@mokagio mokagio commented May 9, 2025

Description

This is part of the ongoing work to move away from CocoaPods, https://linear.app/a8c/issue/AINFRA-216.

#15598 established a BuildTools folder with a Swift package dedicated to dependencies that we only use as tools—i.e. not imported in the code base.

Sourcery is one such dependency and this PR moves it to be provisioned via SwiftPM instead of CocoaPods.

See also https://linear.app/a8c/issue/AINFRA-404.

Steps to reproduce & Testing information

To verify the change works, checkout the branch and run bundle exec rake generate. You'll see SwiftPM fetching all the Sourcery dependencies and after that running the binary to generate the various Swift files from the Sourcery templates. Because the templates have not changed ,there should be no additional change in your local repo.

image

To verify Sourcery actually can generate update files, modify one of the two templates:

  • CodeGeneration/Sourcery/Copiable/Models+Copiable.swifttemplate
  • CodeGeneration/Sourcery/Fakes/Fakes.swifttemplate

and verify the updated files are consistent with the changes you made. Example:

Template change

image

Generated changes

image

image

Screenshots


  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

Reviewer (or Author, in the case of optional code reviews):

Please make sure these conditions are met before approving the PR, or request changes if the PR needs improvement:

  • The PR is small and has a clear, single focus, or a valid explanation is provided in the description. If needed, please request to split it into smaller PRs.
  • Ensure Adequate Unit Test Coverage: The changes are reasonably covered by unit tests or an explanation is provided in the PR description.
  • Manual Testing: The author listed all the tests they ran, including smoke tests when needed (e.g., for refactorings). The reviewer confirmed that the PR works as expected on all devices (phone/tablet) and no regressions are added.

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented May 9, 2025

App Icon📲 You can test the changes from this Pull Request in WooCommerce iOS Prototype by scanning the QR code below to install the corresponding build.

App NameWooCommerce iOS Prototype
Build Number29771
VersionPR #15609
Bundle IDcom.automattic.alpha.woocommerce
Commit1fad314
Installation URL71vaec3b2b9j0
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@mokagio mokagio marked this pull request as ready for review May 9, 2025 05:06
@mokagio mokagio added this to the 22.4 milestone May 9, 2025
@mokagio mokagio added the category: tooling Anything that involves building & maintaining the project, including scripts, `Fastfile`, etc. label May 9, 2025
@mokagio mokagio self-assigned this May 9, 2025
@mokagio mokagio requested review from a team, joshheald and staskus May 9, 2025 05:07
@@ -1,6 +1,168 @@
{
"originHash" : "cd02791f9079102404056ed65d89c5c6bb997332bbfd1b03550dfdd51e57551e",
"originHash" : "bb374fb1cfe6769494b51a8da522b904ded4d3987ad68cd369eadb59e59f5e74",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Lots of dependencies coming via Sourcery. Luckily none of those affect the app.

Comment on lines -146 to +145
%w[Hardware Networking Storage Yosemite WooCommerce WooFoundation].each do |prefix|
puts "\n\nGenerating Copiable for #{prefix}..."
puts '=' * 100

sh "./Pods/Sourcery/bin/sourcery --config CodeGeneration/Sourcery/Copiable/#{prefix}-Copiable.sourcery.yaml"
end

puts "\n\nDONE. Generated Copiable for all projects."

%w[Hardware Networking Yosemite WooFoundation].each do |prefix|
puts "\n\nGenerating Fakes for #{prefix}..."
puts '=' * 100

sh "./Pods/Sourcery/bin/sourcery --config CodeGeneration/Sourcery/Fakes/#{prefix}-Fakes.yaml"
end

puts "\n\nDONE. Generated Fakes."
# See note in BuildTools/.sourcery.yml for why we call without arguments
run_package_plugin(cmd: 'sourcery-command')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For some reason, when running via Swift package plugin, Sourcery ignores the --config parameter and only reads from .sourcery.yml

Luckily, one can configure everything in .sourcery.yml (see below).

I think in the end that's a better approach. We don't need to loop through folders of look for files. The tool does it all for us.

3F0904022D26A40800D8ACCE /* WordPressAuthenticator */ = {isa = PBXFileSystemSynchronizedRootGroup; exceptions = (3F09041C2D26A40800D8ACCE /* PBXFileSystemSynchronizedBuildFileExceptionSet */, ); explicitFileTypes = {}; explicitFolders = (); path = WordPressAuthenticator; sourceTree = "<group>"; };
3F09040E2D26A40800D8ACCE /* WordPressAuthenticatorTests */ = {isa = PBXFileSystemSynchronizedRootGroup; exceptions = (3FD28D5E2D271391002EBB3D /* PBXFileSystemSynchronizedBuildFileExceptionSet */, ); explicitFileTypes = {}; explicitFolders = (); path = WordPressAuthenticatorTests; sourceTree = "<group>"; };
3F0904022D26A40800D8ACCE /* WordPressAuthenticator */ = {
isa = PBXFileSystemSynchronizedRootGroup;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

All these are generated by CocoaPods / Xcode 16.3 — See also #15608

@staskus
Copy link
Contributor

staskus commented May 9, 2025

Note: Failing unit test is unrelated and fixed here.

Copy link
Contributor

@staskus staskus left a comment

Choose a reason for hiding this comment

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

Thanks! Sourcery code gen continue to work 👍

@mokagio mokagio enabled auto-merge May 11, 2025 21:37
@mokagio mokagio merged commit a5bb19e into trunk May 11, 2025
13 checks passed
@mokagio mokagio deleted the ainfra-404-move-sourcery-to-spm branch May 11, 2025 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: tooling Anything that involves building & maintaining the project, including scripts, `Fastfile`, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants