Skip to content

Commit fcd9b96

Browse files
committed
Add lock Swift packges input
1 parent 7531c80 commit fcd9b96

File tree

4 files changed

+59
-4
lines changed

4 files changed

+59
-4
lines changed

main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ func createRunOptions(config step.Config) step.RunOpts {
103103
XcodeMajorVersion: config.XcodeMajorVersion,
104104
ArtifactName: config.ArtifactName,
105105

106+
ShouldLockSwiftPackages: config.ShouldLockSwiftPackages,
107+
106108
CodesignManager: config.CodesignManager,
107109

108110
PerformCleanAction: config.PerformCleanAction,

step.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,24 @@ inputs:
115115
116116
The input value sets xcodebuild's `-configuration` option.
117117
118+
- lock_swift_packages: "yes"
119+
opts:
120+
category: xcodebuild configuration
121+
title: Disable Swift Package Manager automatic resolution
122+
summary: If this input is set, the Step will disable Swift Package Manager automatic resolution.
123+
description: |-
124+
If this input is set, the Step will disable Swift Package Manager automatic resolution.
125+
126+
When enabled, runs the following:
127+
```
128+
defaults write com.apple.dt.Xcode IDEPackageOnlyUseVersionsFromResolvedFile -bool YES
129+
defaults write com.apple.dt.Xcode IDEDisableAutomaticPackageResolution -bool YES
130+
```
131+
value_options:
132+
- "yes"
133+
- "no"
134+
is_required: true
135+
118136
- xcconfig_content: COMPILER_INDEX_STORE_ENABLE = NO
119137
opts:
120138
category: xcodebuild configuration

step/step.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,11 @@ type Inputs struct {
7676
ExportMethod string `env:"distribution_method,opt[app-store,ad-hoc,enterprise,development]"`
7777

7878
// xcodebuild configuration
79-
Configuration string `env:"configuration"`
80-
XcconfigContent string `env:"xcconfig_content"`
81-
PerformCleanAction bool `env:"perform_clean_action,opt[yes,no]"`
82-
XcodebuildOptions string `env:"xcodebuild_options"`
79+
Configuration string `env:"configuration"`
80+
ShouldLockSwiftPackages bool `env:"lock_swift_packages,opt[yes,no]"`
81+
XcconfigContent string `env:"xcconfig_content"`
82+
PerformCleanAction bool `env:"perform_clean_action,opt[yes,no]"`
83+
XcodebuildOptions string `env:"xcodebuild_options"`
8384

8485
// xcodebuild log formatting
8586
LogFormatter string `env:"log_formatter,opt[xcbeautify,xcodebuild,xcpretty]"`
@@ -319,6 +320,8 @@ type RunOpts struct {
319320
XcodeMajorVersion int
320321
ArtifactName string
321322

323+
ShouldLockSwiftPackages bool
324+
322325
// Code signing, nil if automatic code signing is "off"
323326
CodesignManager *codesign.Manager
324327

@@ -361,6 +364,13 @@ func (s XcodebuildArchiver) Run(opts RunOpts) (RunResult, error) {
361364
s.logger.Println()
362365

363366
if opts.XcodeMajorVersion >= 11 {
367+
if opts.ShouldLockSwiftPackages {
368+
s.logger.Infof("Swift package dependencies are locked, disabling automatic updates")
369+
if err := lockSwiftPackages(s.logger, s.cmdFactory); err != nil {
370+
return out, fmt.Errorf("failed to lock swift packages: %w", err)
371+
}
372+
}
373+
364374
s.logger.Infof("Running resolve Swift package dependencies")
365375
// Resolve Swift package dependencies, so running -showBuildSettings later is faster later
366376
// Specifying a scheme is required for workspaces

step/utils.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ package step
33
import (
44
"bufio"
55
"fmt"
6+
"os"
67
"regexp"
78
"strings"
89

910
"github.com/bitrise-io/go-utils/colorstring"
1011
"github.com/bitrise-io/go-utils/sliceutil"
1112
"github.com/bitrise-io/go-utils/stringutil"
13+
"github.com/bitrise-io/go-utils/v2/command"
1214
"github.com/bitrise-io/go-utils/v2/log"
1315
"github.com/bitrise-io/go-xcode/exportoptions"
1416
)
@@ -91,3 +93,26 @@ func findIDEDistrubutionLogsPath(output string, logger log.Logger) (string, erro
9193

9294
return "", nil
9395
}
96+
97+
func lockSwiftPackages(logger log.Logger, cmdFactory command.Factory) error {
98+
// defaults write com.apple.dt.Xcode IDEPackageOnlyUseVersionsFromResolvedFile -bool YES
99+
// defaults write com.apple.dt.Xcode IDEDisableAutomaticPackageResolution -bool YES
100+
101+
cmdOpts := &command.Opts{
102+
Stdout: os.Stdout,
103+
Stderr: os.Stderr,
104+
}
105+
deafultsCommands := []command.Command{
106+
cmdFactory.Create("defaults", []string{"write", "com.apple.dt.Xcode", "IDEPackageOnlyUseVersionsFromResolvedFile", "-bool", "YES"}, cmdOpts),
107+
cmdFactory.Create("defaults", []string{"write", "com.apple.dt.Xcode", "IDEDisableAutomaticPackageResolution", "-bool", "YES"}, cmdOpts),
108+
}
109+
110+
for _, cmd := range deafultsCommands {
111+
logger.Printf("$ %s", cmd.PrintableCommandArgs())
112+
if err := cmd.Run(); err != nil {
113+
return fmt.Errorf("Locking Swift pacakges failed: %w", err)
114+
}
115+
}
116+
117+
return nil
118+
}

0 commit comments

Comments
 (0)