-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[ci] Run Swift formatter and linter during CI formatting #5928
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
Conversation
.ci.yaml
Outdated
target_file: macos_repo_checks.yaml | ||
dependencies: > | ||
[ | ||
{"dependency": "swift_format", "version": "build_id:8797338979890974865"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The version
tag is version:[email protected]
which fails because the @
isn't valid in the regex ^[a-z0-9_]+$
ERROR: projects/flutter: cr-buildbucket.cfg: in "cr-buildbucket.cfg" (buckets #4 - try / swarming / builders #454 - Mac_x64 check_podspecs / caches #4): name: "packages_main_swift_format_version_2@505_chromium_2" does not match "^[a-z0-9_]+$"
I don't think it's important which tag we use, build_id
seems fine too.
Run `swift-format` linter/formatter on Swift files in example apps. This doesn't touch any Swift files in non-example code. Part of turning on swift-format CI formatting #5928
Run `swift-format` linter/formatter on Swift files. Part of turning on swift-format CI formatting #5928
@@ -40,7 +40,7 @@ class TestViewProvider: NSObject, ViewProvider { | |||
var window: NSWindow? = NSWindow() | |||
} | |||
|
|||
class exampleTests: XCTestCase { | |||
class ExampleTests: XCTestCase { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
linter (not format) error:
RunnerTests.swift:43:7: warning: [TypeNamesShouldBeCapitalized] rename the class 'exampleTests' using UpperCamelCase; for example, 'ExampleTests'
No CHANGELOG or version bump needed based on #5933 (comment)
Run `swift-format` linter/formatter on Swift files. Part of turning on swift-format CI formatting #5928
Run `swift-format` linter/formatter on Swift files in example apps. This only touches Swift files in example/test code. This also doesn't format any autogenerated Swift files, which would require changed in the pigeon generator: flutter/flutter#141799 Part of turning on swift-format CI formatting #5928
.ci/targets/macos_repo_checks.yaml
Outdated
@@ -5,6 +5,10 @@ tasks: | |||
- name: update pods repo | |||
script: .ci/scripts/update_pods.sh | |||
infra_step: true # Note infra steps failing prevents "always" from running. | |||
- name: Swift format | |||
script: script/tool_runner.sh | |||
args: ["format", "--fail-on-change", "--swift", "--no-dart", "--no-clang-format", "--no-kotlin", "--no-java" ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that we're turning it on in CI, let's make --swift
default to true
like all the other ones, and then pass --no-swift
on Linux.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -342,6 +359,13 @@ class FormatCommand extends PackageCommand { | |||
(String filePath) => extensions.contains(path.extension(filePath))); | |||
} | |||
|
|||
Iterable<String> _filterGeneratedFiles(Iterable<String> files) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than filtering out generated files, we just need Pigeon to do Swift formatting in CI; this code should include Swift formatting. If we changed the default then it'll just work, otherwise we need to add --swift
there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, but that's not going to work on the Linux machine where we run this.
Hm, do we have a clang-format
CIPD package for macOS already? If so, we could change this to macOS instead of Linux, and adjust the dependencies in ci.yaml. If not I'll need to think more about how we can handles this sanely, and we can land with the exclusion in the meantime.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it's easier to change the Pigeon validator to check specific languages for changes instead of checking everything for changes, and then run it for different languages on different CI hosts the way we do the format
check itself. I'll play with that today.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it's easier to change the Pigeon validator to check specific languages for changes instead of checking everything for changes, and then run it for different languages on different CI hosts the way we do the
format
check itself.
I think #5944 should make this work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed my comment about removing it into a TODO. How about I land this, then you rebase #5944 onto ToT and remove the _filterGeneratedFiles
in that PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than filtering out generated files, we just need Pigeon to do Swift formatting in CI; this code should include Swift formatting.
Oops, now that swift
is enabled by default, that same code will need (until my PR lands) --no-swift
.
@@ -1143,6 +1147,10 @@ targets: | |||
{ | |||
"CHANNEL": "master" | |||
} | |||
dependencies: > | |||
[ | |||
{"dependency": "swift_format", "version": "build_id:8797338979890974865"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The arm64 and x64 build_id
numbers are different, but it's pointing to the same version.
arm: https://chrome-infra-packages.appspot.com/p/infra/3pp/tools/swift-format/mac-arm64/+/RLmOtWwcNQeEUBqiZdpqEtJVh-cdm95Bbcz0W-wC124C
x64: https://chrome-infra-packages.appspot.com/p/infra/3pp/tools/swift-format/mac-amd64/+/xG4XM0suWSr-M7wBW_zojQ83hgZRnRVO2qVYy46d2PgC
.ci/targets/macos_repo_checks.yaml
Outdated
@@ -5,6 +5,10 @@ tasks: | |||
- name: update pods repo | |||
script: .ci/scripts/update_pods.sh | |||
infra_step: true # Note infra steps failing prevents "always" from running. | |||
- name: Swift format | |||
script: script/tool_runner.sh | |||
args: ["format", "--fail-on-change", "--swift", "--no-dart", "--no-clang-format", "--no-kotlin", "--no-java" ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -342,6 +359,13 @@ class FormatCommand extends PackageCommand { | |||
(String filePath) => extensions.contains(path.extension(filePath))); | |||
} | |||
|
|||
Iterable<String> _filterGeneratedFiles(Iterable<String> files) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed my comment about removing it into a TODO. How about I land this, then you rebase #5944 onto ToT and remove the _filterGeneratedFiles
in that PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with nit
@@ -342,6 +359,13 @@ class FormatCommand extends PackageCommand { | |||
(String filePath) => extensions.contains(path.extension(filePath))); | |||
} | |||
|
|||
Iterable<String> _filterGeneratedFiles(Iterable<String> files) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏻
auto label is removed for flutter/packages/5928, due to - The status or check suite Linux_android custom_package_tests master has failed. Please fix the issues identified (or deflake) before re-applying this label. |
Reworks Pigeon's CI validation of generated files to support multiple hosts, rather than only Linux, with the ability to set specific languages per host, to allow us to run validation for each language on whatever host it is most convenient to set up a formatter for that language, rather than having to support all languages on Linux. See discussion in #5928 Part of flutter/flutter#41129
flutter/packages@129e08c...e4cbf23 2024-01-21 [email protected] Roll Flutter from ddf60fb to 5dea6b9 (5 revisions) (flutter/packages#5951) 2024-01-21 [email protected] Update platform label rules for shared iOS/macOS (flutter/packages#5801) 2024-01-20 [email protected] [pigeon] Support other hosts in generated file CI checks (flutter/packages#5944) 2024-01-20 [email protected] [pigeon] Improve style of generated Swift code (flutter/packages#5938) 2024-01-20 [email protected] Roll Flutter from 684247a to ddf60fb (12 revisions) (flutter/packages#5949) 2024-01-20 [email protected] [camera]fix a sample buffer memory leak on pause resume recording (flutter/packages#5927) 2024-01-19 [email protected] [ci] Run Swift formatter and linter during CI formatting (flutter/packages#5928) 2024-01-19 [email protected] Manual roll Flutter from f77f824 to 684247a (39 revisions) (flutter/packages#5948) 2024-01-19 [email protected] Expose registered widget libraries and local widget library widgets. (flutter/packages#5936) 2024-01-19 49699333+dependabot[bot]@users.noreply.github.com Bump actions/upload-artifact from 4.1.0 to 4.2.0 (flutter/packages#5937) 2024-01-19 [email protected] Manual roll Flutter (stable) from ef1af02 to 67457e6 (1 revision) (flutter/packages#5932) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Make
swift-format
CIPD package available on thePATH
https://flutter-review.googlesource.com/c/recipes/+/54020Run
format --no-clang-format --no-java --no-kotlin --no-dart
on the macOS builder so it doesn't duplicate sameformat
call run on Linux.Filter out generated files until flutter/flutter#141799 is done.
Also add
swift-format lint
call duringformat
command. Fix the one casing issue it found in a test file.Failing run:
https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8758535881172004177/+/u/Run_package_tests/Swift_format/stdout
Successful run:
https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8758492350529121249/+/u/Run_package_tests/Swift_format/stdout
Fixes flutter/flutter#41129
Pre-launch Checklist
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style.///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.