Slide 1

Slide 1 text

DANGER FEAT. SWIFTLINT

Slide 2

Slide 2 text

PETR PAVLIK ▸ Lead iOS developer at Hornet (Yes, we're hiring) ▸ I like to play with Swift on Linux

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

GEMFILE source 'https://rubygems.org' gem 'cocoapods', '~> 1.0' gem 'danger', '~> 1.0' gem 'danger-swiftlint', '~> 0.0'

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

THAT'S IT!

Slide 9

Slide 9 text

!

Slide 10

Slide 10 text

! ▸ Can it run on Linux? ▸ There is an experimental Swift implementation

Slide 11

Slide 11 text

CAN IT RUN ON LINUX?

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

GEMFILE source 'https://rubygems.org' gem 'danger-swiftlint', '~> 0.0'

Slide 14

Slide 14 text

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: # ...

Slide 15

Slide 15 text

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: # ...

Slide 16

Slide 16 text

TRAVIS.YML os: # ... before_install: # ... install: # ... script: - swift test - export LINUX_SOURCEKIT_LIB_PATH=$HOME/usr/lib - bundle install - bundle exec danger # Run Danger

Slide 17

Slide 17 text

DANGERFILE message("Hello, this worked") swiftlint.binary_path = '/usr/local/bin/swiftlint' swiftlint.lint_files inline_mode: true

Slide 18

Slide 18 text

#WINNING

Slide 19

Slide 19 text

SWIFT IMPLEMENTATION ▸ https://github.com/danger/danger-swift

Slide 20

Slide 20 text

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!")

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

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)

Slide 23

Slide 23 text

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

Slide 24

Slide 24 text

#WINNING

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

THANKS! @PTRPAVLIK THX TO HORNET FOR SPONSORING THIS MEETUP