0

我使用这个脚本在 travis 上安装 swiftlint:

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

如果在此脚本中需要,这不是始终更新它的最佳方式 - 是否可以始终指向最新发布的 pkg?

4

1 回答 1

0

您可以从 API 获取有关最新版本的信息:https ://api.github.com/repos/realm/SwiftLint/releases/latest

获取标签名称:

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

要获取pkg文件的下载 URL:

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

单行字的来源

于 2018-05-11T20:58:08.010 回答