Skip to content

Add input to disable Swift Package updates #374

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,9 @@ Build a development IPA with custom xcconfig file path:
| --- | --- | --- | --- |
| `project_path` | Xcode Project (`.xcodeproj`) or Workspace (`.xcworkspace`) path. The input value sets xcodebuild's `-project` or `-workspace` option. | required | `$BITRISE_PROJECT_PATH` |
| `scheme` | Xcode Scheme name. The input value sets xcodebuild's `-scheme` option. | required | `$BITRISE_SCHEME` |
| `distribution_method` | Describes how Xcode should export the archive. | required | `development` |
| `distribution_method` | Describes how Xcode should export the archive. The input value sets the method in the export options plist content. From Xcode 15.3 onwards, updated methods are used: - `debugging`, when `development` is selected - `app-store-connect`, when `app-store` is selected - `release-testing`, when `ad-hoc` is selected - `enterprise` is unchanged | required | `development` |
| `configuration` | Xcode Build Configuration. If not specified, the default Build Configuration will be used. The input value sets xcodebuild's `-configuration` option. | | |
| `lock_swift_packages` | If this input is set, the Step will disable Swift Package Manager automatic resolution. When enabled, runs the following: ``` defaults write com.apple.dt.Xcode IDEPackageOnlyUseVersionsFromResolvedFile -bool YES defaults write com.apple.dt.Xcode IDEDisableAutomaticPackageResolution -bool YES ``` | required | `no` |
| `xcconfig_content` | Build settings to override the project's build settings, using xcodebuild's `-xcconfig` option. You can't define `-xcconfig` option in `Additional options for the xcodebuild command` if this input is set. If empty, no setting is changed. When set it can be either: 1. Existing `.xcconfig` file path. Example: `./ios-sample/ios-sample/Configurations/Dev.xcconfig` 2. The contents of a newly created temporary `.xcconfig` file. (This is the default.) Build settings must be separated by newline character (`\n`). Example: ``` COMPILER_INDEX_STORE_ENABLE = NO ONLY_ACTIVE_ARCH[config=Debug][sdk=*][arch=*] = YES ``` | | `COMPILER_INDEX_STORE_ENABLE = NO` |
| `perform_clean_action` | If this input is set, `clean` xcodebuild action will be performed besides the `archive` action. | required | `no` |
| `xcodebuild_options` | Additional options to be added to the executed xcodebuild command. Prefer using `Build settings (xcconfig)` input for specifying `-xcconfig` option. You can't use both. `-destination` is set automatically, unless specified explicitely. | | |
Expand Down
11 changes: 7 additions & 4 deletions e2e/bitrise.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ workflows:
# - BITRISE_SCHEME: World
# - CODE_SIGNING_METHOD: api-key
# - MIN_DAYS_PROFILE_VALID: 0
# - FORCE_CODE_SIGN_IDENTITY: "iPhone Developer: Tooling Bot Bitrise"
# - FORCE_CODE_SIGN_IDENTITY: "Apple Development: Tooling Bot Bitrise"
# - TEAM_ID: 72SA8V3WYL
# - FORCE_PROV_PROFILE_SPECIFIER: ""
# - IPA_EXPORT_METHOD: development
Expand Down Expand Up @@ -102,6 +102,7 @@ workflows:
inputs:
- project_path: ./_tmp/ios-simple-objc/ios-simple-objc.xcodeproj
- scheme: ios-simple-objc
- lock_swift_packages: "yes"
- automatic_code_signing: api-key
- certificate_url_list: $BITFALL_APPLE_IOS_CERTIFICATE_NOPASSPHRASE_URL
- passphrase_list: ""
Expand Down Expand Up @@ -161,9 +162,10 @@ workflows:
- project_path: ./_tmp/$BITRISE_PROJECT_PATH
- scheme: $BITRISE_SCHEME
- automatic_code_signing: $CODE_SIGNING_METHOD
- lock_swift_packages: "yes"
- xcconfig_content: |
COMPILER_INDEX_STORE_ENABLE = NO
CODE_SIGN_IDENTITY = iPhone Developer: Tooling Bot Bitrise
CODE_SIGN_IDENTITY = Apple Development: Tooling Bot Bitrise
- distribution_method: $IPA_EXPORT_METHOD
- icloud_container_environment: $IPA_EXPORT_ICLOUD_CONTAINER_ENVIRONMENT
- export_development_team: $TEAM_ID
Expand Down Expand Up @@ -191,7 +193,7 @@ workflows:
- CODE_SIGNING_METHOD: api-key
- XCCONFIG_CONTENT: |
COMPILER_INDEX_STORE_ENABLE = NO
CODE_SIGN_IDENTITY = iPhone Developer: Tooling Bot Bitrise
CODE_SIGN_IDENTITY = Apple Development: Tooling Bot Bitrise
- MIN_DAYS_PROFILE_VALID: 0
- IPA_EXPORT_METHOD: development
- LOG_FORMATTER: xcodebuild
Expand Down Expand Up @@ -444,7 +446,7 @@ workflows:
- BITRISE_SCHEME: Catalyst Sample
- CODE_SIGNING_METHOD: api-key
- MIN_DAYS_PROFILE_VALID: 0
- FORCE_CODE_SIGN_IDENTITY: "iPhone Developer: Tooling Bot Bitrise"
- FORCE_CODE_SIGN_IDENTITY: "Apple Development: Tooling Bot Bitrise"
- TEAM_ID: 72SA8V3WYL
- FORCE_PROV_PROFILE_SPECIFIER: ""
- IPA_EXPORT_METHOD: development
Expand Down Expand Up @@ -484,6 +486,7 @@ workflows:
inputs:
- project_path: ./_tmp/$BITRISE_PROJECT_PATH
- scheme: $BITRISE_SCHEME
- lock_swift_packages: "yes"
- automatic_code_signing: $CODE_SIGNING_METHOD
- min_profile_validity: $MIN_DAYS_PROFILE_VALID
- certificate_url_list: $BITFALL_APPLE_APPLE_CERTIFICATE_URL_LIST|$BITFALL_APPLE_IOS_CERTIFICATE_URL_LIST
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/bitrise-steplib/steps-xcode-archive

go 1.22
go 1.23.0

toolchain go1.23.5

Expand All @@ -9,7 +9,7 @@ require (
github.com/bitrise-io/go-utils v1.0.14
github.com/bitrise-io/go-utils/v2 v2.0.0-alpha.23
github.com/bitrise-io/go-xcode v1.3.0
github.com/bitrise-io/go-xcode/v2 v2.0.0-alpha.55
github.com/bitrise-io/go-xcode/v2 v2.0.0-alpha.56
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
github.com/stretchr/testify v1.10.0
gopkg.in/yaml.v3 v3.0.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ github.com/bitrise-io/go-utils/v2 v2.0.0-alpha.23 h1:Dfh4nyZPuEtilBisidejqxBrkx9
github.com/bitrise-io/go-utils/v2 v2.0.0-alpha.23/go.mod h1:3XUplo0dOWc3DqT2XA2SeHToDSg7+j1y1HTHibT2H68=
github.com/bitrise-io/go-xcode v1.3.0 h1:QB8Vyr2oZQro/ocs9DJai80rlYL1hU1kwjHqdGslFLo=
github.com/bitrise-io/go-xcode v1.3.0/go.mod h1:9OwsvrhZ4A2JxHVoEY7CPcABAKA+OE7FQqFfBfvbFuY=
github.com/bitrise-io/go-xcode/v2 v2.0.0-alpha.55 h1:hLLVWstKv0KZZexCWE9so1mDB4MnDZK2TrX5jz2AYpI=
github.com/bitrise-io/go-xcode/v2 v2.0.0-alpha.55/go.mod h1:T4rhWQljdgH5As4Dq/RQWuazdScY0YB7uZAMuBUnxeY=
github.com/bitrise-io/go-xcode/v2 v2.0.0-alpha.56 h1:JSwOStu6HCkT6b7icTQ3x/0OBNPQ8mD7Q6vQt2hG7fg=
github.com/bitrise-io/go-xcode/v2 v2.0.0-alpha.56/go.mod h1:zoLzT5fJE8V2SeYq0D0Z+ZN2FAzERjV3uiqDg5H8Bug=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand Down
10 changes: 7 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/bitrise-io/go-utils/v2/log"
"github.com/bitrise-io/go-utils/v2/pathutil"
"github.com/bitrise-io/go-xcode/v2/xcodecommand"
"github.com/bitrise-io/go-xcode/v2/xcodeversion"
"github.com/bitrise-steplib/steps-xcode-archive/step"
)

Expand Down Expand Up @@ -58,11 +59,11 @@ func run() int {
func createConfigParser(logger log.Logger) step.XcodebuildArchiveConfigParser {
envRepository := env.NewRepository()
inputParser := stepconf.NewInputParser(envRepository)
xcodeVersionProvider := step.NewXcodebuildXcodeVersionProvider()
fileManager := fileutil.NewFileManager()
cmdFactory := command.NewFactory(envRepository)
xcodeVersionReader := xcodeversion.NewXcodeVersionProvider(cmdFactory)

return step.NewXcodeArchiveConfigParser(inputParser, xcodeVersionProvider, fileManager, cmdFactory, logger)
return step.NewXcodeArchiveConfigParser(inputParser, xcodeVersionReader, fileManager, cmdFactory, logger)
}

func createXcodebuildArchiver(logger log.Logger, logFormatter string) (step.XcodebuildArchiver, error) {
Expand All @@ -72,6 +73,7 @@ func createXcodebuildArchiver(logger log.Logger, logFormatter string) (step.Xcod
pathModifier := pathutil.NewPathModifier()
fileManager := fileutil.NewFileManager()
cmdFactory := command.NewFactory(envRepository)
xcodeVersionReader := xcodeversion.NewXcodeVersionProvider(cmdFactory)

xcodeCommandRunner := xcodecommand.Runner(nil)
switch logFormatter {
Expand All @@ -92,7 +94,7 @@ func createXcodebuildArchiver(logger log.Logger, logFormatter string) (step.Xcod
panic(fmt.Sprintf("Unknown log formatter: %s", logFormatter))
}

return step.NewXcodebuildArchiver(xcodeCommandRunner, logFormatter, pathProvider, pathChecker, pathModifier, fileManager, cmdFactory, logger), nil
return step.NewXcodebuildArchiver(xcodeCommandRunner, logFormatter, xcodeVersionReader, pathProvider, pathChecker, pathModifier, fileManager, cmdFactory, logger), nil
}

func createRunOptions(config step.Config) step.RunOpts {
Expand All @@ -103,6 +105,8 @@ func createRunOptions(config step.Config) step.RunOpts {
XcodeMajorVersion: config.XcodeMajorVersion,
ArtifactName: config.ArtifactName,

ShouldLockSwiftPackages: config.ShouldLockSwiftPackages,

CodesignManager: config.CodesignManager,

PerformCleanAction: config.PerformCleanAction,
Expand Down
55 changes: 55 additions & 0 deletions mocks/XcodeVersionReader.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions step.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ inputs:
opts:
title: Distribution method
summary: Describes how Xcode should export the archive.
description: |-
Describes how Xcode should export the archive.

The input value sets the method in the export options plist content.

From Xcode 15.3 onwards, updated methods are used:
- `debugging`, when `development` is selected
- `app-store-connect`, when `app-store` is selected
- `release-testing`, when `ad-hoc` is selected
- `enterprise` is unchanged
value_options:
- development
- app-store
Expand All @@ -115,6 +125,24 @@ inputs:

The input value sets xcodebuild's `-configuration` option.

- lock_swift_packages: "no"
opts:
category: xcodebuild configuration
title: Disable Swift Package Manager automatic resolution
summary: If this input is set, the Step will disable Swift Package Manager automatic resolution.
description: |-
If this input is set, the Step will disable Swift Package Manager automatic resolution.

When enabled, runs the following:
```
defaults write com.apple.dt.Xcode IDEPackageOnlyUseVersionsFromResolvedFile -bool YES
defaults write com.apple.dt.Xcode IDEDisableAutomaticPackageResolution -bool YES
```
value_options:
- "yes"
- "no"
is_required: true

- xcconfig_content: COMPILER_INDEX_STORE_ENABLE = NO
opts:
category: xcodebuild configuration
Expand Down
58 changes: 35 additions & 23 deletions step/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/bitrise-io/go-xcode/v2/xcconfig"
cache "github.com/bitrise-io/go-xcode/v2/xcodecache"
"github.com/bitrise-io/go-xcode/v2/xcodecommand"
"github.com/bitrise-io/go-xcode/v2/xcodeversion"
"github.com/bitrise-io/go-xcode/xcarchive"
"github.com/bitrise-io/go-xcode/xcodebuild"
"github.com/kballard/go-shellquote"
Expand Down Expand Up @@ -76,10 +77,11 @@ type Inputs struct {
ExportMethod string `env:"distribution_method,opt[app-store,ad-hoc,enterprise,development]"`

// xcodebuild configuration
Configuration string `env:"configuration"`
XcconfigContent string `env:"xcconfig_content"`
PerformCleanAction bool `env:"perform_clean_action,opt[yes,no]"`
XcodebuildOptions string `env:"xcodebuild_options"`
Configuration string `env:"configuration"`
ShouldLockSwiftPackages bool `env:"lock_swift_packages,opt[yes,no]"`
XcconfigContent string `env:"xcconfig_content"`
PerformCleanAction bool `env:"perform_clean_action,opt[yes,no]"`
XcodebuildOptions string `env:"xcodebuild_options"`

// xcodebuild log formatting
LogFormatter string `env:"log_formatter,opt[xcbeautify,xcodebuild,xcpretty]"`
Expand Down Expand Up @@ -134,17 +136,18 @@ type Config struct {
}

type XcodebuildArchiveConfigParser struct {
stepInputParser stepconf.InputParser
xcodeVersionProvider XcodeVersionProvider
fileManager fileutil.FileManager
cmdFactory command.Factory
logger log.Logger
stepInputParser stepconf.InputParser
xcodeVersionReader xcodeversion.Reader
fileManager fileutil.FileManager
cmdFactory command.Factory
logger log.Logger
}

// XcodebuildArchiver ...
type XcodebuildArchiver struct {
xcodeCommandRunner xcodecommand.Runner
logFormatter string
xcodeVersionReader xcodeversion.Reader
pathProvider pathutil.PathProvider
pathChecker pathutil.PathChecker
pathModifier pathutil.PathModifier
Expand All @@ -153,21 +156,22 @@ type XcodebuildArchiver struct {
cmdFactory command.Factory
}

func NewXcodeArchiveConfigParser(stepInputParser stepconf.InputParser, xcodeVersionProvider XcodeVersionProvider, fileManager fileutil.FileManager, cmdFactory command.Factory, logger log.Logger) XcodebuildArchiveConfigParser {
func NewXcodeArchiveConfigParser(stepInputParser stepconf.InputParser, xcodeVersionReader xcodeversion.Reader, fileManager fileutil.FileManager, cmdFactory command.Factory, logger log.Logger) XcodebuildArchiveConfigParser {
return XcodebuildArchiveConfigParser{
stepInputParser: stepInputParser,
xcodeVersionProvider: xcodeVersionProvider,
fileManager: fileManager,
cmdFactory: cmdFactory,
logger: logger,
stepInputParser: stepInputParser,
xcodeVersionReader: xcodeVersionReader,
fileManager: fileManager,
cmdFactory: cmdFactory,
logger: logger,
}
}

// NewXcodebuildArchiver ...
func NewXcodebuildArchiver(xcodecommandRunner xcodecommand.Runner, logFormatter string, pathProvider pathutil.PathProvider, pathChecker pathutil.PathChecker, pathModifier pathutil.PathModifier, fileManager fileutil.FileManager, cmdFactory command.Factory, logger log.Logger) XcodebuildArchiver {
func NewXcodebuildArchiver(xcodecommandRunner xcodecommand.Runner, logFormatter string, xcodeVersionReader xcodeversion.Reader, pathProvider pathutil.PathProvider, pathChecker pathutil.PathChecker, pathModifier pathutil.PathModifier, fileManager fileutil.FileManager, cmdFactory command.Factory, logger log.Logger) XcodebuildArchiver {
return XcodebuildArchiver{
xcodeCommandRunner: xcodecommandRunner,
logFormatter: logFormatter,
xcodeVersionReader: xcodeVersionReader,
pathProvider: pathProvider,
pathChecker: pathChecker,
pathModifier: pathModifier,
Expand Down Expand Up @@ -222,17 +226,16 @@ func (s XcodebuildArchiveConfigParser) ProcessInputs() (Config, error) {
s.logger.Infof("Xcode version:")

// Detect Xcode major version
xcodebuildVersion, err := s.xcodeVersionProvider.GetXcodeVersion()
xcodebuildVersion, err := s.xcodeVersionReader.GetVersion()
if err != nil {
return Config{}, fmt.Errorf("failed to determine xcode version, error: %s", err)
}
s.logger.Printf("%s (%s)", xcodebuildVersion.Version, xcodebuildVersion.BuildVersion)

xcodeMajorVersion := xcodebuildVersion.MajorVersion
if xcodeMajorVersion < minSupportedXcodeMajorVersion {
return Config{}, fmt.Errorf("invalid xcode major version (%d), should not be less then min supported: %d", xcodeMajorVersion, minSupportedXcodeMajorVersion)
if xcodebuildVersion.Major < minSupportedXcodeMajorVersion {
return Config{}, fmt.Errorf("invalid xcode major version (%d), should not be less then min supported: %d", xcodebuildVersion.Major, minSupportedXcodeMajorVersion)
}
config.XcodeMajorVersion = int(xcodeMajorVersion)
config.XcodeMajorVersion = int(xcodebuildVersion.Major)

// Validation ExportOptionsPlistContent
exportOptionsPlistContent := strings.TrimSpace(config.ExportOptionsPlistContent)
Expand Down Expand Up @@ -319,6 +322,8 @@ type RunOpts struct {
XcodeMajorVersion int
ArtifactName string

ShouldLockSwiftPackages bool

// Code signing, nil if automatic code signing is "off"
CodesignManager *codesign.Manager

Expand Down Expand Up @@ -361,6 +366,13 @@ func (s XcodebuildArchiver) Run(opts RunOpts) (RunResult, error) {
s.logger.Println()

if opts.XcodeMajorVersion >= 11 {
if opts.ShouldLockSwiftPackages {
s.logger.Infof("Swift package dependencies are locked, disabling automatic updates")
if err := lockSwiftPackages(s.logger, s.cmdFactory); err != nil {
return out, fmt.Errorf("failed to lock swift packages: %w", err)
}
}

s.logger.Infof("Running resolve Swift package dependencies")
// Resolve Swift package dependencies, so running -showBuildSettings later is faster later
// Specifying a scheme is required for workspaces
Expand Down Expand Up @@ -1003,9 +1015,9 @@ func (s XcodebuildArchiver) xcodeIPAExport(opts xcodeIPAExportOpts) (xcodeIPAExp
signingStyle = exportoptions.SigningStyleAutomatic
}

generator := exportoptionsgenerator.New(xcodeProj, scheme, configuration, s.logger)
generator := exportoptionsgenerator.New(xcodeProj, scheme, configuration, s.xcodeVersionReader, s.logger)
exportOptions, err := generator.GenerateApplicationExportOptions(exportMethod, opts.ICloudContainerEnvironment, opts.ExportDevelopmentTeam,
opts.UploadBitcode, opts.CompileBitcode, archiveCodeSignIsXcodeManaged, signingStyle, int64(opts.XcodeMajorVersion), opts.TestFlightInternalTestingOnly)
opts.UploadBitcode, opts.CompileBitcode, archiveCodeSignIsXcodeManaged, signingStyle, opts.TestFlightInternalTestingOnly)
if err != nil {
return out, err
}
Expand Down
5 changes: 2 additions & 3 deletions step/step_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ func TestXcodeArchiveStep_ProcessInputs(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
envRepository := MockEnvRepository{envs: tt.envs}
s := XcodebuildArchiveConfigParser{
xcodeVersionProvider: NewMockXcodeVersionProvider(models.XcodebuildVersionModel{MajorVersion: 11}),
stepInputParser: stepconf.NewInputParser(envRepository),
logger: log.NewLogger(),
stepInputParser: stepconf.NewInputParser(envRepository),
logger: log.NewLogger(),
}

config, err := s.ProcessInputs()
Expand Down
Loading