Skip to content

Commit

Permalink
ci: add GitHub Actions workflow (#1)
Browse files Browse the repository at this point in the history
* ci: add GitHub Actions workflow
---------

Co-authored-by: josetorronteras <josetorronteras@users.noreply.github.com>
  • Loading branch information
josetorronteras and josetorronteras committed Feb 7, 2024
1 parent 04669ce commit 111d4a7
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 29 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/swift-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Swift Format

on:
pull_request:
branches:
- main

jobs:
swift-format:
runs-on: macos-14
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Xcode select
run: sudo xcode-select -s '/Applications/Xcode_15.2.app/Contents/Developer'
- name: Install Swift Format
run: brew install swift-format
- name: Swift Format
run: swift format --in-place --recursive ./Package.swift ./Sources ./Tests --configuration swift-format.json
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Run swift-format
22 changes: 22 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: testing

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
testing:
runs-on: macos-14
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Xcode select
run: sudo xcode-select -s '/Applications/Xcode_15.2.app/Contents/Developer'
- name: Build
run: swift build
- name: Test
run: swift test
6 changes: 3 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
import CompilerPluginSupport
import PackageDescription

let package = Package(
name: "EmailValidation",
Expand All @@ -20,7 +20,7 @@ let package = Package(
],
dependencies: [
// Depend on the Swift 5.9 release of SwiftSyntax
.package(url: "https://github.com/apple/swift-syntax.git", from: "509.0.0"),
.package(url: "https://github.com/apple/swift-syntax.git", from: "509.0.0")
],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
Expand All @@ -30,7 +30,7 @@ let package = Package(
name: "EmailValidationMacros",
dependencies: [
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
.product(name: "SwiftCompilerPlugin", package: "swift-syntax")
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
]
),

Expand Down
3 changes: 2 additions & 1 deletion Sources/EmailValidation/EmailValidation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
///
/// produces a tuple `(x + y, "x + y")`.
@freestanding(expression)
public macro stringify<T>(_ value: T) -> (T, String) = #externalMacro(module: "EmailValidationMacros", type: "StringifyMacro")
public macro stringify<T>(_ value: T) -> (T, String) =
#externalMacro(module: "EmailValidationMacros", type: "StringifyMacro")
2 changes: 1 addition & 1 deletion Sources/EmailValidationMacros/EmailValidationMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ public struct StringifyMacro: ExpressionMacro {
@main
struct EmailValidationPlugin: CompilerPlugin {
let providingMacros: [Macro.Type] = [
StringifyMacro.self,
StringifyMacro.self
]
}
48 changes: 24 additions & 24 deletions Tests/EmailValidationTests/EmailValidationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,43 @@ import XCTest

// Macro implementations build for the host, so the corresponding module is not available when cross-compiling. Cross-compiled tests may still make use of the macro itself in end-to-end tests.
#if canImport(EmailValidationMacros)
import EmailValidationMacros
import EmailValidationMacros

let testMacros: [String: Macro.Type] = [
"stringify": StringifyMacro.self,
]
let testMacros: [String: Macro.Type] = [
"stringify": StringifyMacro.self
]
#endif

final class EmailValidationTests: XCTestCase {
func testMacro() throws {
#if canImport(EmailValidationMacros)
assertMacroExpansion(
"""
#stringify(a + b)
""",
expandedSource: """
(a + b, "a + b")
""",
macros: testMacros
)
assertMacroExpansion(
"""
#stringify(a + b)
""",
expandedSource: """
(a + b, "a + b")
""",
macros: testMacros
)
#else
throw XCTSkip("macros are only supported when running tests for the host platform")
throw XCTSkip("macros are only supported when running tests for the host platform")
#endif
}

func testMacroWithStringLiteral() throws {
#if canImport(EmailValidationMacros)
assertMacroExpansion(
#"""
#stringify("Hello, \(name)")
"""#,
expandedSource: #"""
("Hello, \(name)", #""Hello, \(name)""#)
"""#,
macros: testMacros
)
assertMacroExpansion(
#"""
#stringify("Hello, \(name)")
"""#,
expandedSource: #"""
("Hello, \(name)", #""Hello, \(name)""#)
"""#,
macros: testMacros
)
#else
throw XCTSkip("macros are only supported when running tests for the host platform")
throw XCTSkip("macros are only supported when running tests for the host platform")
#endif
}
}
5 changes: 5 additions & 0 deletions swift-format.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"indentation" : {
"spaces" : 4
}
}

0 comments on commit 111d4a7

Please sign in to comment.