Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
34d1bbf
[CI] GitHub Actions support for Linux platform
shahmishal Sep 28, 2024
ab48e0f
Add CODEOWNERS file
shahmishal Sep 28, 2024
26fbd13
Merge pull request #820 from swiftlang/ci-support-linux
shahmishal Sep 28, 2024
1f01ae4
Use human-readable names in pull_request action and consistently use …
ahoppen Sep 29, 2024
a29f7e6
Create a GitHub action to create a release
ahoppen Sep 29, 2024
5cb2b03
Merge pull request #823 from ahoppen/actions-improvements
shahmishal Sep 30, 2024
7a98187
Merge branch 'main' into release-action
shahmishal Sep 30, 2024
d2b01fc
Fix build warning: `eachKeyword` was renamed to `specifier`
ahoppen Sep 29, 2024
acc3c6c
Don’t discard the return value of `FileManager.createFile`
ahoppen Sep 29, 2024
8cb684e
Merge pull request #821 from ahoppen/release-action
ahoppen Sep 30, 2024
9fb082f
Merge pull request #822 from ahoppen/fix-warning
ahoppen Sep 30, 2024
226601a
Replace `Sanity` by `Basic`
ahoppen Sep 30, 2024
77edc43
Quote `$(realpath .)`
ahoppen Sep 30, 2024
83a6ed9
Merge pull request #825 from ahoppen/soundess
ahoppen Sep 30, 2024
abff181
Move tests in `swift-formatTests` to `SwiftFormatTests`
ahoppen Sep 30, 2024
1e0fd86
[CI] Add soundness check (#824)
shahmishal Sep 30, 2024
c1f06b8
Allow the `Publish Release` action to create a tag and release
ahoppen Sep 30, 2024
f7df163
Merge pull request #828 from ahoppen/allow-publish-release-to-publish
ahoppen Oct 1, 2024
b3314ac
Merge pull request #827 from ahoppen/no-executable-test-target
ahoppen Oct 1, 2024
f94d502
Skip files and directories starting with `.` on Windows
ahoppen Oct 1, 2024
6e4c4b5
Merge pull request #829 from ahoppen/skip-dot-windows
ahoppen Oct 1, 2024
6452eff
Bring over swift-syntax's formatter config into swift-format.
allevato Oct 1, 2024
f0eabf8
Run swift-format on swift-format.
allevato Oct 1, 2024
40d3f3e
Re-enable format check (the default behavior).
allevato Oct 1, 2024
e113695
Merge pull request #830 from allevato/reformat
allevato Oct 1, 2024
d36dc4d
Merge remote-tracking branch 'upstream/main' into wasm32-wasi
kkebo Oct 1, 2024
a4515d7
style: reformat swift-format
kkebo Oct 1, 2024
aabb2f7
fix: fix build
kkebo Oct 3, 2024
1da0589
test: fix FileIteratorTests for WASI
kkebo Oct 3, 2024
c46a028
feat(wasi): add support for the `.skipHiddenFiles` option
kkebo Oct 3, 2024
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
28 changes: 28 additions & 0 deletions .github/workflows/create-release-commits.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

set -ex

SWIFT_SYNTAX_TAG="$1"
SWIFT_FORMAT_VERSION="$2"

if [[ -z "$SWIFT_SYNTAX_TAG" || -z "$SWIFT_FORMAT_VERSION" ]]; then
echo "Update the Package manifest to reference a specific version of swift-syntax and embed the given version in the swift-format --version command"
echo "Usage create-release-commits.sh <SWIFT_SYNTAX_TAG> <SWIFT_FORMAT_VERSION>"
echo " SWIFT_SYNTAX_TAG: The tag of swift-syntax to depend on"
echo " SWIFT_FORMAT_VERSION: The version of swift-format that is about to be released"
exit 1
fi

# Without this, we can't perform git operations in GitHub actions.
git config --global --add safe.directory "$(realpath .)"

git config --local user.name 'swift-ci'
git config --local user.email '[email protected]'

sed -E -i "s#branch: \"(main|release/[0-9]+\.[0-9]+)\"#from: \"$SWIFT_SYNTAX_TAG\"#" Package.swift
git add Package.swift
git commit -m "Change swift-syntax dependency to $SWIFT_SYNTAX_TAG"

sed -E -i "s#print\(\".*\"\)#print\(\"$SWIFT_FORMAT_VERSION\"\)#" Sources/swift-format/PrintVersion.swift
git add Sources/swift-format/PrintVersion.swift
git commit -m "Change version to $SWIFT_FORMAT_VERSION"
110 changes: 110 additions & 0 deletions .github/workflows/publish_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
name: Publish Release

on:
workflow_dispatch:
inputs:
prerelease:
type: boolean
description: "Prerelease"
# Whether to create a prerelease or proper release
default: true
required: true
swift_format_version:
type: string
default: 601.0.0
description: "swift-format version"
# The version of swift-format to tag. If this is a prerelease, `-prerelease-<date>` is added to this version.
required: true
swift_syntax_tag:
type: string
default: 601.0.0
description: "swift-syntax version"
# The swift-syntax version to depend on. If this is a prerelease, the latest swift-syntax prerelease tag for this version is used.
required: true

jobs:
check_triggering_actor:
name: Check user is allowed to create release
# Only a single user should be allowed to create releases to avoid two people triggering the creation of a release
# at the same time. If the release manager changes between users, update this condition.
runs-on: ubuntu-latest
steps:
- run: |
if [[ "${{ github.triggering_actor }}" != "ahoppen" ]]; then
echo "${{ github.triggering_actor }} is not allowed to create a release"
exit 1
fi
define_tags:
name: Determine dependent swift-syntax version and prerelease date
runs-on: ubuntu-latest
outputs:
swift_syntax_tag: ${{ steps.swift_syntax_tag.outputs.swift_syntax_tag }}
swift_format_version: ${{ steps.swift_format_version.outputs.swift_format_version }}
steps:
- name: Determine swift-syntax tag to depend on
id: swift_syntax_tag
shell: bash
run: |
if [[ "${{ github.event.inputs.prerelease }}" == "false" ]]; then
SWIFT_SYNTAX_TAG="${{ github.event.inputs.swift_syntax_tag }}"
else
git clone https://github.com/swiftlang/swift-syntax.git
cd swift-syntax
SWIFT_SYNTAX_TAG="$(git tag | grep ${{ github.event.inputs.swift_syntax_tag }}-prerelease | sort -r | head -1)"
fi

echo "Using swift-syntax tag: $SWIFT_SYNTAX_TAG"
echo "swift_syntax_tag=$SWIFT_SYNTAX_TAG" >> "$GITHUB_OUTPUT"
- name: Determine swift-format prerelease version
id: swift_format_version
run: |
if [[ "${{ github.event.inputs.prerelease }}" == "false" ]]; then
SWIFT_FORMAT_VERSION="${{ github.event.inputs.swift_format_version }}"
else
SWIFT_FORMAT_VERSION="${{ github.event.inputs.swift_format_version }}-prerelease-$(date +'%Y-%m-%d')"
fi
echo "Using swift-format version: $SWIFT_FORMAT_VERSION"
echo "swift_format_version=$SWIFT_FORMAT_VERSION" >> "$GITHUB_OUTPUT"
test_debug:
name: Test in Debug configuration
uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main
needs: define_tags
with:
pre_build_command: bash .github/workflows/create-release-commits.sh '${{ needs.define_tags.outputs.swift_syntax_tag }}' '${{ needs.define_tags.outputs.swift_format_version }}'
# We require that releases of swift-format build without warnings
build_command: swift test -Xswiftc -warnings-as-errors
test_release:
name: Test in Release configuration
uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main
needs: define_tags
with:
pre_build_command: bash .github/workflows/create-release-commits.sh '${{ needs.define_tags.outputs.swift_syntax_tag }}' '${{ needs.define_tags.outputs.swift_format_version }}'
# We require that releases of swift-format build without warnings
build_command: swift test -c release -Xswiftc -warnings-as-errors
create_tag:
name: Create Tag
runs-on: ubuntu-latest
needs: [check_triggering_actor, test_debug, test_release, define_tags]
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Create release commits
run: bash .github/workflows/create-release-commits.sh '${{ needs.define_tags.outputs.swift_syntax_tag }}' '${{ needs.define_tags.outputs.swift_format_version }}'
- name: Tag release
run: |
git tag "${{ needs.define_tags.outputs.swift_format_version }}"
git push origin "${{ needs.define_tags.outputs.swift_format_version }}"
- name: Create release
env:
GH_TOKEN: ${{ github.token }}
run: |
if [[ "${{ github.event.inputs.prerelease }}" != "true" ]]; then
# Only create a release automatically for prereleases. For real releases, release notes should be crafted by hand.
exit
fi
gh release create "${{ needs.define_tags.outputs.swift_format_version }}" \
--title "${{ needs.define_tags.outputs.swift_format_version }}" \
--prerelease

16 changes: 16 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Pull request

on:
pull_request:
types: [opened, reopened, synchronize]

jobs:
tests:
name: Test
uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main
soundness:
name: Soundness
uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main
with:
license_header_check_enabled: false
license_header_check_project_name: "Swift.org"
18 changes: 18 additions & 0 deletions .swift-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"version": 1,
"lineLength": 120,
"indentation": {
"spaces": 2
},
"lineBreakBeforeEachArgument": true,
"indentConditionalCompilationBlocks": false,
"prioritizeKeepingFunctionOutputTogether": true,
"rules": {
"AlwaysUseLowerCamelCase": false,
"AmbiguousTrailingClosureOverload": false,
"NoBlockComments": false,
"OrderedImports": true,
"UseLetInEveryBoundCaseVariable": false,
"UseSynthesizedInitializer": false
}
}
14 changes: 14 additions & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#
# This source file is part of the Swift.org open source project
#
# Copyright (c) 2024 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 Swift project authors
#

* @ahoppen @allevato @bnbarham @shawnhyam

.github/ @shahmishal
.swiftci/ @shahmishal
2 changes: 1 addition & 1 deletion Documentation/PrettyPrinter.md
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,6 @@ sense to place this label on the containing group.

Oppen's algorithm prints the indentation whitespace when `break` tokens are
encountered. If we have extra blank lines in between source code, this can
result in hanging or trailing whitespace. Waiting to print the indentation
result in hanging or trailing whitespace. Waiting to print the indentation <!--# ignore-unacceptable-language -->
whitespace until encountering a `syntax`, `comment, or `verbatim` tokens
prevents this.
9 changes: 3 additions & 6 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let package = Package(
name: "swift-format",
platforms: [
.macOS("12.0"),
.iOS("13.0")
.iOS("13.0"),
],
products: [
.executable(
Expand Down Expand Up @@ -48,6 +48,7 @@ let package = Package(
.target(
name: "SwiftFormat",
dependencies: [
.target(name: "WASIHelpers", condition: .when(platforms: [.wasi])),
.product(name: "Markdown", package: "swift-markdown"),
.product(name: "SwiftSyntax", package: "swift-syntax"),
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
Expand Down Expand Up @@ -106,7 +107,6 @@ let package = Package(
dependencies: [
"_SwiftFormatInstructionCounter",
"SwiftFormat",
.target(name: "WASIHelpers", condition: .when(platforms: [.wasi])),
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.product(name: "SwiftSyntax", package: "swift-syntax"),
.product(name: "SwiftParser", package: "swift-syntax"),
Expand Down Expand Up @@ -171,15 +171,12 @@ var dependencies: [Package.Dependency] {
}
}



// MARK: - Compute custom build settings

var swiftformatLinkSettings: [LinkerSetting] {
var swiftformatLinkSettings: [LinkerSetting] {
if installAction {
return [.unsafeFlags(["-no-toolchain-stdlib-rpath"], .when(platforms: [.linux, .android]))]
} else {
return []
}
}

34 changes: 17 additions & 17 deletions Plugins/FormatPlugin/plugin.swift
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
import PackagePlugin
import Foundation
import PackagePlugin

@main
struct FormatPlugin {
func format(tool: PluginContext.Tool, targetDirectories: [String], configurationFilePath: String?) throws {
let swiftFormatExec = URL(fileURLWithPath: tool.path.string)

var arguments: [String] = ["format"]

arguments.append(contentsOf: targetDirectories)

arguments.append(contentsOf: ["--recursive", "--parallel", "--in-place"])

if let configurationFilePath = configurationFilePath {
arguments.append(contentsOf: ["--configuration", configurationFilePath])
}

let process = try Process.run(swiftFormatExec, arguments: arguments)
process.waitUntilExit()

if process.terminationReason == .exit && process.terminationStatus == 0 {
print("Formatted the source code.")
}
else {
} else {
let problem = "\(process.terminationReason):\(process.terminationStatus)"
Diagnostics.error("swift-format invocation failed: \(problem)")
}
Expand All @@ -35,15 +34,16 @@ extension FormatPlugin: CommandPlugin {
arguments: [String]
) async throws {
let swiftFormatTool = try context.tool(named: "swift-format")

var argExtractor = ArgumentExtractor(arguments)
let targetNames = argExtractor.extractOption(named: "target")
let targetsToFormat = targetNames.isEmpty ? context.package.targets : try context.package.targets(named: targetNames)

let targetsToFormat =
targetNames.isEmpty ? context.package.targets : try context.package.targets(named: targetNames)

let configurationFilePath = argExtractor.extractOption(named: "swift-format-configuration").first
let sourceCodeTargets = targetsToFormat.compactMap{ $0 as? SourceModuleTarget }

let sourceCodeTargets = targetsToFormat.compactMap { $0 as? SourceModuleTarget }

try format(
tool: swiftFormatTool,
targetDirectories: sourceCodeTargets.map(\.directory.string),
Expand All @@ -58,10 +58,10 @@ import XcodeProjectPlugin
extension FormatPlugin: XcodeCommandPlugin {
func performCommand(context: XcodeProjectPlugin.XcodePluginContext, arguments: [String]) throws {
let swiftFormatTool = try context.tool(named: "swift-format")

var argExtractor = ArgumentExtractor(arguments)
let configurationFilePath = argExtractor.extractOption(named: "swift-format-configuration").first

try format(
tool: swiftFormatTool,
targetDirectories: [context.xcodeProject.directory.string],
Expand Down
30 changes: 15 additions & 15 deletions Plugins/LintPlugin/plugin.swift
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
import PackagePlugin
import Foundation
import PackagePlugin

@main
struct LintPlugin {
func lint(tool: PluginContext.Tool, targetDirectories: [String], configurationFilePath: String?) throws {
let swiftFormatExec = URL(fileURLWithPath: tool.path.string)

var arguments: [String] = ["lint"]

arguments.append(contentsOf: targetDirectories)

arguments.append(contentsOf: ["--recursive", "--parallel", "--strict"])

if let configurationFilePath = configurationFilePath {
arguments.append(contentsOf: ["--configuration", configurationFilePath])
}

let process = try Process.run(swiftFormatExec, arguments: arguments)
process.waitUntilExit()

if process.terminationReason == .exit && process.terminationStatus == 0 {
print("Linted the source code.")
}
else {
} else {
let problem = "\(process.terminationReason):\(process.terminationStatus)"
Diagnostics.error("swift-format invocation failed: \(problem)")
}
Expand All @@ -35,16 +34,17 @@ extension LintPlugin: CommandPlugin {
arguments: [String]
) async throws {
let swiftFormatTool = try context.tool(named: "swift-format")

// Extract the arguments that specify what targets to format.
var argExtractor = ArgumentExtractor(arguments)
let targetNames = argExtractor.extractOption(named: "target")

let targetsToFormat = targetNames.isEmpty ? context.package.targets : try context.package.targets(named: targetNames)

let targetsToFormat =
targetNames.isEmpty ? context.package.targets : try context.package.targets(named: targetNames)
let configurationFilePath = argExtractor.extractOption(named: "swift-format-configuration").first

let sourceCodeTargets = targetsToFormat.compactMap { $0 as? SourceModuleTarget }

try lint(
tool: swiftFormatTool,
targetDirectories: sourceCodeTargets.map(\.directory.string),
Expand All @@ -61,7 +61,7 @@ extension LintPlugin: XcodeCommandPlugin {
let swiftFormatTool = try context.tool(named: "swift-format")
var argExtractor = ArgumentExtractor(arguments)
let configurationFilePath = argExtractor.extractOption(named: "swift-format-configuration").first

try lint(
tool: swiftFormatTool,
targetDirectories: [context.xcodeProject.directory.string],
Expand Down
Loading
Loading