Skip to content

Commit abe9e8f

Browse files
xiaoweiizxkane
authored andcommitted
ci: add github action.
1 parent 122c308 commit abe9e8f

File tree

7 files changed

+99
-9
lines changed

7 files changed

+99
-9
lines changed

.github/workflows/swiftlint.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Swift SDK Lint
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
jobs:
10+
code-lint:
11+
runs-on: macos-12
12+
steps:
13+
- uses: actions/checkout@v3
14+
- name: Run swiftformat
15+
run: swiftformat .
16+
- name: Run swiftlint
17+
run: swiftlint

.github/workflows/test.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Swift SDK Test
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
jobs:
10+
test:
11+
runs-on: macos-12
12+
steps:
13+
- uses: actions/checkout@v3
14+
- name: Run test
15+
run: xcodebuild test -scheme aws-solution-clickstream-swift -destination 'platform=iOS Simulator,name=iPhone 14 Pro,OS=latest' -resultBundlePath .build/test/TestResults.xcresult | xcpretty --simple --color --report junit
16+
- name: Upload Test Report
17+
uses: codecov/codecov-action@v3
18+
with:
19+
name: report
20+
files: .build/test/TestResults.xcresult
21+
swift: true
22+

.github/workflows/title-lint.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Commit Title Lint
2+
3+
on:
4+
pull_request:
5+
branches: [ "main" ]
6+
7+
jobs:
8+
title-lint:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: amannn/action-semantic-pull-request@v3.2.6
12+
env:
13+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
14+
with:
15+
# Configure which types are allowed.
16+
# Default: https://github.com/commitizen/conventional-commit-types
17+
types: |
18+
fix
19+
feat
20+
docs
21+
style
22+
refactor
23+
perf
24+
test
25+
build
26+
ci
27+
chore
28+
revert
29+
release
30+
# Configure that a scope must always be provided.
31+
requireScope: false
32+
# Configure additional validation for the subject based on a regex.
33+
# This example ensures the subject doesn't start with an uppercase character.
34+
subjectPattern: ^(?![A-Z]).+$
35+
# If `subjectPattern` is configured, you can use this property to override
36+
# the default error message that is shown when the pattern doesn't match.
37+
# The variables `subject` and `title` can be used within the message.
38+
subjectPatternError: |
39+
The subject "{subject}" found in the pull request title "{title}"
40+
didn't match the configured pattern. Please ensure that the subject
41+
doesn't start with an uppercase character.
42+
# For work-in-progress PRs you can typically use draft pull requests
43+
# from Github. However, private repositories on the free plan don't have
44+
# this option and therefore this action allows you to opt-in to using the
45+
# special "[WIP]" prefix to indicate this state. This will avoid the
46+
# validation of the PR title and the pull request checks remain pending.
47+
# Note that a second check will be reported if this is enabled.
48+
wip: true

Sources/Clickstream/DataBase/ClickstreamDBUtil.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class ClickstreamDBUtil: ClickstreamDBProtocol {
7676
_ = try dbAdapter.executeQuery(deleteStatement, [])
7777
}
7878

79-
// swiftlint:disable: force_cast
79+
// swiftlint:disable force_cast
8080
func getTotalSize() throws -> Int64 {
8181
let getTotalStatement = """
8282
SELECT SUM(eventSize) FROM Event
@@ -92,6 +92,7 @@ class ClickstreamDBUtil: ClickstreamDBProtocol {
9292
let totalCount = try dbAdapter.executeQuery(getEventCountStatement, []).scalar() as! Int64
9393
return totalCount
9494
}
95+
// swiftlint:enable force_cast
9596
}
9697

9798
extension ClickstreamDBUtil: ClickstreamLogger {}

Sources/Clickstream/Dependency/Clickstream/ActivityTracking/ActivityTracker.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,17 @@ class ActivityTracker: ActivityTrackerBehaviour {
132132
#if canImport(UIKit)
133133
if backgroundTrackingTimeout > 0 {
134134
backgroundTask = UIApplication.shared.beginBackgroundTask(withName:
135-
Constants.backgroundTask) { [weak self] in
135+
Constants.backgroundTask)
136+
{ [weak self] in
136137
self?.stateMachine.process(.backgroundTrackingDidTimeout)
137138
self?.stopBackgroundTracking()
138139
}
139140
}
140141
#endif
141142
guard backgroundTrackingTimeout != .infinity else { return }
142143
backgroundTimer = Timer.scheduledTimer(withTimeInterval:
143-
backgroundTrackingTimeout, repeats: false) { [weak self] _ in
144+
backgroundTrackingTimeout, repeats: false)
145+
{ [weak self] _ in
144146
self?.stateMachine.process(.backgroundTrackingDidTimeout)
145147
self?.stopBackgroundTracking()
146148
}

Tests/ClickstreamTests/Clickstream/EventRecorderTest.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ class EventRecorderTest: XCTestCase {
307307
try eventRecorder.save(clickstreamEvent)
308308
eventRecorder.submitEvents()
309309
XCTAssertEqual(1, eventRecorder.queue.operationCount)
310-
Thread.sleep(forTimeInterval: 0.1)
310+
Thread.sleep(forTimeInterval: 0.3)
311311
let totalEvent = try dbUtil.getEventCount()
312312
XCTAssertEqual(0, totalEvent)
313313
}
@@ -357,7 +357,7 @@ class EventRecorderTest: XCTestCase {
357357
eventRecorder.submitEvents()
358358
eventRecorder.submitEvents()
359359
XCTAssertEqual(2, eventRecorder.queue.operationCount)
360-
Thread.sleep(forTimeInterval: 0.3)
360+
Thread.sleep(forTimeInterval: 0.5)
361361
let totalEvent = try dbUtil.getEventCount()
362362
XCTAssertEqual(0, totalEvent)
363363
}
@@ -369,7 +369,7 @@ class EventRecorderTest: XCTestCase {
369369
for _ in 0 ..< 1_100 {
370370
eventRecorder.submitEvents()
371371
}
372-
XCTAssertEqual(1_000, eventRecorder.queue.operationCount)
372+
XCTAssertTrue(eventRecorder.queue.operationCount <= 1_000)
373373
}
374374
}
375375

Tests/ClickstreamTests/IntegrationTest.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ class IntegrationTest: XCTestCase {
6767
]
6868
let event = BaseClickstreamEvent(name: "userId", attribute: attribute)
6969
ClickstreamAnalytics.recordEvent(event: event)
70-
Thread.sleep(forTimeInterval: 0.3)
70+
Thread.sleep(forTimeInterval: 0.5)
7171
let eventCount = try eventRecorder.dbUtil.getEventCount()
7272
XCTAssertEqual(0, eventCount)
7373
}
7474

7575
func testRecordOneEventWithNameSuccess() throws {
7676
ClickstreamAnalytics.recordEvent(eventName: "testEvent")
77-
Thread.sleep(forTimeInterval: 0.3)
77+
Thread.sleep(forTimeInterval: 0.5)
7878
let eventCount = try eventRecorder.dbUtil.getEventCount()
7979
XCTAssertEqual(0, eventCount)
8080
}
@@ -167,7 +167,7 @@ class IntegrationTest: XCTestCase {
167167
configuration.isCompressEvents = true
168168
configuration.endpoint = testSuccessEndpoint
169169
ClickstreamAnalytics.recordEvent(eventName: "testEvent")
170-
Thread.sleep(forTimeInterval: 0.3)
170+
Thread.sleep(forTimeInterval: 1)
171171
let eventCount = try eventRecorder.dbUtil.getEventCount()
172172
XCTAssertEqual(0, eventCount)
173173
}

0 commit comments

Comments
 (0)