Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Travis CIのBuild Matrixを活用して、Swift製ライブラリをLinux対応させる

Travis CIのBuild Matrixを活用して、Swift製ライブラリをLinux対応させる

「CI/CD Test Night #4」の発表資料です #cicd_test_night

Sho Ikeda

June 20, 2019
Tweet

More Decks by Sho Ikeda

Other Decks in Programming

Transcript

  1. Sho Ikeda / @ikesyo • ͍͚͠ΐʔʗ஑ా ᠳ • גࣜձࣾ͸ͯͳʢژ౎ΦϑΟεʣ •

    εϚʔτϑΥϯΞϓϦ։ൃ • iOS / Android / React Native • Swiftίϛολʔ • https://twitter.com/ikesyo • https://github.com/ikesyo
  2. Agenda • Swift Packages • Swift on Linux • ϩʔΧϧ։ൃ

    • Docker • CI؀ڥ • Travis CI • Build Matrix • swiftenv • ͦͷଞͷCIαʔϏε
  3. Swift Package Manager (SwiftPM) • The Package Manager for the

    Swift Programming Language • Bundled with Swift • Introduced in Swift 3 (2016) • ݱࡏ͸Swift 5ʢ2019೥ळʹSwift 5.1ʣ • https://github.com/apple/swift-package-manager
  4. // swift-tools-version:5.0 import PackageDescription let package = Package( name: "Himotoki",

    platforms: [ .macOS(.v10_10), .iOS(.v8), .tvOS(.v9), .watchOS(.v2) ], products: [ .library(name: "Himotoki", targets: ["Himotoki"]), ], targets: [ .target(name: "Himotoki", dependencies: [], path: "Sources"), .testTarget(name: "HimotokiTests", dependencies: ["Himotoki"]), ], swiftLanguageVersions: [.v5] )
  5. Swift Package Manager (SwiftPM) • Uses • [NEW!] iOS/macOS/tvOS/watchOS Apps

    (since Xcode 11) • CLI tools • Server-side Swift
  6. Swift on Linux • https://swift.org/about/#linux • Official: Ubuntu 18.04/16.04/14.04 •

    Community: Fedora 27, Debian 9.5 • ී௨ͷSwiftϓϩάϥϚʔ͸macOSͱXcodeͰ։ൃ͍ͯ͠Δ • Ͳ͏΍ͬͯLinuxͰϏϧυͯ͠ςετ͢Δʁ • ޓ׵ੑ͸Ͳ͏ͳͷʁ
  7. swift-docker • An Ubuntu 16.04 and Ubuntu 18.04 Docker image

    for Swift. • https://github.com/apple/swift-docker • https://hub.docker.com/_/swift/ • $ docker run -it -v `pwd`:/project swift bash • $ cd project; swift build
  8. ෳ਺όʔδϣϯͰςετ • ෳ਺όʔδϣϯαϙʔτɺޓ׵ੑͷ֬อ • $ docker run -it -v `pwd`:/project

    swift:5.0 bash • $ docker run -it -v `pwd`:/project swift:4.2 bash • $ docker run -it -v `pwd`:/project swift:4.1 bash • ...
  9. Travis CI • Build Matrix • https://docs.travis-ci.com/user/build-matrix/ • ෳ਺ͷδϣϒΛฒྻ࣮ߦ͢Δ •

    Linux͚ͩ͡Όͳͯ͘macOS΋࢖͑Δ • https://docs.travis-ci.com/user/reference/osx/ • macOSͱLinuxΛ·ͱΊͯςετͰ͖Δ • Always free for open source projects • https://travis-ci.com/plans • OSS͸ແྉͰLinux΋macOS΋࢖͑ΔʢmacOSͷಉ࣮࣌ߦ਺͸2·Ͱʣ • 1δϣϒ͋ͨΓͷϏϧυ࣌ؒͷ্ݶ͕50෼
  10. Travis CI • Build Matrix • https://docs.travis-ci.com/user/build-matrix/ • ෳ਺ͷδϣϒΛฒྻ࣮ߦ͢Δ •

    Linux͚ͩ͡Όͳͯ͘macOS΋࢖͑Δ • https://docs.travis-ci.com/user/reference/osx/ • macOSͱLinuxΛ·ͱΊͯςετͰ͖Δ • Always free for open source projects • https://travis-ci.com/plans • OSS͸ແྉͰLinux΋macOS΋࢖͑ΔʢmacOSͷಉ࣮࣌ߦ਺͸2·Ͱʣ • 1δϣϒ͋ͨΓͷϏϧυ࣌ؒͷ্ݶ͕50෼
  11. Build Matrix • 2*2*2ͷ8௨Γ rvm: - 2.5 - 2.2 gemfile:

    - gemfiles/Gemfile.rails-3.2.x - gemfiles/Gemfile.rails-3.0.x env: - ISOLATED=true - ISOLATED=false
  12. Build Matrix matrix: include: - rvm: 2.5 gemfile: gemfiles/Gemfile.rails-3.2.x env:

    ISOLATED=false - rvm: 2.5 gemfile: gemfiles/Gemfile.rails-3.2.x env: ISOLATED=true
  13. Build Matrix language: generic matrix: include: - &swiftpm_darwin name: SwiftPM

    / Darwin / Swift 4.2 os: osx osx_image: xcode10.1 script: swift test - <<: *swiftpm_darwin name: SwiftPM / Darwin / Swift 5.0 osx_image: xcode10.2 - &swiftpm_linux name: SwiftPM / Linux / Swift 4.2 os: linux sudo: required dist: trusty env: - SWIFT_VERSION=4.2.4 install: eval "$(curl -sL https://swiftenv.fuller.li/install.sh)" script: swift test - <<: *swiftpm_linux name: SwiftPM / Linux / Swift 5.0 env: - SWIFT_VERSION=5.0 - <<: *swiftpm_linux name: SwiftPM / Linux / Swift 5.1 Development env: - SWIFT_VERSION=5.1-DEVELOPMENT-SNAPSHOT-2019-05-28-a
  14. - &swiftpm_darwin name: SwiftPM / Darwin / Swift 4.2 os:

    osx osx_image: xcode10.1 script: swift test - <<: *swiftpm_darwin name: SwiftPM / Darwin / Swift 5.0 osx_image: xcode10.2
  15. - &swiftpm_linux name: SwiftPM / Linux / Swift 4.2 os:

    linux sudo: required dist: trusty env: - SWIFT_VERSION=4.2.4 install: eval "$(curl -sL https://swiftenv.fuller.li/install.sh)" script: swift test - <<: *swiftpm_linux name: SwiftPM / Linux / Swift 5.0 env: - SWIFT_VERSION=5.0 - <<: *swiftpm_linux name: SwiftPM / Linux / Swift 5.1 Development env: - SWIFT_VERSION=5.1-DEVELOPMENT-SNAPSHOT-2019-05-28-a
  16. swiftenv • https://github.com/kylef/swiftenv • Swift Version Manager • ͲͪΒ͔ͰόʔδϣϯΛࢦఆ •

    ϑΝΠϧ: .swift-version • ؀ڥม਺: SWIFT_VERSION • $ eval "$(curl -sL https://swiftenv.fuller.li/install.sh)" • swiftenvࣗମͱɺࢦఆ͞ΕͨSwiftͷόʔδϣϯΛΠϯετʔϧ • Travis CIͷδϣϒͰDockerΛ࢖͏ͷ͸໘౗ͳͷͰ͜Ε͕ศར • https://docs.travis-ci.com/user/docker/
  17. Bitrise • https://www.bitrise.io/ • OSS޲͚ͷແྉϓϥϯ͋Γ • https://blog.bitrise.io/free-developer-plan-features-for-open-source- projects-on-bitrise • ฒྻ࣮ߦෆՄ

    • Ϗϧυ࣌ؒ: 45෼·Ͱ • Ϗϧυճ਺: ແ੍ݶ • Linux/Android StackͰ͸࢖༻͢ΔDockerΠϝʔδΛࢦఆͰ͖Δ
  18. CircleCI • Workflows • https://circleci.com/docs/2.0/workflows-overview/ • Travis CIͷBuild MatrixͷΑ͏ʹॊೈͳฒྻ࣮ߦ͕Ͱ͖Δ •

    Linux: DockerϕʔεͳͷͰswiftenv͍Βͣ • ॊೈͳΩϟογϡ੍ޚ • https://circleci.com/docs/2.0/caching/