How to call fastlane scan with the --clean parameter using CircleCI?

We have an Xcode 11 iOS project and we added some swift packages to the project as dependencies. This is causing some issue with CircleCI (builds fine locally). We don’t have a fastlane configuration file, just the .circleci/config.yml.

First issue is Xcode 11 issue that it has to use https dependency url scheme. This required overriding the forced switch to ssh+git that circleci does via:

      - run:
          name: Override CircleCI GitHub URL rewriting
          command: git config --global --unset url."ssh://".insteadOf

and then changing all our package dependencies to use https urls (pain, but it works). However, then there are issues with the swift package cache (possibly from the previous failed attempts).

I had hoped to add --clean to the fastlane command, as in:

      - run:
          name: Build and run tests
          command: fastlane scan --clean
            SCAN_DEVICE: iPhone 11 (13.0)
            SCAN_SCHEME:  CircleCIScheme

xcodebuild: error: Could not resolve package dependencies:
An unknown error occurred. ‘/Users/distiller/Library/Developer/Xcode/DerivedData/TestProject-bivykjtderujuveypcdernfqexxy/SourcePackages/repositories/CwlCatchException-463e8527’ exists and is not an empty directory (-4)

I get the same thing if I try it without the dashes as command: fastlane scan clean

I can get the build to work (at least most of the time) if instead of adding --clean to the fastlane scan command I instead add an xcodebuild and clean run command first:

      - run: 
          name: xcode clean (fixes stale package cache)
          command: xcodebuild -scheme CircleCIScheme -project ./TestProject.xcodeproj clean

seems to work, doing this first:

#!/bin/bash -eo pipefail
xcodebuild -scheme CircleCIScheme -project ./TestProject.xcodeproj clean
^D^DResolve Package Graph




Checking out at 2.0.0-beta.1


Checking out at 2.0.0-beta.3

Resolved source packages:
CwlCatchException: @ 2.0.0-beta.1
CwlPreconditionTesting: @ 2.0.0-beta.3

note: Using new build system


but that seems wrong. It seems like I should be able to pass clean to fastlane and have it do the clean and package stuff automatically.

Suggestions? TIA

I am facing the same issue. Did you get solution to how to clean the build data