Share
Embed
Transcript
26 slides
-
PETR PAVLIK ▸ Lead iOS developer at Hornet (Yes, we're
hiring) ▸ I like to play with Swift on Linux -
DANGER ▸ Danger runs during your CI process, and gives
teams the chance to automate common code review chores. ▸ She does this by leaving messages inside your PRs based on rules that you create with the Ruby scripting language. ▸ https://danger.systems -
GEMFILE source 'https://rubygems.org' gem 'cocoapods', '~> 1.0' gem 'danger', '~>
1.0' gem 'danger-swiftlint', '~> 0.0' -
DANGERFILE # Ensure a clean commits history if git.commits.any? {
|c| c.message =~ /^Merge branch/ } fail('Please rebase to get rid of the merge commits in this PR') end # Podfile has been updated podfile_updated = !git.modified_files.grep(/Podfile/).empty? # run SwiftLint swiftlint.lint_files inline_mode: true -
BUDDYBUILD_POSTBUILD.SH #!/bin/bash chruby 2.3.1 bundle install bundle exec danger --fail-on-errors=true
▸ Add a DANGER_GITHUB_API_TOKEN to your CI -
! ▸ Can it run on Linux? ▸ There is
an experimental Swift implementation -
GEOSWIFT do { let prague = try GeoCoordinate2D(latitude: 50.0880400, longitude:
14.4207600) let brno = try GeoCoordinate2D(latitude: 49.195060, longitude: 16.606837) let distancePragueBrnoInMeters = prague.distance(from: brno) print("\(distancePragueBrnoInMeters * 0.00062137) mi.") } catch { // Tried to create an instance of `GeoCoordinate2D` with invalid coordinates. } https://github.com/petrpavlik/GeoSwift -
TRAVIS.YML os: - linux language: generic sudo: required dist: trusty
before_install: - sudo apt-get -qq update - sudo apt-get install -y clang libblocksruntime0 libcurl4-openssl-dev - sudo curl https://swift.org/builds/...tu14.04.tar.gz \ | sudo tar xz --directory / --strip-components=1 install: # ... script: # ... -
TRAVIS.YML os: # ... before_install: # ... install: - sudo
chmod -R a+rwx /usr/ - git clone https://github.com/realm/SwiftLint.git - cd SwiftLint - rm .swift-version - swift build -c release --static-swift-stdlib - mv .build/x86_64-unknown-linux/release/swiftlint /usr/local/bin/ - cd .. - rm -rf SwiftLint - swift build script: # ... -
TRAVIS.YML os: # ... before_install: # ... install: # ...
script: - swift test - export LINUX_SOURCEKIT_LIB_PATH=$HOME/usr/lib - bundle install - bundle exec danger # Run Danger -
DANGERFILE.SWIFT // Dangerfile.swift import Danger import DangerSwiftLint // package: https://github.com/ashfurrow/danger-swiftlint.git
var x = 5; // to generate a linter warning SwiftLint.lint() message("It works!") -
os: - linux language: generic sudo: required dist: trusty before_install:
- sudo apt-get -qq update - sudo apt-get install -y clang libblocksruntime0 libcurl4-openssl-dev - sudo curl https://swift... # download swift # bug fixes - sudo update-alternatives --install /usr/bin/ld ld /usr/bin/ld.gold 9 - sudo update-alternatives --set ld /usr/bin/ld.gold install: - sudo chmod -R a+rwx /usr/ - node -v - npm install -g danger # compile swiftlint... - git clone https://github.com/petrpavlik/danger-swift.git - cd danger-swift - make install - cd .. - swift build script: - swift test - export LINUX_SOURCEKIT_LIB_PATH=$HOME/usr/lib # - swiftlint lint --quiet --path "danger/Dangerfile.swift" --reporter json # test swiftlint - danger process danger-swift # Run Danger -
MAKEFILE TOOL_NAME = danger-swift # Get this from the package.swift
VERSION = 0.3.3 PREFIX = /usr/local INSTALL_PATH = $(PREFIX)/bin/$(TOOL_NAME) BUILD_PATH = .build/release/$(TOOL_NAME) LIB_INSTALL_PATH = $(PREFIX)/lib/danger TAR_FILENAME = $(TOOL_NAME)-$(VERSION).tar.gz SWIFT_LIB_FILES = .build/release/libDanger.so .build/release/Danger.swiftdoc .build/release/Danger.swiftmodule install: build mkdir -p $(PREFIX)/bin mkdir -p $(PREFIX)/lib/danger cp -f $(BUILD_PATH) $(INSTALL_PATH) cp -f $(SWIFT_LIB_FILES) $(LIB_INSTALL_PATH) build: swift package clean swift build --disable-sandbox -c release --static-swift-stdlib uninstall: rm -f $(INSTALL_PATH) get_sha: wget https://github.com/danger/$(TOOL_NAME)/archive/$(VERSION).tar.gz -O $(TAR_FILENAME) shasum -a 256 $(TAR_FILENAME) rm $(TAR_FILENAME) -
MAKEFILE ▸ Build and copy executables and libraries to standard
linux paths ▸ I had to fork the repo and slightly modify filenames and build flags for linux ▸ Will submit a PR to the original repo -
CONCLUSION ▸ I made it work ▸ I find it
very useful for server-side Swift projects - checks for try! and such ▸ The Swift implementation is more of a toy project ▸ Being able to install SwiftLint using apt-get would be much appreciated