Created
September 25, 2012 16:20
-
-
Save lyrixx/3782905 to your computer and use it in GitHub Desktop.
depoy via zip
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Define your constante here */ | |
define('DESTINATION_BASE', '/home/sensio/dev/danone_prod/'); | |
define('DESTINATION_FOLDER_BASENAME', 'DANONEPRO_PHP_%s'); | |
define('DESTINATION_FOLDER_DOC_BASENAME', 'DANONEPRO_PHP_DOC_%s'); | |
/* Do not touch after */ | |
exec('git fetch -q && git fetch -t -q'); | |
//Get last tag | |
$currentTag = exec('git describe --abbrev=0 --tags'); | |
logOutput('Current tag', $currentTag); | |
// Check if diff exist | |
$diffReturn = array(); | |
exec(sprintf('git diff --stat origin/master..%s',$currentTag), $diffReturn); | |
if (!count($diffReturn)) { | |
die('Il n\'y a pas de diff depuis le dernier tag'."\n"); | |
} | |
// Get last tag name | |
$currentTagInfo = array(); | |
$resultPregMatch = preg_match('#v(?P<major>\d+.\d+).(?P<minor>\d+)#', $currentTag, $currentTagInfo); | |
if (false == $resultPregMatch) { | |
die('Impossible d\'analyser le tag'."\n"); | |
} | |
// Get (current|next) (tag name) | |
$nextTag = sprintf('v%s.%s', $currentTagInfo['major'], $currentTagInfo['minor'] + 1); | |
logOutput('Next tag', $nextTag); | |
// Create new tag | |
exec(sprintf('git tag %s -a -f -m "created tag %s" origin/master', $nextTag, $nextTag)); | |
exec('git push --tags -q'); | |
logOutput('GIT', 'tag created'); | |
// Create filediff | |
exec(sprintf('git diff %s..%s --name-status | /bin/grep -v -e \'^D\' | awk \'{print $2}\' | sort | uniq > filediff.txt', | |
$currentTag, | |
$nextTag | |
)); | |
logOutput('GIT', 'File diff created'); | |
// Update working copy | |
exec('git reset --hard origin/master'); | |
// Export file Diff | |
$currentVersion = str_replace('v', '', $currentTag); | |
$nextVersion = str_replace('v', '', $nextTag); | |
$folderName = sprintf(DESTINATION_FOLDER_BASENAME, $nextVersion); | |
$folderPath = sprintf('%s%s', DESTINATION_BASE, $folderName); | |
exec(sprintf('rsync --delete --files-from=filediff.txt . %s', $folderPath)); | |
logOutput('Rsync','Executed'); | |
// Zip it | |
exec(sprintf('cd %s/web && zip -r ../../%s.zip * && cd -', $folderPath, $folderName)); | |
logOutput('Zip','Source Created'); | |
// Manage doc | |
$folderCurrentDocName = sprintf(DESTINATION_FOLDER_DOC_BASENAME, $currentVersion); | |
$folderCurrentPath = sprintf('%s%s', DESTINATION_BASE, $folderCurrentDocName); | |
$folderDocName = sprintf(DESTINATION_FOLDER_DOC_BASENAME, $nextVersion); | |
$folderDocPath = sprintf('%s%s', DESTINATION_BASE, $folderDocName); | |
exec(sprintf('cp -r %s %s', $folderCurrentPath, $folderDocPath)); | |
logOutput('Doc','Doc Copied'); | |
file_put_contents(sprintf('%s/VERSION.txt', $folderDocPath ), sprintf('version %s', $nextVersion)); | |
$changelog = <<< EOL | |
version %version%, %date% | |
- ??? | |
------------------------ | |
EOL; | |
$changelog = str_replace('%version%', $nextVersion, $changelog); | |
$changelog = str_replace('%date%', date('Y-m-d'), $changelog); | |
$changelog .= file_get_contents(sprintf('%s/CHANGELOG.txt', $folderDocPath )); | |
file_put_contents(sprintf('%s/CHANGELOG.txt', $folderDocPath ), $changelog); | |
$install = <<< EOL | |
INSTALLATION | |
------------ | |
1. UNZIP | |
cd www | |
cp ~/delivery/DANONEPRO_PHP_%version%.zip ./ | |
unzip DANONEPRO_PHP_%version%.zip | |
rm DANONEPRO_PHP_%version%.zip | |
EOL; | |
$install = str_replace('%version%', $nextVersion, $install); | |
file_put_contents(sprintf('%s/INSTALL.txt', $folderDocPath ), $install); | |
logOutput('Doc','Doc Updated'); | |
// Zip doc | |
exec(sprintf('cd %s && zip -r ../%s.zip * && cd -', $folderDocPath, $folderDocName)); | |
logOutput('Zip','Doc Created'); | |
/* Functions */ | |
function logOutput($title, $info = null) { | |
if ($info) { | |
return print sprintf('[%-15s] : %s', $title, $info). "\n"; | |
} | |
return print $title. "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment