From 477af99eab65345af429d80dc08d93faee987d8c Mon Sep 17 00:00:00 2001 From: Salar Rahmanian Date: Sat, 8 Feb 2025 20:14:50 -0800 Subject: [PATCH] Have a separate workflow for test with correct file paths --- ...ild-and-test.yml => build-and-release.yml} | 33 +++---------------- .github/workflows/test.yml | 30 +++++++++++++++++ Package.swift | 9 ++--- Tests/ParserTests.swift | 8 ++--- 4 files changed, 39 insertions(+), 41 deletions(-) rename .github/workflows/{build-and-test.yml => build-and-release.yml} (69%) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-release.yml similarity index 69% rename from .github/workflows/build-and-test.yml rename to .github/workflows/build-and-release.yml index a95036a..e41ccc2 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-release.yml @@ -1,36 +1,12 @@ -name: Build and Test +name: Build and Release Artifacts on: - push: - branches: - - main - pull_request: - branches: - - main release: - types: [created] + types: [published] jobs: - test: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Set up Swift - uses: swift-actions/setup-swift@v2 - with: - swift-version: '6.0' - - - name: Get swift version - run: swift --version - - - name: Run tests - run: swift test - build-macos: runs-on: macos-latest - if: github.event_name == 'release' strategy: matrix: arch: [x86_64, arm64] @@ -53,14 +29,13 @@ jobs: cp .build/apple/Products/Release/fishee artifacts/macos-${{ matrix.arch }}/ - name: Upload macOS artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: fishee-macos-${{ matrix.arch }}-${{ github.ref_name }} path: artifacts/macos-${{ matrix.arch }} build-linux: runs-on: ubuntu-latest - if: github.event_name == 'release' steps: - name: Checkout code uses: actions/checkout@v3 @@ -80,7 +55,7 @@ jobs: cp .build/release/fishee artifacts/linux/ - name: Upload Linux artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: fishee-linux-${{ github.ref_name }} path: artifacts/linux diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..e94eb4c --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,30 @@ +name: Run Tests + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + test: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [macos-latest, ubuntu-latest] + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Swift + uses: swift-actions/setup-swift@v2 + with: + swift-version: '6.0' + + - name: Get swift version + run: swift --version + + - name: Run tests + run: swift test diff --git a/Package.swift b/Package.swift index 88dcba6..8149129 100644 --- a/Package.swift +++ b/Package.swift @@ -10,17 +10,13 @@ let package = Package( ], dependencies: [ .package( - url: "https://github.com/apple/swift-argument-parser.git", .upToNextMajor(from: "1.5.0")), - .package(url: "https://github.com/duckdb/duckdb-swift", .upToNextMinor(from: .init(1, 1, 0))), + url: "https://github.com/apple/swift-argument-parser.git", .upToNextMajor(from: "1.5.0")) ], targets: [ - // Targets are the basic building blocks of a package, defining a module or a test suite. - // Targets can depend on other targets in this package and products from dependencies. .executableTarget( name: "Fishee", dependencies: [ - .product(name: "ArgumentParser", package: "swift-argument-parser"), - .product(name: "DuckDB", package: "duckdb-swift"), + .product(name: "ArgumentParser", package: "swift-argument-parser") ], path: "Sources" ), @@ -31,6 +27,7 @@ let package = Package( resources: [ .copy("Resources/fish_history_test.txt"), .copy("Resources/fish_history_test_2.txt"), + .process("TestPlan.xctestplan"), ] ), ] diff --git a/Tests/ParserTests.swift b/Tests/ParserTests.swift index a6d54e9..c9589f6 100644 --- a/Tests/ParserTests.swift +++ b/Tests/ParserTests.swift @@ -23,12 +23,8 @@ final class ParserTests { let fishHistoryFile = Bundle.module.path(forResource: "fish_history_test", ofType: "txt") let historyItem = FishHistoryEntry(cmd: "cd Projects/Fishee/", when: 1727545693, paths: ["Projects/Fishee/"]) let historyItem2 = FishHistoryEntry(cmd: "swift package tools-version", when: 1727545709, paths: []) - let filePathforWriteTest = FileManager.default.urls(for: .downloadsDirectory, in: .userDomainMask)[0].appendingPathComponent( - "myfile.txt" - ) - let filePathforFileBackupTest = FileManager.default.urls(for: .downloadsDirectory, in: .userDomainMask)[0].appendingPathComponent( - "myfile_copy.txt" - ) + let filePathforWriteTest = FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent("myfile.txt") + let filePathforFileBackupTest = FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent("myfile_copy.txt") deinit { if FileManager.default.fileExists(atPath: filePathforWriteTest.path) {