How to link different versioning of dependencies for different pipelines?

I am trying to use SwiftPM and Swift Package Plugin for our project which has multi stages and pipelines, for example nightly, stable.

Currently, our project A uses an internal library called "MyModuleB" as dependency, and for different stages we want to use different branches of "MyModuleB".
nightly of Project A -> develop branch of MyModuleB
stable of Project B -> main branch of MyModuleB
like

dependencies: [
        .package(
            url: "https://git.my-company.com/my-module-b.git",  
            branch: "develop"                                                       // nightly version
            //.upToNextMajor(from: "3.1.0")),                               // release version
        ),

Right now, we switch the branches manually, but it is not effective.
How could we automatically adapt this by pipeline?
Is there any official approach doing this?

And is it possible easily to upgrade the version after each release of MyModuleB
like .upToNextMajor(from: "3.1.0") -> .upToNextMajor(from: "3.2.0")?

Thanks and best regards