How to use XCode Cloud with multiple app versions?

I'm investigating converting our pipeline that uses Gitlab runners and Fastlane to XCode Cloud.

I think I got the basic workflow set up ok, but the problem comes in when trying to archive to a different version - we generally have the next release in our develop branch, the following release in a delta branch and/or feature branches, and sometimes switch to a far-future version to test things when we don't want a build on the current release to confuse our testing team.

With our current setup, we have a Fastlane lane that checks the version in our project, checks the latest build number for that version, and increments it, like so:

lane:checkAndIncrementBuildNumber do
    # Increment the build number
        localProjectVersion = get_version_number_from_plist(
          xcodeproj: PROJECT_NAME, 
          target: TARGET_NAME, 
          build_configuration_name: BUILD_CONFIGURATION,
          plist_build_setting_support: true)
        current_build_number = latest_testflight_build_number(api_key_path: API_KEY_PATH,version: localProjectVersion)
        increment_build_number(
          build_number: current_build_number + 1
        )
        incrementedBuildNumber = get_info_plist_value(path: INFO_PLIST_PATH, key: "CFBundleVersion")
        File.write(VERSION_NUMBER_FILE_NAME, localProjectVersion)
        File.write(BUILD_NUMBER_FILE_NAME, incrementedBuildNumber)
        File.write(VERSION_BUILD_FILE_NAME, localProjectVersion + " (#{incrementedBuildNumber})")
        File.write(IPA_FILE_NAME_FILE, IPA_FILE_NAME_START + localProjectVersion.tr(".","") + "b" + incrementedBuildNumber + ".ipa")
  end

Can I just call this lane or something like it in the ci_pre_xcodebuild script? Or is there a way to replicate this functionality without having to set up new workflows every time we switch releases?

How to use XCode Cloud with multiple app versions?
 
 
Q