Skip to content

Commit

Permalink
Merge branch 'master' into support_mannequin_user_type
Browse files Browse the repository at this point in the history
  • Loading branch information
f-meloni authored Jan 22, 2025
2 parents 34f8d71 + e035543 commit ce18ad6
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 118 deletions.
141 changes: 40 additions & 101 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,24 @@ concurrency:
cancel-in-progress: true

jobs:
test-on-macos-13:
name: Test on macOS 13
runs-on: macOS-13
test-on-macos:
name: Test on macOS
strategy:
fail-fast: false
matrix:
xcode: ["14.3.1"]
include:
- runner: "macos-13"
xcode: "14.3.1"
- runner: "macos-14"
xcode: "15.4"
- runner: "macos-15"
xcode: "16.1"
runs-on: ${{ matrix.runner }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Cache dependencies
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: |
.build/artifacts
Expand All @@ -50,57 +56,22 @@ jobs:
if: ${{ github.event_name == 'pull_request' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
test-on-macos-14:
name: Test on macOS 14
runs-on: macOS-14
strategy:
fail-fast: false
matrix:
xcode: ["15.4", "16.0"]
steps:
- uses: actions/checkout@v2

- name: Cache dependencies
uses: actions/cache@v2
with:
path: |
.build/artifacts
.build/checkouts
.build/repositories
key: ${{ runner.os }}-dependencies-${{ matrix.xcode }}-${{ hashFiles('**/Package.resolved') }}
restore-keys: |
${{ runner.os }}-dependencies-${{ matrix.xcode }}-${{ hashFiles('**/Package.resolved') }}
${{ runner.os }}-dependencies-${{ matrix.xcode }}-
- name: Select Xcode
run: |
xcodebuild -version
ls -nt /Applications/ | grep "Xcode*"
sudo xcode-select -switch /Applications/Xcode_${{ matrix.xcode }}.app
xcodebuild -version
- name: Install danger-js
run: brew install danger/tap/danger-js

- run: swift test

- run: swift run danger-swift ci --verbose --failOnErrors
if: ${{ github.event_name == 'pull_request' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

test-dependencies-resolver:
name: Test dependencies resolver
runs-on: macOS-14
strategy:
fail-fast: false
matrix:
xcode: ["15.4", "16.0"]
include:
- runner: "macos-14"
xcode: "15.4"
- runner: "macos-15"
xcode: "16.1"
runs-on: ${{ matrix.runner }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Cache dependencies
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: |
.build/artifacts
Expand Down Expand Up @@ -138,11 +109,11 @@ jobs:
matrix:
swift: ["5.9", "5.10", "6.0"]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v4
- uses: actions/setup-node@v4

- name: Cache dependencies
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: |
.build/artifacts
Expand All @@ -169,18 +140,24 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

test-without-spm-on-macos-13:
name: Test without SPM on macOS 13
runs-on: macOS-13
test-without-spm-on-macos:
name: Test without SPM on macOS
strategy:
fail-fast: false
matrix:
xcode: ["14.3.1"]
include:
- runner: "macos-13"
xcode: "14.3.1"
- runner: "macos-14"
xcode: "15.4"
- runner: "macos-15"
xcode: "16.1"
runs-on: ${{ matrix.runner }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Cache dependencies
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: |
.build/artifacts
Expand All @@ -202,47 +179,9 @@ jobs:
run: brew install danger/tap/danger-js

- run: make install

- run: rm -rf .build && rm -rf Package.swift

- run: danger-swift ci --verbose --failOnErrors
if: ${{ github.event_name == 'pull_request' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

test-without-spm-on-macos-14:
name: Test without SPM on macOS 14
runs-on: macOS-14
strategy:
fail-fast: false
matrix:
xcode: ["15.4", "16.0"]
steps:
- uses: actions/checkout@v2

- name: Cache dependencies
uses: actions/cache@v2
with:
path: |
.build/artifacts
.build/checkouts
.build/repositories
key: ${{ runner.os }}-without-spm-package-${{ matrix.xcode }}-${{ hashFiles('**/Package.resolved') }}
restore-keys: |
${{ runner.os }}-without-spm-package-${{ matrix.xcode }}-${{ hashFiles('**/Package.resolved') }}
${{ runner.os }}-without-spm-package-${{ matrix.xcode }}-
- name: Select Xcode
run: |
xcodebuild -version
ls -nt /Applications/ | grep "Xcode*"
sudo xcode-select -switch /Applications/Xcode_${{ matrix.xcode }}.app
xcodebuild -version
- name: Install danger-js
run: brew install danger/tap/danger-js

if: ${{ matrix.runner == 'macos-13' }}
- run: make install PREFIX='/opt/homebrew'
if: ${{ matrix.runner != 'macos-13' }}

- run: rm -rf .build && rm -rf Package.swift

Expand All @@ -259,11 +198,11 @@ jobs:
matrix:
swift: ["5.9", "5.10", "6.0"]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v4
- uses: actions/setup-node@v4

- name: Cache dependencies
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: |
.build/artifacts
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
## Master

- Support user type mannequin on for GitHub [@f-meloni][] - [#638](https://github.com/danger/swift/pull/638)
- Add Android support [@marcprux][] - [#635](https://github.com/danger/swift/pull/635)

## 3.20.2

Expand Down
4 changes: 3 additions & 1 deletion Sources/Danger/Danger.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Foundation

#if os(Linux)
#if canImport(Glibc)
import Glibc
#elseif canImport(Android)
import Android
#else
import Darwin.C
#endif
Expand Down
26 changes: 16 additions & 10 deletions Sources/DangerShellExecutor/ShellExecutor.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif

public enum SpawnError: Error {
case commandFailed(command: String, exitCode: Int32, stdout: String, stderr: String)
Expand Down Expand Up @@ -62,16 +65,19 @@ public struct ShellExecutor: ShellExecuting {
with: arguments,
environmentVariables: environmentVariables,
outputFile: outputFile)
do {
let pipe = Pipe()
task.standardOutput = pipe
try task.run()

let pipe = Pipe()
task.standardOutput = pipe
task.launch()
let data = pipe.fileHandleForReading.readDataToEndOfFile()

let data = pipe.fileHandleForReading.readDataToEndOfFile()
task.waitUntilExit()

task.waitUntilExit()

return String(data: data, encoding: .utf8)!.trimmingCharacters(in: .whitespacesAndNewlines)
return String(data: data, encoding: .utf8)!.trimmingCharacters(in: .whitespacesAndNewlines)
} catch {
return error.localizedDescription
}
}

// Similar to above, but can throw, and throws with most of
Expand All @@ -90,7 +96,7 @@ public struct ShellExecutor: ShellExecuting {
task.standardOutput = stdout
let stderr = Pipe()
task.standardError = stderr
task.launch()
try task.run()

// Pull out the STDOUT as a string because we'll need that regardless
let stdoutData = stdout.fileHandleForReading.readDataToEndOfFile()
Expand Down Expand Up @@ -131,10 +137,10 @@ public struct ShellExecutor: ShellExecuting {
let script = "\(command) \(arguments.joined(separator: " "))" + scriptOutputFile

let task = Process()
task.launchPath = "/bin/sh"
task.executableURL = URL(fileURLWithPath: "/bin/sh")
task.arguments = ["-c", script]
task.environment = mergeEnvs(localEnv: environmentVariables, processEnv: ProcessInfo.processInfo.environment)
task.currentDirectoryPath = FileManager.default.currentDirectoryPath
task.currentDirectoryURL = URL(fileURLWithPath: FileManager.default.currentDirectoryPath)
return task
}

Expand Down
9 changes: 6 additions & 3 deletions Sources/Runner/Commands/RunDangerJS.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import Foundation
import Logger
import RunnerLib
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif

func runDangerJSCommandToRunDangerSwift(_ command: DangerCommand, logger: Logger) throws -> Int32 {
guard let dangerJS = try? getDangerCommandPath(logger: logger) else {
Expand All @@ -22,7 +25,7 @@ func runDangerJSCommandToRunDangerSwift(_ command: DangerCommand, logger: Logger

let proc = Process()
proc.environment = ProcessInfo.processInfo.environment
proc.launchPath = dangerJS
proc.executableURL = URL(fileURLWithPath: dangerJS)

let dangerOptionsIndexes = DangerSwiftOption.allCases
.compactMap { option -> (DangerSwiftOption, Int)? in
Expand Down Expand Up @@ -62,8 +65,8 @@ func runDangerJSCommandToRunDangerSwift(_ command: DangerCommand, logger: Logger
proc.standardOutput = standardOutput
proc.standardError = standardOutput

logger.debug("Running: \(proc.launchPath!) \(proc.arguments!.joined(separator: " ")) ")
proc.launch()
logger.debug("Running: \(proc.executableURL!) \(proc.arguments!.joined(separator: " ")) ")
try proc.run()
proc.waitUntilExit()

return proc.terminationStatus
Expand Down
9 changes: 6 additions & 3 deletions Sources/Runner/Commands/Runner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import DangerShellExecutor
import Foundation
import Logger
import RunnerLib
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif

// swiftlint:disable:next function_body_length
func runDanger(version dangerSwiftVersion: String, logger: Logger) throws {
Expand Down Expand Up @@ -152,19 +155,19 @@ func runDanger(version dangerSwiftVersion: String, logger: Logger) throws {

// Create a process to eval the Swift file
let proc = Process()
proc.launchPath = swiftC
proc.executableURL = URL(fileURLWithPath: swiftC)
proc.arguments = args
let standardOutput = FileHandle.standardOutput
if let cwdOptionIndex = CommandLine.arguments.firstIndex(of: DangeSwiftRunnerOption.cwd.rawValue),
(cwdOptionIndex + 1) < CommandLine.arguments.count,
let directoryURL = URL(string: CommandLine.arguments[cwdOptionIndex + 1])
{
proc.currentDirectoryPath = directoryURL.absoluteString
proc.currentDirectoryURL = directoryURL
}
proc.standardOutput = standardOutput
proc.standardError = standardOutput

proc.launch()
try proc.run()
proc.waitUntilExit()

logger.debug("Completed evaluation")
Expand Down

0 comments on commit ce18ad6

Please sign in to comment.