Skip to content
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

Add CI for formatting #33

Merged
merged 7 commits into from
Dec 12, 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
37 changes: 37 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Lint

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]

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

jobs:
validate_format_config:
name: Validate Format Config
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Install apt dependencies
run: sudo apt-get -qq update && sudo apt-get -qq -y install curl

- name: Compare against swift-mmio swift-format config
run: |
curl -sL https://raw.githubusercontent.com/apple/swift-mmio/refs/heads/main/SupportingFiles/Tools/swift-format/.swift-format -o .swift-format-mmio
diff .swift-format .swift-format-mmio

soundness:
name: Soundness
uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main
with:
api_breakage_check_enabled: false # this repo doesn't vend any API
license_header_check_enabled: false # incorrectly flags this github workflow yml file
license_header_check_project_name: "" # bug: https://github.com/swiftlang/github-workflows/issues/76
shell_check_enabled: false # incorrectly flags tutorial content
unacceptable_language_check_enabled: false # incorrectly flags "master" in external branch names
3 changes: 2 additions & 1 deletion .swift-format
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"lineBreakBeforeControlFlowKeywords" : false,
"lineBreakBeforeEachArgument" : false,
"lineBreakBeforeEachGenericRequirement" : false,
"lineLength" : 160,
"lineLength" : 80,
"maximumBlankLines" : 1,
"multiElementCollectionTrailingCommas" : true,
"noAssignmentInExpressions" : {
Expand Down Expand Up @@ -62,6 +62,7 @@
"UseWhereClausesInForLoops" : false,
"ValidateDocumentationComments" : true
},
"spacesBeforeEndOfLineComments": 2,
"spacesAroundRangeFormationOperators" : false,
"tabWidth" : 2,
"version" : 1
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import PackageDescription
let package = Package(
name: "swift-matter-examples",
products: [
.library(name: "SwiftMatterExamples", targets: ["SwiftMatterExamples"]),
.library(name: "SwiftMatterExamples", targets: ["SwiftMatterExamples"])
],
targets: [
.target(name: "SwiftMatterExamples")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#! /bin/sh

# Install Homebrew
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#! /bin/sh

# Install Homebrew
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#! /bin/sh

# Install Homebrew
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#! /bin/sh

# Install Homebrew
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#! /bin/sh

# Install Homebrew
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#! /bin/sh

# Install Homebrew
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#! /bin/sh

# Install Homebrew
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
//
//===----------------------------------------------------------------------===//

func app_main() {
func main() {
print("🏎️ Hello, Embedded Swift! (LED Blink)")
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
//===----------------------------------------------------------------------===//

@_cdecl("app_main")
func app_main() {
func main() {
print("🏎️ Hello, Embedded Swift! (LED Blink)")
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//===----------------------------------------------------------------------===//

@_cdecl("app_main")
func app_main() {
func main() {
print("🏎️ Hello, Embedded Swift! (LED Blink)")

let led = LED()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//===----------------------------------------------------------------------===//

@_cdecl("app_main")
func app_main() {
func main() {
print("🏎️ Hello, Embedded Swift! (LED Blink)")

let led = LED()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//===----------------------------------------------------------------------===//

@_cdecl("app_main")
func app_main() {
func main() {
print("🏎️ Hello, Embedded Swift! (LED Blink)")

let led = LED()
Expand All @@ -21,7 +21,7 @@ func app_main() {
sleep(1)
led.enabled.toggle()
if led.enabled {
led.color = .hueSaturation(Int.random(in: 0 ..< 360), 100)
led.color = .hueSaturation(Int.random(in: 0..<360), 100)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
//===----------------------------------------------------------------------===//

@_cdecl("app_main")
func app_main() {
func main() {
print("🏎️ Hello, Embedded Swift! (Smart Light)")
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//===----------------------------------------------------------------------===//

@_cdecl("app_main")
func app_main() {
func main() {
print("🏎️ Hello, Embedded Swift! (Smart Light)")

let led = LED()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//===----------------------------------------------------------------------===//

@_cdecl("app_main")
func app_main() {
func main() {
print("🏎️ Hello, Embedded Swift! (Smart Light)")

let led = LED()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//===----------------------------------------------------------------------===//

@_cdecl("app_main")
func app_main() {
func main() {
print("🏎️ Hello, Embedded Swift! (Smart Light)")

let led = LED()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//===----------------------------------------------------------------------===//

@_cdecl("app_main")
func app_main() {
func main() {
print("🏎️ Hello, Embedded Swift! (Smart Light)")

let led = LED()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//===----------------------------------------------------------------------===//

@_cdecl("app_main")
func app_main() {
func main() {
print("🏎️ Hello, Embedded Swift! (Smart Light)")

let led = LED()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//===----------------------------------------------------------------------===//

@_cdecl("app_main")
func app_main() {
func main() {
print("🏎️ Hello, Embedded Swift! (Smart Light)")

let led = LED()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//===----------------------------------------------------------------------===//

@_cdecl("app_main")
func app_main() {
func main() {
print("🏎️ Hello, Embedded Swift! (Smart Light)")

let led = LED()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//===----------------------------------------------------------------------===//

@_cdecl("app_main")
func app_main() {
func main() {
print("🏎️ Hello, Embedded Swift! (Smart Light)")

let led = LED()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,14 @@

@Steps {
@Step {
We start the application by declaring an **`app_main`** function with a print statement to show the application has started.

`app_main` serves the same purpose as a `main` function in a traditional user-land application and acts as the primary entry point for our firmware application.
We start the application by declaring an **`main`** function with a print statement to show the application has started.

@Code(name: "Main.swift", file: "walkthrough-example-led-blink-01.swift", previousFile: "walkthrough-example-led-blink-00.swift")
}

@Step {
We use the **`@_cdecl("app_main")`** attribute to generate a wrapper C symbol which is expected by ESP IDF.

> Important: Underscored attributes, like `@_cdecl`, are unstable features of the Swift compiler and may change behavior or break between compiler versions.

@Code(name: "Main.swift", file: "walkthrough-example-led-blink-02.swift", previousFile: "walkthrough-example-led-blink-01.swift")
Expand Down
2 changes: 1 addition & 1 deletion empty-template/main/Main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
//===----------------------------------------------------------------------===//

@_cdecl("app_main")
func app_main() {
func main() {
print("🏎️ Hello, Embedded Swift!")
}
2 changes: 1 addition & 1 deletion empty-template/main/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
dependencies:
espressif/cmake_utilities:
version: 0.*
rules: # will add "optional_component" only when all if clauses are True
rules: # will add "optional_component" only when all if clauses are True
- if: "idf_version >=5.0"
- if: "target in [esp32c2]"
13 changes: 7 additions & 6 deletions led-blink/main/LED.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,27 +53,28 @@ final class LED {
// Hue range is 0 ..< 360.
var hue: Int {
switch self {
case .hueSaturation(let hue, _): return hue
case .temperature: return 0
case .hueSaturation(let hue, _): return hue
case .temperature: return 0
}
}

// Saturation is 0 ... 100.
var saturation: Int {
switch self {
case .hueSaturation(_, let saturation): return saturation
case .temperature: return 0
case .hueSaturation(_, let saturation): return saturation
case .temperature: return 0
}
}
}

var handle: led_driver_handle_t

init() {
var config = led_driver_get_config()
let handle = led_driver_init(&config)
guard let handle else { fatalError("Failed to initialize handle") }
led_driver_set_power(handle, true)
self.handle = handle!
self.handle = handle
}

}
Expand Down
4 changes: 2 additions & 2 deletions led-blink/main/Main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//===----------------------------------------------------------------------===//

@_cdecl("app_main")
func app_main() {
func main() {
print("🏎️ Hello, Embedded Swift! (LED Blink)")

let led = LED()
Expand All @@ -21,7 +21,7 @@ func app_main() {
sleep(1)
led.enabled.toggle()
if led.enabled {
led.color = .hueSaturation(Int.random(in: 0 ..< 360), 100)
led.color = .hueSaturation(Int.random(in: 0..<360), 100)
}
}
}
2 changes: 1 addition & 1 deletion led-blink/main/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
dependencies:
espressif/cmake_utilities:
version: 0.*
rules: # will add "optional_component" only when all if clauses are True
rules: # will add "optional_component" only when all if clauses are True
- if: "idf_version >=5.0"
- if: "target in [esp32c2]"
Loading
Loading