Skip to content

Commit

Permalink
support github action test 1
Browse files Browse the repository at this point in the history
  • Loading branch information
yume190 committed Aug 29, 2023
1 parent 2890c17 commit 9497285
Show file tree
Hide file tree
Showing 10 changed files with 256 additions and 38 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ jobs:
- name: Checkout code
uses: actions/checkout@v3

- name: SPM Cache
uses: actions/cache@v2
with:
path: .build
key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }}
restore-keys: |
${{ runner.os }}-spm-
- name: Build Binaries
run: |
swift build -c release --arch arm64 --arch x86_64
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,17 @@ jobs:

steps:
- uses: actions/checkout@v3

- name: SPM Cache
uses: actions/cache@v2
with:
path: .build
key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }}
restore-keys: |
${{ runner.os }}-spm-
- name: Build
run: swift build -v

- name: Run tests
run: swift test -v
14 changes: 13 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ test: build

.PHONY: release
release:
@swift build -c release
@swift build -c release --arch x86_64

.PHONY: releaseArm
releaseArm:
@swift build -c release --arch arm64

.PHONY: releaseAll
releaseAll:
Expand Down Expand Up @@ -60,3 +64,11 @@ single:
leakDetect \
--sdk macosx \
--file fixture/temp.swift

.PHONY: proj
proj:
# git clone https://github.com/antranapp/LeakDetector

leakDetect \
--module LeakDetectorDemo \
--file LeakDetector/LeakDetectorDemo.xcworkspace
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/yume190/TypeFill",
"state" : {
"revision" : "4db66dfdb227ad99827e3bb1aa1af300d1050802",
"version" : "0.4.7"
"revision" : "84cc8baa4370ab49535a8b6f0e6eeb9257432c34",
"version" : "0.4.9"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ let package = Package(

.package(
url: "https://github.com/yume190/TypeFill",
from: "0.4.7"
from: "0.4.9"
),
// .package(path: "../TypeFill"),

Expand Down
23 changes: 10 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,26 @@ mint install yume190/LeakDetect

``` bash
leakDetect \
--moduleName "SCHEME NAME" \
--targetType xcworkspace \
--file Sample.xcworkspace

--module "SCHEME NAME" \
--file Sample.xcworkspace

leakDetect \
--moduleName "SCHEME NAME" \
--targetType xcodeproj \
--module "SCHEME NAME" \
--file Sample.xcodeproj
```

#### [Assign](LeakDetectKit/Assign/AssignClosureVisitor.swift)

Detect assign instance function.

1. `x = self.func`
[o] Check function is `instance function`.
[x] Check self is `struct`
- [x] Check function is `instance function`.
- [ ] Check self is `struct`

2. `y(self.func)`
[o] Check function is `instance function`.
[x] Check parameter is `escaping closure`
- [x] Check function is `instance function`.
- [ ] Check parameter is `escaping closure`

see [Don't use this syntax!](https://www.youtube.com/watch?v=mzsz_Tit1HA).
see [Don't use this syntax!](https://www.youtube.com/watch?v=mzsz_Tit1HA).

```swift
func escape(block: @escaping () -> Void) {}
Expand All @@ -62,6 +60,5 @@ cd LeakDetector

leakDetect \
--module LeakDetectorDemo \
--targetType xcworkspace \
--file LeakDetectorDemo.xcworkspace
```
21 changes: 17 additions & 4 deletions Sources/LeakDetect/Arguments+Ex.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,23 @@ import SKClient
import PathKit

extension Reporter: ExpressibleByArgument {
static let all: String = Reporter
.allCases
.map(\.rawValue)
.joined(separator: "|")
public init?(argument: String) {

switch argument {
case "xcode":
self = .xcode
case "vscode":
self = .vscode
default:
self = .custom { _, _ in }
}
}
public var defaultValueDescription: String { "vscode" }

public static var allValueStrings: [String] { ["xcode", "vscode", "custom"] }
public static var defaultCompletionKind: CompletionKind { .list(allValueStrings) }

static let all: String = "xcode|vscode|custom"
}

extension SDK: ExpressibleByArgument {}
Expand Down
59 changes: 44 additions & 15 deletions Sources/LeakDetect/Command.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,20 @@ import LeakDetectKit
import SKClient
import SourceKittenFramework

struct Command: ParsableCommand {
struct Command: AsyncParsableCommand {
static var configuration: CommandConfiguration = .init(
abstract: "A Tool to Detect Potential Leaks",
discussion: """
# Example:
git clone https://github.com/antranapp/LeakDetector
cd LeakDetector
leakDetect \
--module LeakDetectorDemo \
--targetType xcworkspace \
--file LeakDetectorDemo.xcworkspace
leakDetect --module LeakDetectorDemo --file LeakDetectorDemo.xcworkspace
""",
version: "0.0.4"
)

@Flag(name: [.customLong("verbose", withSingleDash: false), .short], help: "print inpect time")
@Flag(name: [.customLong("verbose", withSingleDash: false), .short], help: "verbose")
var verbose: Bool = false

@Option(name: [.customLong("reporter", withSingleDash: false)], help: "[\(Reporter.all)]")
Expand All @@ -36,24 +33,31 @@ struct Command: ParsableCommand {
@Option(name: [.customLong("sdk", withSingleDash: false)], help: "[\(SDK.all)]")
var sdk: SDK = .iphonesimulator

@Option(name: [.customLong("targetType", withSingleDash: false)], help: "[\(Reporter.all)]")
@Option(name: [.customLong("targetType", withSingleDash: false)], help: "[\(TargetType.all)]")
var targetType: TargetType = .auto

@Option(name: [.customLong("module", withSingleDash: false)], help: "Name of Swift module to document (can't be used with `--single-file`)")
@Option(name: [.customLong("module", withSingleDash: false)], help: "Name of Swift module to document (can't be used with `--targetType singleFile`)")
var moduleName = ""

@Option(name: [.customLong("file", withSingleDash: false)], help: "xcworkspace/xcproject/xxx.swift")
@Option(name: [.customLong("file", withSingleDash: false)], help: "xxx.xcworkspace/xxx.xcodeproj/xxx.swift")
var file: String
var path: String {
URL(fileURLWithPath: file).path
}

var base: String {
let _base = path.removeSuffix(file)

if _base.isEmpty {
return URL(fileURLWithPath: file).deletingLastPathComponent().path
} else {
return _base
}
}

@Argument(help: "Arguments passed to `xcodebuild` or `swift build`")
var arguments: [String] = []

typealias LeakCount = Int

private var module: Module? {
let moduleName = self.moduleName.isEmpty ? nil : self.moduleName

Expand Down Expand Up @@ -82,11 +86,17 @@ struct Command: ParsableCommand {
return nil
}
}

mutating func run() throws {
mutating func run() async throws {
let githubAction = GithubAtionReporter(base: base)
let newReporter = Reporter.custom { [weak githubAction] location, _ in
githubAction?.add(location)
}

if case .singleFile = targetType.detect(path) {
try SingleFilePipeline(path, arguments + [path] + sdk.pathArgs)
.detect(reporter, verbose)
.detect(newReporter, verbose)

try await githubAction?.call()
return
}

Expand All @@ -95,6 +105,25 @@ struct Command: ParsableCommand {
return
}

try Pipeline.detect(module, reporter, verbose)
try Pipeline.detect(module, newReporter, verbose)
try await githubAction?.call()
}
}

extension String {
func removeSuffix(_ text: String) -> String {
if self.hasSuffix(text) {
return String(self.dropLast(text.count))
} else {
return self
}
}

func removePrefix(_ text: String) -> String {
if self.hasPrefix(text) {
return String(self.dropFirst(text.count))
} else {
return self
}
}
}
4 changes: 2 additions & 2 deletions Sources/LeakDetect/Entry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation

@main
struct Main {
static func main() throws {
Command.main()
static func main() async throws {
await Command.main()
}
}
Loading

0 comments on commit 9497285

Please sign in to comment.