Skip to content

Commit

Permalink
Merge pull request #1 from xwp/feature/keep-history
Browse files Browse the repository at this point in the history
Include SVN revision number in the source reference
  • Loading branch information
kasparsd authored Feb 20, 2020
2 parents 88116ff + e4f778c commit ad3651b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 32 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "xwp/wpcom-vip-plugins",
"name": "xwp/vip-wpcom-plugins-builder",
"description": "Composer repository for VIP WPCOM shared plugins",
"type": "project",
"license": "MIT",
Expand Down Expand Up @@ -33,6 +33,7 @@
"composer validate --no-check-all"
],
"build": [
"rm -rf public/*",
"XWP\\WPCOMVIPPlugins\\ConfigBuilder::build",
"satis build satis.json public"
]
Expand Down
58 changes: 29 additions & 29 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 18 additions & 2 deletions src/ConfigBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public static function build(Event $event)

$repositories = array_map(
function ($plugin) use ($plugins_dir) {
$plugin_dir_path = sprintf('%s/%s', $plugins_dir, $plugin);
$revisions = self::getDirectorySvnRevisions($plugin_dir_path);
$latestRevision = reset($revisions);

return [
'type' => 'package',
'package' => [
Expand All @@ -23,10 +27,10 @@ function ($plugin) use ($plugins_dir) {
'source' => [
'url' => 'https://vip-svn.wordpress.com/plugins',
'type' => 'svn',
'reference' => $plugin,
'reference' => sprintf('%s@%s', $plugin, $latestRevision),
],
'dist' => [
'url' => sprintf('%s/%s', $plugins_dir, $plugin),
'url' => $plugin_dir_path,
'type' => 'path',
],
],
Expand Down Expand Up @@ -54,4 +58,16 @@ protected static function getDirectories($path) {

return glob($pattern , GLOB_ONLYDIR);
}

protected static function getDirectorySvnRevisions($path) {
$logCommand = sprintf('svn log --xml %s', $path);
$xml = simplexml_load_string(shell_exec($logCommand));
$revisions = [];

foreach ($xml->logentry as $logentry) {
$revisions[] = (int) $logentry->attributes()->revision;
}

return $revisions;
}
}

0 comments on commit ad3651b

Please sign in to comment.