I'm trying out Swift for backend development (no use of Xcode or Apple platforms).
In my CI/CD workflow, which uses GitHub Actions, I have implemented a step to cache the build and use it accordingly.
- name: Set up Swift ${{ env.SWIFT_VERSION }}
uses: fwal/setup-swift@v1
with:
swift-version: ${{ env.SWIFT_VERSION }}
- name: Load Swift Build cache
uses: actions/cache@v3
id: cached-build
with:
path: .build
key: swift-${{ runner.os }}-${{ env.SWIFT_VERSION }}-${{ hashFiles('**/Package.resolved') }}
restore-keys: |
swift-${{ runner.os }}-${{ env.SWIFT_VERSION }}-
swift-${{ runner.os }}-
swift-
- name: Build Application
if: steps.cached-build.outputs.cache-hit != 'true'
id: build
run: swift build
- name: Run tests
id: tests
run: swift test
While the workflow runs, GitHub retrieves the cached build without any problem. The problem is that the test
step now starts by building the entire application and all of its dependencies and only then starts to run the TestCases (written with XCTest).
Before I added the caching logic, the workflow would build the application as usual, and then the test
step would start right away with the TestCases - the test
step took ~10sec, and now it takes ~2:30min.
Help is very much appreciated why this happens.