// Start the build script // ******************************* Config::enableLogging(); // ******************** // *** Initial output // Task::log("\n---------------------------------------\n"); Task::log("-------- Sync repository\n\n"); // Prompt for user password, if it's not hardcoded CliTask::promptAccountPassword($cogecoAccount); // ******************** // Prompt user input // // Prompt user to input a local folder to sync $workingCopy = CliTask::promptRepo(); Task::log("You chose " . $workingCopy->getRepoUrl() . "\n\n"); // Prompt user to chose a remote folder to sync to $selectedDir = CliTask::promptDir(array($devDir, $dev2Dir, $uatDir, $uat2Dir, $uat3Dir, $preprodDir)); Task::log("You chose " . $selectedDir->getPath() . "\n\n"); CliTask::promptQuit('Continue? [y/n]: '); // ******************** // *** Checkout // SvnTask::checkoutClean($workingCopy); SvnTask::createManifestFile($workingCopy, FALSE, TRUE); // ******************** // Sync files and folders // $rsyncOptions = new RsyncOptions($workingCopy->dir, $selectedDir); $rsyncOptions->chmod('Du=rwx,Dg=rwx,Do=rwx,Fu=rw,Fg=rw,Fo=r')->excludesAppend(array('/dev/', '/db/')); FileSyncTask::sync($rsyncOptions);
$changesText = ViewTask::getLogEntriesText($logEntries); $changesHtml = ViewTask::getLogEntriesHtml($logEntries); // Load the email templates with the changes $emailText = ViewTask::load('views/template-release-text.php', array('changes' => $changesText), TRUE); $emailHtml = ViewTask::load('views/template-release-html.php', array('changes' => $changesHtml), TRUE); // Create the emails as files $emailFileBaseName = "release-prod-r{$workingCopy->info->commitRevision}"; EmailTask::createEmailFiles($emailFileBaseName, $emailHtml, $emailText); // ******************** // *** Deploy intermediate // // Sync files from the working copy to the temporary prod directory FileSyncTask::sync($rsyncOptions1); // Task::log("- Syncing intermediate directory {$syncDestinationDir1->path} with {$syncDestinationDir2->path}\n\n"); // $rsyncCommand = FileSyncTask::getRsyncCommand($rsyncOptions2); SshTask::exec($syncDestinationDir2->getHost(), $rsyncCommand); Task::log("\n"); // ******************** // *** Tag release // if ($build === 'prod') { SvnTask::tagRelease($maoTag, $workingCopy->dir->path, "Release to production - Revision: {$workingCopy->info->commitRevision}"); } // ******************** // *** Notify // $maoReleaseEmail->bodyHtml = $emailHtml; $maoReleaseEmail->bodyText = $emailText; EmailTask::sendEmail($emailConnector, $maoReleaseEmail);
// Start the build script // ******************************* Config::enableLogging(); // ******************** // *** Initial output // Task::log("\n---------------------------------------\n"); Task::log("-------- Sync repository\n\n"); // Prompt for user password, if it's not hardcoded CliTask::promptAccountPassword($cogecoAccount); // ******************** // Prompt user input // // Prompt user to input a local folder to sync $workingCopy = CliTask::promptRepo(); Task::log("You chose " . $workingCopy->getRepoUrl() . "\n\n"); // Prompt user to chose a remote folder to sync to $selectedDir = CliTask::promptDir(array($maoDev1Dir, $maoDev2Dir, $maoUat1Dir, $maoUat2Dir, $maoUat3Dir, $maoUat4Dir, $maoUat5Dir)); Task::log("You chose " . $selectedDir->getPath() . "\n\n"); CliTask::promptQuit('Continue? [y/n]: '); // ******************** // *** Checkout // SvnTask::checkoutClean($workingCopy); SvnTask::createManifestFile($workingCopy); // ******************** // Sync files and folders // $rsyncOptions = new RsyncOptions($workingCopy->dir, $selectedDir); $rsyncOptions->excludesAppend(array('/user_guide/', '/license.txt', '/vendor', 'application/logs/', '/dev/')); FileSyncTask::sync($rsyncOptions);
// Task::log("- Syncing revision {$workingCopy->info->commitRevision} with {$syncDestinationDir1->getPath()} on {$syncDestinationDir1->getHost()->hostname}\n\n"); // FileSyncTask::sync($rsyncOptions1); // ******************** // *** Deploy // TimerTask::start(); // Import DB MysqlTask::importDump($destinationDb, $tmpDumpFile->getPath(), $destinationDbSchema); // Task::log("- Syncing intermediate directory {$syncDestinationDir1->path} with {$syncDestinationDir2->path}\n\n"); // $rsyncCommand = FileSyncTask::getRsyncCommand($rsyncOptions2); SshTask::exec($syncDestinationDir1->getHost(), $rsyncCommand); // Stop the deploy timer and log it TimerTask::stop(); Task::log("Deploy time: " . TimerTask::getLastElapsedTime() . "\n\n"); exit; // ******************** // *** Tag // if ($build === 'prod') { SvnTask::commit($workingCopy, "Release to Production"); } // ******************** // *** Notify // $cogecoCaReleaseEmail->bodyHtml = ViewTask::load('views/template-release-html.php', array('changes' => ''), TRUE); $cogecoCaReleaseEmail->bodyText = ViewTask::load('views/template-release-text.php', array('changes' => ''), TRUE); EmailTask::sendEmail($emailConnector, $cogecoCaReleaseEmail);
/** * Check out a clean working copy from SVN * @param \Cogeco\Build\Entity\WorkingCopy $workingCopy * @param int $revision * @param int $externalsRevision */ public static function checkoutClean(WorkingCopy $workingCopy, $revision = 0, $externalsRevision = 0) { $rev = $revision === 0 ? 'HEAD' : $revision; $extRev = $externalsRevision === 0 ? 'HEAD' : $rev; self::log("-- Getting a clean checkout at "); if ($revision > 0) { self::log("revision {$revision}"); } else { self::log("head revision"); } if ($externalsRevision > 0) { self::log(" with externals at revision {$externalsRevision}"); } self::log("\n\n"); // Get the repo information to validate the requested revision numbers to checkout $svnRemoteInfo = self::getRepoInfo($workingCopy, $revision); $realRevision = $svnRemoteInfo->commitRevision; $realExtRevision = $externalsRevision; // Correct the requested revision number to the last commit one from the repo if ($revision !== $realRevision) { self::log("Check out last commit revision {$realRevision}\n\n"); } // Determine the real externals revision number as well if ($externalsRevision === $revision) { $realExtRevision = $realRevision; } else { $svnRemoteExtInfo = self::getRepoInfo($workingCopy, $externalsRevision); // Correct the requested revision number to the last commit one from the repo if ($externalsRevision !== $svnRemoteExtInfo->commitRevision) { self::log("Checking out last (externals) commit revision {$svnRemoteExtInfo->commitRevision}\n\n"); $realExtRevision = $svnRemoteExtInfo->commitRevision; } } // Get local svn info if (empty($workingCopy->info)) { try { $workingCopy->info = SvnTask::getInfo($workingCopy); } catch (Exception $e) { $workingCopy->info = NULL; // Indicates that the working copy is not checked out yet } } // The Working copy and remote repo do not share the same URL. // We must delete the working copy and do a fresh checkout if (!empty($workingCopy->info) && $workingCopy->info->url !== $svnRemoteInfo->url) { self::log("- Emptying the working copy folder\n\n"); FileSystemTask::rrmdir($workingCopy->dir->getPath(), FALSE); $workingCopy->info = NULL; } if ($workingCopy->info === NULL) { self::log("- Checkout a fresh copy\n\n"); self::checkout($workingCopy, $realRevision); $workingCopy->info = SvnTask::getInfo($workingCopy); } else { self::cleanUp($workingCopy); } // Do a bit of cleanup self::revert($workingCopy); self::purgeIgnoredAndUnversioned($workingCopy); // Set the externals and update the info object if (self::setExternalsToRevision($workingCopy, $realExtRevision)) { self::update($workingCopy, $realRevision); $workingCopy->info = SvnTask::getInfo($workingCopy); } }
} $dateTime['seconds'] = 0; $dateTime['minutes'] = 45; $dateTime['hours'] = 14; } else { $dateTime['seconds'] = 0; $dateTime['minutes'] = 45; $dateTime['hours'] = 9; } } $dateTime['0'] = strtotime(sprintf("%s-%s-%s %s:%s:%s", $dateTime['year'], $dateTime['mon'], $dateTime['mday'], $dateTime['hours'], $dateTime['minutes'], $dateTime['seconds'])); $deployTime = @ucfirst(strftime("%A le %d %B %Y à %Hh%M", $dateTime['0'])); // ******************************* // Get the latest SVN entry logs up until the last release to production // ******************************* $latestSvnLogEntries = SvnTask::getLatestLogEntries($workingCopy); $projectSvnLogEntries = array(); foreach ($latestSvnLogEntries as $revision => $entry) { if (stripos($entry->message, "Release to Production") !== FALSE) { break; } else { $projectSvnLogEntries[$revision] = $entry; } } unset($latestSvnLogEntries); // ******************** // *** Prep notification email and send it // $emailHtml = ViewTask::load('views/template-deploy-request-html.php', array('svnEntries' => $projectSvnLogEntries, 'deployTime' => $deployTime), TRUE); $deployRequestEmail->bodyHtml = $emailHtml; EmailTask::sendEmail($emailConnector, $deployRequestEmail);