Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged Makefile CI branch into main #413

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
11 changes: 11 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ jobs:
${FLUENTFLAGS} ${LEAFFLAGS}
- name: Test new project
run: swift test --package-path /tmp/toolbox-test

testMakeFile:
runs-on: ubuntu-latest
steps:
- name: Check out toolbox
uses: actions/checkout@v3
- name: TestMakefile
run: |
make install
make uninstall
make clean

integration-macos:
strategy:
Expand Down
44 changes: 29 additions & 15 deletions scripts/build.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,44 @@ import Foundation
try build()

func build() throws {
try withVersion(in: "Sources/VaporToolbox/Version.swift", as: currentVersion()) {
try foregroundShell(
"swift", "build",
"--disable-sandbox",
"--configuration", "release",
"-Xswiftc", "-cross-module-optimization"
)
do {
try withVersion(in: "Sources/VaporToolbox/Version.swift", as: currentVersion()) {
do {
try foregroundShell(
"swift", "build",
"--disable-sandbox",
"--configuration", "release",
"-Xswiftc", "-cross-module-optimization"
)
} catch {
print("foregroundShell failed.")
}
}
} catch {
print("withVerison failed.")
}
}

func withVersion(in file: String, as version: String, _ closure: () throws -> ()) throws {
let fileURL = URL(fileURLWithPath: file)
let originalFileContents = try String(contentsOf: fileURL, encoding: .utf8)
// set version
try originalFileContents
.replacingOccurrences(of: "nil", with: "\"\(version)\"")
.write(to: fileURL, atomically: true, encoding: .utf8)
defer {
// undo set version
try! originalFileContents
do {
try originalFileContents
.replacingOccurrences(of: "nil", with: "\"\(version)\"")
.write(to: fileURL, atomically: true, encoding: .utf8)

defer {
// undo set version
try! originalFileContents
.write(to: fileURL, atomically: true, encoding: .utf8)
}
// run closure
try closure()
} catch {
print("originalFileContents replacing occurences failed.", error.localizedDescription)
throw error
}
// run closure
try closure()
}

func currentVersion() throws -> String {
Expand Down
Loading