Skip to content

Add a command to dev utils that run all other necessary scripts to submit a PR #2334

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 2 commits into from
Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ Alternatively, you can generate the files from the command line by running the f
swift run --package-path CodeGeneration
```

## Running Pre-PR Checks Script

To ensure that your changes to the project are implemented correctly and do not introduce issues across the repository, a script has been provided to automate the necessary pre-PR checks.

```bash
./swift-syntax-dev-utils local-pr-precheck
```

> [!NOTE]
> Running the pre-PR checks script may take some time, so it's recommended to perform this final check before submitting a PR rather than after every change.

## Authoring commits

Prefer to squash the commits of your PR (*pull request*) and avoid adding commits like “Address review comments”. This creates a clearer git history, which doesn’t need to record the history of how the PR evolved.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct SwiftSyntaxDevUtils: ParsableCommand {
Build.self,
Format.self,
GenerateSourceCode.self,
LocalPrPrecheck.self,
Test.self,
VerifyDocumentation.self,
VerifySourceCode.self,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

import ArgumentParser
import Foundation

struct LocalPrPrecheck: ParsableCommand {
static let configuration = CommandConfiguration(
abstract: """
Ensure changes are fully tested, formatted, and validated before pull request submission.
"""
)

@OptionGroup
var arguments: SourceCodeGeneratorArguments
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ahoppen I've used this arguments group because it has all the needed arguments for this command but the name doesn't fit anymore, should I change it or stop using it and create local arguments?

Copy link
Member

Choose a reason for hiding this comment

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

If you have any good new name ideas for SourceCodeGeneratorArguments. If you have any, I think renaming would be nice but otherwise, I think it’s OK as-is as well.


func run() throws {
let executor = LocalPrPrecheckExecutor(
toolchain: try arguments.toolchain,
verbose: arguments.verbose
)
try executor.run()
}
}

struct LocalPrPrecheckExecutor {
private let formatExecutor: FormatExecutor
private let generateSourceCodeExecutor: GenerateSourceCodeExecutor
private let buildExecutor: BuildExecutor
private let testExecutor: TestExecutor

/// Creates an executor
/// - Parameters:
/// - toolchain: The path to the toolchain that shall be used to build SwiftSyntax.
/// - verbose: Enable verbose logging.
init(toolchain: URL, verbose: Bool = false) {
self.formatExecutor = FormatExecutor(update: false, verbose: verbose)
self.generateSourceCodeExecutor = GenerateSourceCodeExecutor(toolchain: toolchain, verbose: verbose)
self.buildExecutor = BuildExecutor(swiftPMBuilder: SwiftPMBuilder(toolchain: toolchain, useLocalDeps: false, verbose: verbose))
self.testExecutor = TestExecutor(swiftPMBuilder: SwiftPMBuilder(toolchain: toolchain, useLocalDeps: false, verbose: verbose))
}

func run() throws {
try formatExecutor.run()
try generateSourceCodeExecutor.run(sourceDir: Paths.sourcesDir)
try buildExecutor.run()
try testExecutor.run()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ struct SwiftPMBuilder {
/// no round-trip or assertion failures.
let enableTestFuzzing: Bool

/// A flag indicating whether to use local dependencies during the build process.
let useLocalDeps: Bool

/// Treat all warnings as errors.
let warningsAsErrors: Bool

Expand All @@ -51,6 +54,7 @@ struct SwiftPMBuilder {
release: Bool = false,
enableRawSyntaxValidation: Bool = false,
enableTestFuzzing: Bool = false,
useLocalDeps: Bool = true,
warningsAsErrors: Bool = false,
verbose: Bool = false
) {
Expand All @@ -60,6 +64,7 @@ struct SwiftPMBuilder {
self.release = release
self.enableRawSyntaxValidation = enableRawSyntaxValidation
self.enableTestFuzzing = enableTestFuzzing
self.useLocalDeps = useLocalDeps
self.warningsAsErrors = warningsAsErrors
self.verbose = verbose
}
Expand Down Expand Up @@ -139,8 +144,10 @@ struct SwiftPMBuilder {
additionalEnvironment["SWIFTPARSER_ENABLE_ALTERNATE_TOKEN_INTROSPECTION"] = "1"
}

// Tell other projects in the unified build to use local dependencies
additionalEnvironment["SWIFTCI_USE_LOCAL_DEPS"] = "1"
if useLocalDeps {
// Tell other projects in the unified build to use local dependencies
additionalEnvironment["SWIFTCI_USE_LOCAL_DEPS"] = "1"
}

return additionalEnvironment
}
Expand Down