0

I use this script to install swiftlint on travis:

set -e

SWIFTLINT_PKG_PATH="/tmp/SwiftLint.pkg"
SWIFTLINT_PKG_URL="https://github.com/realm/SwiftLint/releases/download/0.25.1/SwiftLint.pkg"
wget --output-document=$SWIFTLINT_PKG_PATH $SWIFTLINT_PKG_URL

if [ -f $SWIFTLINT_PKG_PATH ]; then
  echo "SwiftLint package exists! Installing it..."
  sudo installer -pkg $SWIFTLINT_PKG_PATH -target /
else
  echo "SwiftLint package doesn't exist. Compiling from source..." &&
  git clone https://github.com/realm/SwiftLint.git /tmp/SwiftLint &&
  cd /tmp/SwiftLint &&
  git submodule update --init --recursive &&
  sudo make install
fi

It's not the best way to always update it if needed in this script - is it possible to point to always the latest released pkg?

Vladyslav Zavalykhatko
  • 15,202
  • 8
  • 65
  • 100

1 Answers1

0

You can get info about last release from API: https://api.github.com/repos/realm/SwiftLint/releases/latest

To get tag name:

curl --silent "https://api.github.com/repos/realm/SwiftLint/releases/latest" | 
    grep -Po '"tag_name": "\K.*?(?=")'

To get download URL for pkg file:

curl --silent "https://api.github.com/repos/realm/SwiftLint/releases/latest" |
    grep -Po '"browser_download_url": "\K.*?.pkg(?=")'

Source of one-liners.

rob006
  • 21,383
  • 5
  • 53
  • 74