Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[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

Merged
merged 5 commits into from
Jan 19, 2024

Conversation

jmagman
Copy link
Member

@jmagman jmagman commented Jan 18, 2024

Make swift-format CIPD package available on the PATH https://flutter-review.googlesource.com/c/recipes/+/54020

Run format --no-clang-format --no-java --no-kotlin --no-dart on the macOS builder so it doesn't duplicate same format call run on Linux.

Filter out generated files until flutter/flutter#141799 is done.

Also add swift-format lint call during format 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

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the package surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@jmagman jmagman self-assigned this Jan 18, 2024
.ci.yaml Outdated
target_file: macos_repo_checks.yaml
dependencies: >
[
{"dependency": "swift_format", "version": "build_id:8797338979890974865"}
Copy link
Member Author

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_]+$"

https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8758535881024973153/+/u/luci_validate/stdout

I don't think it's important which tag we use, build_id seems fine too.

auto-submit bot pushed a commit that referenced this pull request Jan 19, 2024
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
auto-submit bot pushed a commit that referenced this pull request Jan 19, 2024
Run `swift-format` linter/formatter on Swift files.

Part of turning on swift-format CI formatting #5928
@jmagman jmagman added override: no versioning needed Override the check requiring version bumps for most changes override: no changelog needed Override the check requiring CHANGELOG updates for most changes labels Jan 19, 2024
@@ -40,7 +40,7 @@ class TestViewProvider: NSObject, ViewProvider {
var window: NSWindow? = NSWindow()
}

class exampleTests: XCTestCase {
class ExampleTests: XCTestCase {
Copy link
Member Author

@jmagman jmagman Jan 19, 2024

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)

@jmagman jmagman changed the title [ci] Run Swift formatter during CI formatting [ci] Run Swift formatter and linter during CI formatting Jan 19, 2024
auto-submit bot pushed a commit that referenced this pull request Jan 19, 2024
Run `swift-format` linter/formatter on Swift files.

Part of turning on swift-format CI formatting #5928
auto-submit bot pushed a commit that referenced this pull request Jan 19, 2024
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
@jmagman jmagman marked this pull request as ready for review January 19, 2024 07:13
@jmagman jmagman requested a review from cbracken as a code owner January 19, 2024 07:13
@@ -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" ]
Copy link
Contributor

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.

Copy link
Member Author

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) {
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Member Author

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?

Copy link
Contributor

Choose a reason for hiding this comment

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

👍🏻

Copy link
Contributor

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"}
Copy link
Member Author

@jmagman jmagman Jan 19, 2024

Choose a reason for hiding this comment

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

@@ -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" ]
Copy link
Member Author

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) {
Copy link
Member Author

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?

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a 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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍🏻

@jmagman jmagman added the autosubmit Merge PR when tree becomes green via auto submit App label Jan 19, 2024
Copy link
Contributor

auto-submit bot commented Jan 19, 2024

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.

@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jan 19, 2024
@jmagman jmagman requested a review from tarrinneal as a code owner January 19, 2024 21:08
@jmagman jmagman added the autosubmit Merge PR when tree becomes green via auto submit App label Jan 19, 2024
@auto-submit auto-submit bot merged commit 44ee590 into flutter:main Jan 19, 2024
@jmagman jmagman deleted the repo-checks branch January 19, 2024 22:38
auto-submit bot pushed a commit that referenced this pull request Jan 20, 2024
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
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 22, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Jan 22, 2024
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App override: no changelog needed Override the check requiring CHANGELOG updates for most changes override: no versioning needed Override the check requiring version bumps for most changes p: file_selector p: pigeon platform-macos
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[packages] Add support for swift-format
2 participants