Modify updateCode

This commit is contained in:
sebastian 2025-04-24 12:15:11 +02:00
parent 5151b22dc2
commit eeb2c016f7

View File

@ -163,43 +163,11 @@ class Local extends AbstractTasks
throw new ConfigurationException("Missing 'repository' configuration."); throw new ConfigurationException("Missing 'repository' configuration.");
} }
$targetWithDir = $target;
if (!empty(get('sub_directory'))) {
$targetWithDir .= ':{{sub_directory}}';
}
$bare = parse('{{deploy_path}}/.dep/repo');
$env = [
'GIT_TERMINAL_PROMPT' => '0',
'GIT_SSH_COMMAND' => get('git_ssh_command'),
];
start:
// Clone the repository to a bare repo.
runLocally("[ -d $bare ] || mkdir -p $bare");
runLocally("[ -f $bare/HEAD ] || $git clone --mirror $repository $bare 2>&1", ['env' => $env]);
// If remote url changed, drop `.dep/repo` and reinstall.
if (runLocally("cd $bare; $git config --get remote.origin.url") !== $repository) {
runLocally("rm -rf {{deploy_path}}$bare");
goto start;
}
runLocally("$git remote update 2>&1", ['env' => $env]);
// Copy to release_path. // Copy to release_path.
if (get('update_code_strategy') === 'archive') { runLocally("cd {{release_path}}; $git clone --branch $target $repository .");
runLocally("cd $bare; $git archive $targetWithDir | tar -x -f - -C {{release_path}} 2>&1");
} elseif (get('update_code_strategy') === 'clone') {
runLocally("cd {{release_path}}; $git clone -l $bare .");
runLocally("cd {{release_path}}; $git remote set-url origin $repository", ['env' => $env]);
runLocally("cd {{release_path}}; $git checkout --force $target");
} else {
throw new ConfigurationException(parse("Unknown `update_code_strategy` option: {{update_code_strategy}}."));
}
// Save git revision in REVISION file. // Save git revision in REVISION file.
$rev = escapeshellarg(runLocally("cd $bare; $git rev-list $target -1")); $rev = escapeshellarg(runLocally("cd {{release_path}}; $git rev-list $target -1"));
runLocally("echo $rev > {{release_path}}/REVISION"); runLocally("echo $rev > {{release_path}}/REVISION");
} }