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

Danger feat. SwiftLint on Linux

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers. →

Danger feat. SwiftLint on Linux

Avatar for Petr Pavlik

Petr Pavlik

March 07, 2018

More Decks by Petr Pavlik

Other Decks in Programming

Transcript

  1. PETR PAVLIK ▸ Lead iOS developer at Hornet (Yes, we're

    hiring) ▸ I like to play with Swift on Linux
  2. 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
  3. 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
  4. !

  5. ! ▸ Can it run on Linux? ▸ There is

    an experimental Swift implementation
  6. 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
  7. 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: # ...
  8. 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: # ...
  9. TRAVIS.YML os: # ... before_install: # ... install: # ...

    script: - swift test - export LINUX_SOURCEKIT_LIB_PATH=$HOME/usr/lib - bundle install - bundle exec danger # Run Danger
  10. 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
  11. 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)
  12. 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
  13. 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