Fix support for Ubuntu 20.04, use GHA for SwiftLint (#134)

Resolves #114.

As support for SwiftLint in Danger seems a bit buggy (causing duplicate warning comments sometimes), this PR calls SwiftLint through a separate action that displays warnings only in the PR diff and hopefully in better way.

* Add support for Ubuntu 20.04

* Refine formatting

* Move SwiftLint to a separate GitHub Action

* Fix linker warnings

* Remove `danger.yml` and `Dangerfile.swift`

* Remove `--strict` argument from `swiftlint.yml`

* Update README.md
This commit is contained in:
Max Desiatov 2020-10-21 14:27:50 +01:00 committed by GitHub
parent d4c92c5e0e
commit 4635766c61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 58 additions and 44 deletions

View File

@ -1,23 +0,0 @@
# This is a basic workflow to help you get started with Actions
name: Danger
# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the main branch
on:
pull_request:
branches: [main]
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
danger-lint:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Danger Swift
uses: maxdesiatov/danger-swift@swiftlint-docker
if: github.event.pull_request.head.repo.full_name == github.repository
env:
GITHUB_TOKEN: ${{ secrets.PAT }}

View File

@ -75,3 +75,18 @@ jobs:
../.build/debug/carton bundle
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ubuntu20_04-swift5_3:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Build on Ubuntu 20.04 with Swift 5.3
run: |
swift build
./install_ubuntu_deps.sh
curl https://get.wasmer.io -sSfL | sh
source /home/runner/.wasmer/wasmer.sh
cd TestApp && ../.build/debug/carton test
../.build/debug/carton bundle

18
.github/workflows/swiftlint.yml vendored Normal file
View File

@ -0,0 +1,18 @@
name: SwiftLint
on:
pull_request:
paths:
- ".github/workflows/swiftlint.yml"
- ".swiftlint.yml"
- "**/*.swift"
jobs:
SwiftLint:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v1
- name: GitHub Action for SwiftLint with --strict
uses: norio-nomura/action-swiftlint@3.1.0
env:
DIFF_BASE: ${{ github.base_ref }}

View File

@ -1,9 +0,0 @@
import Danger
SwiftLint.lint(inline: true, configFile: ".swiftlint.yml", strict: true)
let danger = Danger()
print("Calling SwiftFormat...")
danger.utils.exec("swiftformat", arguments: ["."])

View File

@ -26,7 +26,7 @@ development workflow such as toolchain and SDK installations.
### Requirements
- macOS 10.15 and Xcode 11.4 or later.
- [Swift 5.2 or later](https://swift.org/download/) and Ubuntu 18.04 for Linux users.
- [Swift 5.2 or later](https://swift.org/download/) and Ubuntu 18.04 or 20.04 for Linux users.
### Installation

View File

@ -30,6 +30,7 @@ enum ToolchainError: Error, CustomStringConvertible {
case missingPackageManifest
case invalidVersion(version: String)
case invalidResponse(url: String, status: UInt)
case unsupportedOperatingSystem
var description: String {
switch self {
@ -56,6 +57,8 @@ enum ToolchainError: Error, CustomStringConvertible {
return "Invalid version \(version)"
case let .invalidResponse(url: url, status: status):
return "Response from \(url) had invalid status \(status) or didn't contain body"
case .unsupportedOperatingSystem:
return "This version of the operating system is not supported"
}
}
}

View File

@ -142,7 +142,22 @@ extension FileSystem {
#if os(macOS)
let platformSuffixes = ["osx", "catalina", "macos"]
#elseif os(Linux)
let platformSuffixes = ["linux", "ubuntu18.04"]
let releaseFile = AbsolutePath("/etc/lsb-release")
guard isFile(releaseFile) else {
throw ToolchainError.unsupportedOperatingSystem
}
let releaseData = try readFileContents(releaseFile).description
let ubuntuSuffix: String
if releaseData.contains("DISTRIB_RELEASE=18.04") {
ubuntuSuffix = "ubuntu18.04"
} else if releaseData.contains("DISTRIB_RELEASE=20.04") {
ubuntuSuffix = "ubuntu20.04"
} else {
throw ToolchainError.unsupportedOperatingSystem
}
let platformSuffixes = ["linux", ubuntuSuffix]
#endif
terminal.logLookup(
@ -181,16 +196,11 @@ extension FileSystem {
toolchainBinDir: binDir,
extraCCFlags: includeFlags,
extraSwiftcFlags: includeFlags + [
"-Xlinker",
"-lFoundation",
"-Xlinker",
"-lCoreFoundation",
"-Xlinker",
"-lBlocksRuntime",
"-Xlinker",
"-licui18n",
"-Xlinker",
"-luuid",
"-Xlinker", "-lFoundation",
"-Xlinker", "-lCoreFoundation",
"-Xlinker", "-lBlocksRuntime",
"-Xlinker", "-licui18n",
"-Xlinker", "-luuid",
]
)