Commit 3db55c28 authored by Mathieu Lutfy's avatar Mathieu Lutfy Committed by Aegir user

extdir: only process the latest tag

parent cb6fa77b
......@@ -83,10 +83,11 @@ function drush_extdir_scan($pattern = NULL) {
continue;
// $giturl = _extdir_guess_git_url($lastRelease, $extension);
}
$gittags = _extdir_get_tags($giturl);
$gittags = _extdir_get_latest_tag($giturl);
_extdir_debug(array('giturl' => $giturl, 'gittags' => $gittags));
// Foreach source release, create release if needed and possible
foreach ($gittags as $version => $tag) {
// Is this release not yet created on civicrm.org?
if (!in_array($version, $releases)) {
......@@ -117,9 +118,9 @@ function drush_extdir_scan($pattern = NULL) {
}
_extdir_send_email(implode($maintainers, ', '), $subject, $body);
}
} // end if version not in existing releases
} // end foreach git tag
} // end foreach extension
}
}
}
}
function _extdir_debug($mixed) {
......@@ -239,27 +240,42 @@ function _extdir_create_release($extension, $version, $giturl, $tag) {
}
/**
* Get a list of tags in a git repo
* Get the latest tag from the repository.
*
* Previously returned all version tags, but later modified to return only
* the latest, because emails of failed releases are annoying.
*
* @param string|NULL $giturl
* @return array (string $version => string $tag) list of tags. if $giturl is missing/invalid, then array()
*/
function _extdir_get_tags($giturl) {
$gittags = array();
function _extdir_get_latest_tag($giturl) {
$gittags = [];
if (!empty($giturl)) {
$output = array();
$cmd = sprintf("git ls-remote --tags %s", escapeshellarg($giturl));
// This lists all tags and normalizes the tag so that we can do a proper version
// sort, even if the extention author mixed release tags of 'v1.0.0' and '2.0.0'.
//
// For those who understandably do not like awk:
// - awk -F'/' => uses '/' as a separator, so that: "5e132[...]4be refs/tags/1.1" returns "1.1" as the 3rd column
// - sub(/^v/, \"\", $3) does a string replacement to remove the 'v' in the version number
// - since sub does a replacement on the line, we save version=$3 so that we can output both the original and modified version
// - the second awk call, is so that after the version sort, we can get rid of the normalized version, keep only the original (second column)
$cmd = sprintf("git ls-remote --tags %s | awk -F'/' '{version=$3; sub(/^v/, \"\", $3); print $3, version}' | sort -r -V | awk '{print $2}'", escapeshellarg($giturl));
$output = [];
exec($cmd, $output);
foreach ($output as $line) {
if ($pos = strpos($line, 'tags/')) {
$tag = substr($line, $pos + 5);
if (preg_match('/^v?[0-9](0|1|2|3|4|5|6|7|8|9|\.|-|alpha|beta)*$/', $tag)) {
$version = str_replace('v', '', $tag);
$gittags[$version] = $tag;
}
foreach ($output as $tag) {
if (preg_match('/^v?[0-9](0|1|2|3|4|5|6|7|8|9|\.|-|alpha|beta)*$/', $tag)) {
$version = str_replace('v', '', $tag);
$gittags[$version] = $tag;
// Return the first valid tag, i.e. the most recent version
return $gittags;
}
}
}
return $gittags;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment