Skip to content

Commit 48d3d29

Browse files
committed
add docker setup and CI scripts
motivation: preperation to sanbox changes: * add docker setup and sanity check scripts we can use for CI * add swift formatting rules and adjust formatting * cleanup project name in copyright headers * add contributors list * add linux tests generation script + regenerate linux tests
1 parent cd20490 commit 48d3d29

15 files changed

+591
-29
lines changed

.mailmap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

.swiftformat

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# file options
2+
3+
--exclude .build
4+
5+
# format options
6+
7+
--self insert
8+
--patternlet inline
9+
--stripunusedargs unnamed-only
10+
--comments ignore
11+
12+
# rules

CONTRIBUTORS.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
For the purpose of tracking copyright, this is the list of individuals and
2+
organizations who have contributed source code to the SwiftStatsdClient.
3+
4+
For employees of an organization/company where the copyright of work done
5+
by employees of that company is held by the company itself, only the company
6+
needs to be listed here.
7+
8+
## COPYRIGHT HOLDERS
9+
10+
- Apple Inc. (all contributors with '@apple.com')
11+
12+
### Contributors
13+
14+
- tomer doron <tomerd@apple.com>
15+
16+
**Updating this list**
17+
18+
Please do not edit this file manually. It is generated using `./scripts/generate_contributors_list.sh`. If a name is misspelled or appearing multiple times: add an entry in `./.mailmap`

Package.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
//===----------------------------------------------------------------------===//
44
//
5-
// This source file is part of the StatsdClient open source project
5+
// This source file is part of the SwiftStatsdClient open source project
66
//
7-
// Copyright (c) 2019 the StatsdClient project authors
7+
// Copyright (c) 2019 the SwiftStatsdClient project authors
88
// Licensed under Apache License v2.0
99
//
1010
// See LICENSE.txt for license information
11-
// See CONTRIBUTORS.txt for the list of StatsdClient project authors
11+
// See CONTRIBUTORS.txt for the list of SwiftStatsdClient project authors
1212
//
1313
// SPDX-License-Identifier: Apache-2.0
1414
//

Sources/StatsdClient/StatsdClient.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
//===----------------------------------------------------------------------===//
22
//
3-
// This source file is part of the StatsdClient open source project
3+
// This source file is part of the SwiftStatsdClient open source project
44
//
5-
// Copyright (c) 2019 the StatsdClient project authors
5+
// Copyright (c) 2019 the SwiftStatsdClient project authors
66
// Licensed under Apache License v2.0
77
//
88
// See LICENSE.txt for license information
9-
// See CONTRIBUTORS.txt for the list of StatsdClient project authors
9+
// See CONTRIBUTORS.txt for the list of SwiftStatsdClient project authors
1010
//
1111
// SPDX-License-Identifier: Apache-2.0
1212
//
@@ -282,9 +282,9 @@ private final class Client {
282282
return self.eventLoopGroup.next().makeSucceededFuture(channel)
283283
}
284284

285-
let bootstrap = DatagramBootstrap(group: self.eventLoopGroup)
285+
let bootstrap = DatagramBootstrap(group: eventLoopGroup)
286286
.channelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
287-
.channelInitializer { channel in return channel.pipeline.addHandler(Encoder(address: self.address)) }
287+
.channelInitializer { channel in channel.pipeline.addHandler(Encoder(address: self.address)) }
288288

289289
// the bind address is local and does not really matter, the remote address is addressed by AddressedEnvelope below
290290
let future = bootstrap.bind(host: "0.0.0.0", port: 0)
@@ -309,11 +309,11 @@ private final class Client {
309309
// histogram: <metric name>:<value>|h
310310
// meter: <metric name>:<value>|m
311311
public func write(context: ChannelHandlerContext, data: NIOAny, promise: EventLoopPromise<Void>?) {
312-
let metric = self.unwrapOutboundIn(data)
312+
let metric = unwrapOutboundIn(data)
313313
let string = "\(metric.name):\(metric.value)|\(metric.type.rawValue)"
314314
var buffer = context.channel.allocator.buffer(capacity: string.utf8.count)
315315
buffer.writeString(string)
316-
context.writeAndFlush(self.wrapOutboundOut(AddressedEnvelope(remoteAddress: self.address, data: buffer)), promise: promise)
316+
context.writeAndFlush(wrapOutboundOut(AddressedEnvelope(remoteAddress: self.address, data: buffer)), promise: promise)
317317
}
318318
}
319319
}
@@ -322,7 +322,7 @@ private final class Client {
322322

323323
private enum StatsdUtils {
324324
static func id(label: String, dimensions: [(String, String)]) -> String {
325-
return dimensions.isEmpty ? label : dimensions.reduce(label, { a, b in "\(a).\(b.0).\(b.1)" })
325+
return dimensions.isEmpty ? label : dimensions.reduce(label) { a, b in "\(a).\(b.0).\(b.1)" }
326326
}
327327
}
328328

Tests/LinuxMain.swift

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,31 @@
11
//===----------------------------------------------------------------------===//
22
//
3-
// This source file is part of the StatsdClient open source project
3+
// This source file is part of the SwiftStatsdClient open source project
44
//
5-
// Copyright (c) 2017-2018 the StatsdClient project authors
5+
// Copyright (c) 2019 the SwiftStatsdClient project authors
66
// Licensed under Apache License v2.0
77
//
88
// See LICENSE.txt for license information
9-
// See CONTRIBUTORS.txt for the list of StatsdClient project authors
9+
// See CONTRIBUTORS.txt for the list of SwiftStatsdClient project authors
1010
//
1111
// SPDX-License-Identifier: Apache-2.0
1212
//
1313
//===----------------------------------------------------------------------===//
14-
14+
//
15+
// LinuxMain.swift
16+
//
1517
import XCTest
1618

17-
import StatsdClientTests
19+
///
20+
/// NOTE: This file was generated by generate_linux_tests.rb
21+
///
22+
/// Do NOT edit this file directly as it will be regenerated automatically when needed.
23+
///
1824

19-
var tests = [XCTestCaseEntry]()
20-
tests += StatsdClientTests.__allTests()
25+
#if os(Linux) || os(FreeBSD)
26+
@testable import StatsdClientTests
2127

22-
XCTMain(tests)
28+
XCTMain([
29+
testCase(StatsdClientTests.allTests),
30+
])
31+
#endif
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the SwiftStatsdClient open source project
4+
//
5+
// Copyright (c) 2019 the SwiftStatsdClient project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of SwiftStatsdClient project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
//
15+
// StatsdClientTests+XCTest.swift
16+
//
17+
import XCTest
18+
19+
///
20+
/// NOTE: This file was generated by generate_linux_tests.rb
21+
///
22+
/// Do NOT edit this file directly as it will be regenerated automatically when needed.
23+
///
24+
25+
extension StatsdClientTests {
26+
static var allTests: [(String, (StatsdClientTests) -> () throws -> Void)] {
27+
return [
28+
("testCounter", testCounter),
29+
("testCounterOverflow", testCounterOverflow),
30+
("testTimer", testTimer),
31+
("testGaugeInteger", testGaugeInteger),
32+
("testGaugeDouble", testGaugeDouble),
33+
("testRecorderInteger", testRecorderInteger),
34+
("testRecorderDouble", testRecorderDouble),
35+
("testCouncurrency", testCouncurrency),
36+
]
37+
}
38+
}

Tests/StatsdClientTests/StatsdClientTests.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
//===----------------------------------------------------------------------===//
22
//
3-
// This source file is part of the StatsdClient open source project
3+
// This source file is part of the SwiftStatsdClient open source project
44
//
5-
// Copyright (c) 2019 the StatsdClient project authors
5+
// Copyright (c) 2019 the SwiftStatsdClient project authors
66
// Licensed under Apache License v2.0
77
//
88
// See LICENSE.txt for license information
9-
// See CONTRIBUTORS.txt for the list of StatsdClient project authors
9+
// See CONTRIBUTORS.txt for the list of SwiftStatsdClient project authors
1010
//
1111
// SPDX-License-Identifier: Apache-2.0
1212
//
@@ -295,9 +295,9 @@ class StatsdClientTests: XCTestCase {
295295
}
296296

297297
func connect() -> EventLoopFuture<Void> {
298-
let bootstrap = DatagramBootstrap(group: self.eventLoopGroup)
298+
let bootstrap = DatagramBootstrap(group: eventLoopGroup)
299299
.channelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
300-
.channelInitializer { channel in return channel.pipeline.addHandler(Aggregator(storage: self.store)) }
300+
.channelInitializer { channel in channel.pipeline.addHandler(Aggregator(storage: self.store)) }
301301

302302
return bootstrap.bind(host: self.host, port: self.port).map { _ in Void() }
303303
}
@@ -325,8 +325,8 @@ class StatsdClientTests: XCTestCase {
325325
self.storage = storage
326326
}
327327

328-
func channelRead(context: ChannelHandlerContext, data: NIOAny) {
329-
let envelope = self.unwrapInboundIn(data)
328+
func channelRead(context _: ChannelHandlerContext, data: NIOAny) {
329+
let envelope = unwrapInboundIn(data)
330330
let string = String(bytes: envelope.data.getBytes(at: envelope.data.readerIndex, length: envelope.data.readableBytes)!, encoding: .utf8)!
331331
self.storage(string)
332332
}

Tests/StatsdClientTests/XCTestManifests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
//===----------------------------------------------------------------------===//
22
//
3-
// This source file is part of the StatsdClient open source project
3+
// This source file is part of the SwiftStatsdClient open source project
44
//
5-
// Copyright (c) 2019 the StatsdClient project authors
5+
// Copyright (c) 2019 the SwiftStatsdClient project authors
66
// Licensed under Apache License v2.0
77
//
88
// See LICENSE.txt for license information
9-
// See CONTRIBUTORS.txt for the list of StatsdClient project authors
9+
// See CONTRIBUTORS.txt for the list of SwiftStatsdClient project authors
1010
//
1111
// SPDX-License-Identifier: Apache-2.0
1212
//

docker/Dockerfile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
ARG swift_version=5.0
2+
ARG ubuntu_version=bionic
3+
FROM swift:$swift_version-$ubuntu_version
4+
# needed to do again after FROM due to docker limitation
5+
ARG swift_version
6+
ARG ubuntu_version
7+
8+
# set as UTF-8
9+
RUN apt-get update && apt-get install -y locales locales-all
10+
ENV LC_ALL en_US.UTF-8
11+
ENV LANG en_US.UTF-8
12+
ENV LANGUAGE en_US.UTF-8
13+
14+
# dependencies
15+
RUN apt-get update && apt-get install -y wget
16+
RUN apt-get update && apt-get install -y lsof dnsutils netcat-openbsd net-tools # used by integration tests
17+
18+
# ruby and jazzy for docs generation
19+
RUN apt-get update && apt-get install -y ruby ruby-dev libsqlite3-dev
20+
RUN gem install jazzy --no-ri --no-rdoc
21+
22+
# tools
23+
RUN mkdir -p $HOME/.tools
24+
RUN echo 'export PATH="$HOME/.tools:$PATH"' >> $HOME/.profile
25+
26+
# script to allow mapping framepointers on linux (until part of the toolchain)
27+
RUN wget -q https://raw.githubusercontent.com/apple/swift/master/utils/symbolicate-linux-fatal -O $HOME/.tools/symbolicate-linux-fatal
28+
RUN chmod 755 $HOME/.tools/symbolicate-linux-fatal
29+
30+
# swiftformat (until part of the toolchain)
31+
32+
ARG swiftformat_version=0.40.11
33+
RUN git clone --branch $swiftformat_version --depth 1 https://github.com/nicklockwood/SwiftFormat $HOME/.tools/swift-format
34+
RUN cd $HOME/.tools/swift-format && swift build -c release
35+
RUN ln -s $HOME/.tools/swift-format/.build/release/swiftformat $HOME/.tools/swiftformat

0 commit comments

Comments
 (0)