Skip to content
Merged
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
33 changes: 30 additions & 3 deletions .github/workflows/installer-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -207,16 +207,30 @@ jobs:
mkdir -p "$HOME/.gnupg"
chmod 700 "$HOME/.gnupg"

# Get current branch name for testing with fallbacks
# GITHUB_HEAD_REF is set for pull requests, GITHUB_REF for pushes
# If both fail, default to main branch to prevent CI failures
if [ -n "$GITHUB_HEAD_REF" ]; then
CURRENT_BRANCH="$GITHUB_HEAD_REF"
elif [ -n "$GITHUB_REF" ]; then
CURRENT_BRANCH="${GITHUB_REF#refs/heads/}"
else
CURRENT_BRANCH="main"
echo "Warning: Could not detect branch, defaulting to main"
fi
echo "Using branch: $CURRENT_BRANCH"

# Run the installer with minimal configuration that shouldn't require interaction
# We use https as the git clone protocol to avoid SSH key prompts
# We use the current branch to test branch-specific changes
timeout 300 ./dotfiles-installer install \
--non-interactive \
--plain \
--extra-verbose \
--install-prerequisites=true \
--git-clone-protocol=https \
--git-branch="$CURRENT_BRANCH" \
--work-env=false \
--multi-user-system=false

- name: Install expect tool
run: |
Expand All @@ -243,12 +257,25 @@ jobs:
mkdir -p "$HOME/.gnupg"
chmod 700 "$HOME/.gnupg"

# Run the expect script with test parameters
# Get current branch name for testing with fallbacks
# This ensures we test against the same branch as the installer changes
if [ -n "$GITHUB_HEAD_REF" ]; then
CURRENT_BRANCH="$GITHUB_HEAD_REF"
elif [ -n "$GITHUB_REF" ]; then
CURRENT_BRANCH="${GITHUB_REF#refs/heads/}"
else
CURRENT_BRANCH="main"
echo "Warning: Could not detect branch, defaulting to main"
fi
echo "Using branch: $CURRENT_BRANCH"

# Run the expect script with test parameters and current branch
installer/test-interactive-gpg.exp \
"./dotfiles-installer" \
"test-user@example.com" \
"Test CI User" \
"test-ci-passphrase"
"test-ci-passphrase" \
"$CURRENT_BRANCH"

- name: Verify Installation Artifacts (if created)
run: |
Expand Down
4 changes: 0 additions & 4 deletions dot_zprofile.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ if [[ ! -v BREW_LOADED || "$BREW_LOADED" == "false" ]]; then
# Load (home)brew
eval "$("$BREW_BINARY" shellenv)"
{{- end -}}
{{ if .system.multi_user_system -}}
# Impersonate brew management user
alias brew="sudo -Hu {{ .system.brew_multi_user }} $BREW_BINARY"
{{- end }}
fi

BREW_LOADED=true
Expand Down
4 changes: 0 additions & 4 deletions dot_zshenv.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ if [[ ! -v BREW_LOADED || "$BREW_LOADED" == "false" ]]; then
load_brew_env
{{- end -}}
{{- end -}}
{{- if .system.multi_user_system }}
# Impersonate brew management user
alias brew="sudo -Hu {{ .system.brew_multi_user }} $BREW_BINARY"
{{- end }}
fi

BREW_LOADED=true
Expand Down
4 changes: 0 additions & 4 deletions dot_zshrc.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ zstyle ':completion:*' menu select
mkdir -p ~/.zfunc &>/dev/null
fpath+=~/.zfunc

{{ if .system.multi_user_system -}}
autoload -U +X compinit && compinit -u
{{- else -}}
autoload -U +X compinit && compinit
{{- end }}
autoload -U +X bashcompinit && bashcompinit

autoload -U select-word-style
Expand Down
32 changes: 15 additions & 17 deletions installer/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ var (
shellName string
installBrew bool
installShellWithBrew bool
multiUserSystem bool

gitCloneProtocol string
gitBranch string
verbose bool
installPrerequisites bool
)
Expand Down Expand Up @@ -243,14 +244,13 @@ func installHomebrew(sysInfo compatibility.SystemInfo, log logger.Logger) (strin

// Create BrewInstaller using the new API.
installer := brew.NewBrewInstaller(brew.Options{
SystemInfo: &sysInfo,
Logger: cliLogger,
Commander: globalCommander,
HTTPClient: globalHttpClient,
OsManager: globalOsManager,
Fs: globalFilesystem,
MultiUserSystem: multiUserSystem,
DisplayMode: GetDisplayMode(),
SystemInfo: &sysInfo,
Logger: cliLogger,
Commander: globalCommander,
HTTPClient: globalHttpClient,
OsManager: globalOsManager,
Fs: globalFilesystem,
DisplayMode: GetDisplayMode(),
})

log.StartProgress("Checking Homebrew availability")
Expand Down Expand Up @@ -428,7 +428,7 @@ func installGpgClient(log logger.Logger) error {
func setupDotfilesManager(log logger.Logger) error {
log.StartProgress("Setting up dotfiles manager")

dm, err := chezmoi.TryStandardChezmoiManager(log, globalFilesystem, globalOsManager, globalCommander, globalPackageManager, globalHttpClient, GetDisplayMode(), chezmoi.DefaultGitHubUsername, gitCloneProtocol == "ssh")
dm, err := chezmoi.TryStandardChezmoiManager(log, globalFilesystem, globalOsManager, globalCommander, globalPackageManager, globalHttpClient, GetDisplayMode(), chezmoi.DefaultGitHubUsername, gitCloneProtocol == "ssh", gitBranch)
if err != nil {
log.FailProgress("Failed to create dotfiles manager", err)
return err
Expand Down Expand Up @@ -466,9 +466,7 @@ func initDotfilesManagerData(dm dotfilesmanager.DotfilesManager) error {
LastName: "Gruber",
Email: "timor.gruber@gmail.com",
SystemData: mo.Some(dotfilesmanager.DotfilesSystemData{
Shell: shellName,
MultiUserSystem: multiUserSystem,
BrewMultiUser: "linuxbrew-manager",
Shell: shellName,
}),
}

Expand Down Expand Up @@ -515,11 +513,11 @@ func init() {
"Install brew if not already installed")
installCmd.Flags().BoolVar(&installShellWithBrew, "install-shell-with-brew", true,
"Install shell with brew if not already installed")
installCmd.Flags().BoolVar(&multiUserSystem, "multi-user-system", false,
"Treat this system as a multi-user system (affects some dotfiles)")
installCmd.Flags().StringVar(&gitCloneProtocol, "git-clone-protocol", "https",
"Use the given git clone protocol (ssh or https) for git operations")

installCmd.Flags().StringVar(&gitBranch, "git-branch", "",
"Use the given git branch for dotfiles repository operations (defaults to repository's default branch). "+
"Useful for testing changes in feature branches or when running in CI/CD pipelines.")
installCmd.Flags().BoolVar(&installPrerequisites, "install-prerequisites", false,
"Automatically install missing prerequisites")

Expand All @@ -529,8 +527,8 @@ func init() {
viper.BindPFlag("shell", installCmd.Flags().Lookup("shell"))
viper.BindPFlag("install-brew", installCmd.Flags().Lookup("install-brew"))
viper.BindPFlag("install-shell-with-brew", installCmd.Flags().Lookup("install-shell-with-brew"))
viper.BindPFlag("multi-user-system", installCmd.Flags().Lookup("multi-user-system"))
viper.BindPFlag("git-clone-protocol", installCmd.Flags().Lookup("git-clone-protocol"))
viper.BindPFlag("git-branch", installCmd.Flags().Lookup("git-branch"))

viper.BindPFlag("install-prerequisites", installCmd.Flags().Lookup("install-prerequisites"))
}
Loading
Loading