Skip to content

Commit 4d6bad1

Browse files
authored
Merge pull request #1000 from swiftlang/automerge/merge-main-2025-04-18_21-03
Merge `main` into `release/6.2`
2 parents 6242861 + 8b55263 commit 4d6bad1

File tree

4 files changed

+32
-57
lines changed

4 files changed

+32
-57
lines changed

.github/workflows/automerge.yml

Lines changed: 7 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,17 @@
11
name: Create PR to merge main into release branch
2-
32
# In the first period after branching the release branch, we typically want to include all changes from `main` also in the release branch. This workflow automatically creates a PR every Monday to merge main into the release branch.
43
# Later in the release cycle we should stop this practice to avoid landing risky changes by disabling this workflow. To do so, disable the workflow as described in https://docs.github.com/en/actions/managing-workflow-runs-and-deployments/managing-workflow-runs/disabling-and-enabling-a-workflow
5-
64
on:
75
schedule:
8-
- cron: '0 0 * * MON'
6+
- cron: '0 9 * * MON'
97
workflow_dispatch:
10-
118
jobs:
129
create_merge_pr:
1310
name: Create PR to merge main into release branch
14-
runs-on: ubuntu-latest
11+
uses: swiftlang/github-workflows/.github/workflows/create_automerge_pr.yml@main
12+
with:
13+
base_branch: release/6.2
14+
permissions:
15+
contents: write
16+
pull-requests: write
1517
if: (github.event_name == 'schedule' && github.repository == 'swiftlang/swift-format') || (github.event_name != 'schedule') # Ensure that we don't run this on a schedule in a fork
16-
steps:
17-
- name: Set up variables
18-
id: variables
19-
run: |
20-
echo "release_branch=release/6.2" >> "$GITHUB_OUTPUT"
21-
echo "pr_branch=automerge/merge-main-$(date +%Y-%m-%d)" >> "$GITHUB_OUTPUT"
22-
- name: Checkout repository
23-
uses: actions/checkout@v4
24-
with:
25-
fetch-depth: 0
26-
- name: Create merge commit
27-
id: create_merge_commit
28-
run: |
29-
# Without this, we can't perform git operations in GitHub actions.
30-
git config --global --add safe.directory "$(realpath .)"
31-
git config --local user.name 'swift-ci'
32-
git config --local user.email '[email protected]'
33-
34-
git checkout ${{ steps.variables.outputs.release_branch }}
35-
git merge main
36-
37-
if [[ "$(git rev-parse HEAD)" = "$(git rev-parse main)" ]]; then
38-
echo "has_merged_commits=true" >> "$GITHUB_OUTPUT"
39-
else
40-
echo "has_merged_commits=false" >> "$GITHUB_OUTPUT"
41-
fi
42-
- name: Push branch and create PR
43-
id: push_branch
44-
if: ${{ steps.create_merge_commit.outputs.has_merged_commits }}
45-
env:
46-
GH_TOKEN: ${{ github.token }}
47-
run: |
48-
git checkout -b "${{ steps.variables.outputs.pr_branch }}"
49-
git push --set-upstream origin "${{ steps.variables.outputs.pr_branch }}"
50-
51-
gh pr create -B "${{ steps.variables.outputs.release_branch }}" -H "${{ steps.variables.outputs.pr_branch }}" \
52-
--title 'Merge `main` into `${{ steps.variables.outputs.release_branch }}`' \
53-
--body 'This PR was automatically opened by a GitHub action. Review the changes included in this PR and determine if they should be included in the release branch. If yes, merge the PR. Otherwise revert changes that should not be included on this branch.'

Sources/swift-format/Frontend/Frontend.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,14 +200,21 @@ class Frontend {
200200
/// Creates a new frontend with the given options.
201201
///
202202
/// - Parameter lintFormatOptions: Options that apply during formatting or linting.
203-
init(configurationOptions: ConfigurationOptions, lintFormatOptions: LintFormatOptions) {
203+
init(
204+
configurationOptions: ConfigurationOptions,
205+
lintFormatOptions: LintFormatOptions,
206+
treatWarningsAsErrors: Bool = false
207+
) {
204208
self.configurationOptions = configurationOptions
205209
self.lintFormatOptions = lintFormatOptions
206210

207211
self.diagnosticPrinter = StderrDiagnosticPrinter(
208212
colorMode: lintFormatOptions.colorDiagnostics.map { $0 ? .on : .off } ?? .auto
209213
)
210-
self.diagnosticsEngine = DiagnosticsEngine(diagnosticsHandlers: [diagnosticPrinter.printDiagnostic])
214+
self.diagnosticsEngine = DiagnosticsEngine(
215+
diagnosticsHandlers: [diagnosticPrinter.printDiagnostic],
216+
treatWarningsAsErrors: treatWarningsAsErrors
217+
)
211218
self.configurationProvider = ConfigurationProvider(diagnosticsEngine: self.diagnosticsEngine)
212219
}
213220

Sources/swift-format/Subcommands/Lint.swift

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ extension SwiftFormatCommand {
2828

2929
@Flag(
3030
name: .shortAndLong,
31-
help: "Fail on warnings. Deprecated: All findings are treated as errors now."
31+
help: "Treat all findings as errors instead of warnings."
3232
)
3333
var strict: Bool = false
3434

@@ -37,15 +37,11 @@ extension SwiftFormatCommand {
3737

3838
func run() throws {
3939
try performanceMeasurementOptions.printingInstructionCountIfRequested {
40-
let frontend = LintFrontend(configurationOptions: configurationOptions, lintFormatOptions: lintOptions)
41-
42-
if strict {
43-
frontend.diagnosticsEngine.emitWarning(
44-
"""
45-
Running swift-format with --strict is deprecated and will be removed in the future.
46-
"""
47-
)
48-
}
40+
let frontend = LintFrontend(
41+
configurationOptions: configurationOptions,
42+
lintFormatOptions: lintOptions,
43+
treatWarningsAsErrors: strict
44+
)
4945
frontend.run()
5046

5147
if frontend.diagnosticsEngine.hasErrors {

Sources/swift-format/Utilities/DiagnosticsEngine.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,28 @@ final class DiagnosticsEngine {
2626
/// A Boolean value indicating whether any warnings were emitted by the diagnostics engine.
2727
private(set) var hasWarnings: Bool
2828

29+
/// Whether to upgrade all warnings to errors.
30+
private let treatWarningsAsErrors: Bool
31+
2932
/// Creates a new diagnostics engine with the given diagnostic handlers.
3033
///
3134
/// - Parameter diagnosticsHandlers: An array of functions, each of which takes a `Diagnostic` as
3235
/// its sole argument and returns `Void`. The functions are called whenever a diagnostic is
3336
/// received by the engine.
34-
init(diagnosticsHandlers: [(Diagnostic) -> Void]) {
37+
init(diagnosticsHandlers: [(Diagnostic) -> Void], treatWarningsAsErrors: Bool = false) {
3538
self.handlers = diagnosticsHandlers
3639
self.hasErrors = false
3740
self.hasWarnings = false
41+
self.treatWarningsAsErrors = treatWarningsAsErrors
3842
}
3943

4044
/// Emits the diagnostic by passing it to the registered handlers, and tracks whether it was an
4145
/// error or warning diagnostic.
4246
private func emit(_ diagnostic: Diagnostic) {
47+
var diagnostic = diagnostic
48+
if treatWarningsAsErrors, diagnostic.severity == .warning {
49+
diagnostic.severity = .error
50+
}
4351
switch diagnostic.severity {
4452
case .error: self.hasErrors = true
4553
case .warning: self.hasWarnings = true
@@ -135,7 +143,7 @@ final class DiagnosticsEngine {
135143
/// diagnostics engine and returns it.
136144
private func diagnosticMessage(for finding: Finding) -> Diagnostic {
137145
return Diagnostic(
138-
severity: .error,
146+
severity: .warning,
139147
location: finding.location.map(Diagnostic.Location.init),
140148
category: "\(finding.category)",
141149
message: "\(finding.message.text)"

0 commit comments

Comments
 (0)