Skip to content
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

version to work with windows #49

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
deploy.php
deploy.log
/.idea/*
4 changes: 3 additions & 1 deletion deploy.sample.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?php
define("TOKEN", "secret-token"); // The secret token to add as a GitHub or GitLab secret, or otherwise as https://www.example.com/?token=secret-token
define("REMOTE_REPOSITORY", "[email protected]:username/repository.git"); // The SSH URL to your repository
define("DIR", "/var/www/vhosts/repository/"); // The path to your repostiroy; this must begin with a forward slash (/)
define("DIR", "/var/www/vhosts/repository/"); // The path to your repository; this must begin with a forward slash (/)
//define("DIR", getcwd()); // The path to your repository; this must begin with a forward slash (/)
define("BRANCH", "refs/heads/master"); // The branch route
define("LOGFILE", "deploy.log"); // The name of the file you want to log to.
define("GIT", "/usr/bin/git"); // The path to the git executable
//define("GIT", '"C:\Program Files\Git\cmd\git.exe"'); // The path to the git executable for git windows
define("MAX_EXECUTION_TIME", 180); // Override for PHP's max_execution_time (may need set in php.ini)
define("BEFORE_PULL", ""); // A command to execute before pulling
define("AFTER_PULL", ""); // A command to execute after successfully pulling
Expand Down
12 changes: 9 additions & 3 deletions deployer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
$time = time();
$token = false;
$sha = false;
$DIR = preg_match("/\/$/", DIR) ? DIR : DIR . "/";
$DIR = preg_match("/\/$/", DIR) ? DIR : DIR;

// retrieve the token
if (!$token && isset($_SERVER["HTTP_X_HUB_SIGNATURE"])) {
Expand Down Expand Up @@ -69,12 +69,18 @@ function forbid($file, $reason) {
} elseif (!empty(TOKEN) && !isset($_SERVER["HTTP_X_HUB_SIGNATURE"]) && !isset($_SERVER["HTTP_X_GITLAB_TOKEN"]) && !isset($_GET["token"])) {
forbid($file, "No token detected");
} else {
// if json is empty get the current branch name
if(empty($json)){
exec( GIT . " branch --show-current 2>&1", $output, $exit);
$json["ref"]= reset($output);
}

// check if pushed branch matches branch specified in config
if ($json["ref"] === BRANCH) {
fputs($file, $content . PHP_EOL);

// ensure directory is a repository
if (file_exists($DIR . ".git") && is_dir($DIR)) {
if (file_exists($DIR . "\.git") && is_dir($DIR)) {
// change directory to the repository
chdir($DIR);

Expand Down Expand Up @@ -139,7 +145,7 @@ function forbid($file, $reason) {
// if an error occurred, return 500 and log the error
if ($exit !== 0) {
http_response_code(500);
$output = "=== ERROR: Pull failed using GIT `" . GIT . "` and DIR `" . DIR . "` ===\n" . $output;
$output = "=== ERROR: Pull failed using GIT `" . GIT . "` and DIR `" . $DIR . "` ===\n" . $output;
}

// write the output to the log and the body
Expand Down