PHPCI
PHPCI copied to clipboard
Github webhook build failed
I have phpci configured for github private repository and it is working fine if i run build manually or with default webhook confuration. But i'm trying to configure webhook for pull request event. I have added github token into phpci config.yml. But getting strange error:
Submodule 'asset/layouts/widget' ([email protected]:user/widget.git) registered for path 'asset/layouts/widget'
Submodule path 'asset/layouts/widget': checked out '967b036b561e5e785ddad1a9cff05cc142c25ba4'
Cloning into '/home/phpci/www/phpci/PHPCI/build/121_616e1'...
Cloning into 'asset/layouts/widget'...
Switched to a new branch 'phpci/121'
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Failed to clone remote git repository.
Exception: Could not create a working copy.
Removing Build.
But manually runned builds are ok:
Submodule 'asset/layouts/widget' ([email protected]:user/widget.git) registered for path 'asset/layouts/widget'
Submodule path 'asset/layouts/widget': checked out '967b036b561e5e785ddad1a9cff05cc142c25ba4'
Cloning into '/home/phpci/www/phpci/PHPCI/build/118_72e34'...
Cloning into 'asset/layouts/widget'...
6cab5ba91a1f329a64e5bf83670dcb9bb5ec2836
Working copy created: /
RUNNING PLUGIN: composer
Using --prefer-dist flag
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Generating autoload files
PLUGIN: SUCCESS
RUNNING PLUGIN: mysql
PLUGIN: SUCCESS
RUNNING PLUGIN: shell
PLUGIN: SUCCESS
RUNNING PLUGIN: codeception
PLUGIN: SUCCESS
RUNNING PLUGIN: mysql
PLUGIN: SUCCESS
BUILD SUCCESS
Removing Build.
Any ideas how to fix this? Does phpci generates any logs or has verbose mode for runner?
So, i found this pretty bug. file PHPCI/Model/Build/GithubBuild.php
/**
* Handle any post-clone tasks, like applying a pull request patch on top of the branch.
* @param Builder $builder
* @param $cloneTo
* @return bool
*/
protected function postCloneSetup(Builder $builder, $cloneTo)
{
$buildType = $this->getExtra('build_type');
$success = true;
try {
if (!empty($buildType) && $buildType == 'pull_request') {
$remoteUrl = $this->getExtra('remote_url');
$remoteBranch = $this->getExtra('remote_branch');
$cmd = 'cd "%s" && git checkout -b phpci/' . $this->getId() . ' %s && git pull -q --no-edit %s %s';
$success = $builder->executeCommand($cmd, $cloneTo, $this->getBranch(), $remoteUrl, $remoteBranch);
}
} catch (\Exception $ex) {
$success = false;
}
if ($success) {
$success = parent::postCloneSetup($builder, $cloneTo);
}
return $success;
}
But git pull -q --no-edit %s %s'
require ssh authorization for private repos!
As hotfix i made
/**
* Handle any post-clone tasks, like applying a pull request patch on top of the branch.
* @param Builder $builder
* @param $cloneTo
* @return bool
*/
protected function postCloneSetup(Builder $builder, $cloneTo)
{
$buildType = $this->getExtra('build_type');
$success = true;
try {
if (!empty($buildType) && $buildType == 'pull_request') {
$keyFile = $this->writeSshKey($cloneTo);
if (!IS_WIN) {
$gitSshWrapper = $this->writeSshWrapper($cloneTo, $keyFile);
}
$remoteUrl = $this->getExtra('remote_url');
$remoteBranch = $this->getExtra('remote_branch');
$cmd = 'cd "%s" && git checkout -b phpci/' . $this->getId() . ' %s && git pull -q --no-edit %s %s';
if (!IS_WIN) {
$cmd = 'export GIT_SSH="'.$gitSshWrapper.'" && ' . $cmd;
}
$success = $builder->executeCommand($cmd, $cloneTo, $this->getBranch(), $remoteUrl, $remoteBranch);
}
} catch (\Exception $ex) {
$success = false;
}
if ($success) {
$success = parent::postCloneSetup($builder, $cloneTo);
}
return $success;
}
but this perform some useless duplicating and idealy $gitSshWrapper
needs to be passed as argument or stored in class params. I can make a pr if needs.
@hotrush +1 Experienced the same issue with pull request hook build and this patch fixed. Thanks!
I think your patch can be simplified to:
**
* Handle any post-clone tasks, like applying a pull request patch on top of the branch.
* @param Builder $builder
* @param $cloneTo
* @return bool
*/
protected function postCloneSetup(Builder $builder, $cloneTo)
{
$buildType = $this->getExtra('build_type');
$success = true;
try {
if (!empty($buildType) && $buildType == 'pull_request') {
$remoteUrl = $this->getExtra('remote_url');
$remoteBranch = $this->getExtra('remote_branch');
$cmd = 'cd "%s" && git checkout -b phpci/' . $this->getId() . ' %s && git pull -q --no-edit %s %s';
if (!IS_WIN) {
$keyFile = $this->writeSshKey($cloneTo);
$gitSshWrapper = $this->writeSshWrapper($cloneTo, $keyFile);
$cmd = 'export GIT_SSH="'.$gitSshWrapper.'" && ' . $cmd;
}
$success = $builder->executeCommand($cmd, $cloneTo, $this->getBranch(), $remoteUrl, $remoteBranch);
}
} catch (\Exception $ex) {
$success = false;
}
if ($success) {
$success = parent::postCloneSetup($builder, $cloneTo);
}
return $success;
}
@bdanchilla yeap, thanks!
@hotrush @bdanchilla - Sorry it has taken me ages to get to this. Would either of you mind submitting a PR for this fix? It would be super helpful.
Thanks! 👍
@dancryer Hi, i will take a look bit closer on holidays and prepare a PR.