Skip to content

Commit

Permalink
Expose latest tag name in footer and release notes (#916)
Browse files Browse the repository at this point in the history
* Expose latest tag name in the footer and automatically generate a release in /news
  • Loading branch information
TheoChevalier authored and flodolo committed Nov 6, 2017
1 parent 49050aa commit f8fff54
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ app/config/sources/*.txt
cache/*.cache
cache/lastdataupdate.txt
cache/stats_*.json
cache/tag.txt
cache/version.txt
composer.lock
composer.phar
Expand Down
2 changes: 1 addition & 1 deletion app/inc/constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
If the file doesn't exist, or is empty, fall back to 'unknown.dev'.
*/
if (file_exists(CACHE_PATH . 'version.txt')) {
$file_content = file(CACHE_PATH . 'version.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$file_content = file(CACHE_PATH . 'version.txt');
$git_hash = empty($file_content)
? 'unknown.dev'
: $file_content[0];
Expand Down
21 changes: 19 additions & 2 deletions app/models/changelog.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
};

// Helper to generate the list of patches for the version
$github_link = function ($release) use ($releases) {
$github_link = function ($release, $releases) {
if ($release > 1) {
$keys = array_keys($releases);
$previous = $keys[array_search($release, $keys, true) - 1];
Expand All @@ -76,7 +76,7 @@
};

// Helper to generate a release title block
$release_title = function ($version) use ($releases) {
$release_title = function ($version, $releases) {
return <<<TITLE
<h2 class="release_number" id="v{$version}"><a href="#v{$version}">Version {$version}
<span class="release_date">{$releases[$version]}</span></a>
Expand Down Expand Up @@ -122,3 +122,20 @@

return $text;
};

$latest_undocumented_release = function() use ($releases, $github_link, $release_title) {
$text = '';
$version_number = substr(file_get_contents(CACHE_PATH . 'tag.txt'), 1);
end($releases);
$last_release = key($releases);

if ($version_number != $last_release) {
$github_relnotes = "https://github.com/mozfr/transvision/releases/tag/v{$version_number}";
$releases[$version_number] = 'Unknown';
$text .= $release_title($version_number, $releases);
$text .= "<p>There is no entry in the changelog for this release, but you can learn more about it in the <a href=\"{$github_relnotes}\">GitHub release notes</a> and look at the list of commits from the latest documented release.</p>";
$text .= $github_link($version_number, $releases);
}

return $text;
};
5 changes: 4 additions & 1 deletion app/scripts/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,19 @@ DEV_VERSION="dev"
if [ ! -d ${install}/.git ]
then
CURRENT_TIP="unknown"
LATEST_TAG_NAME="unknown"
else
cd "${install}"
CURRENT_TIP=$(git rev-parse HEAD)
LATEST_TAG=$(git describe --abbrev=0 --tags | xargs -I {} git rev-list -n 1 {})
LATEST_TAG_NAME=$(git describe --abbrev=0 --tags)
if [ "${CURRENT_TIP}" = "${LATEST_TAG}" ]
then
DEV_VERSION=""
fi
fi
echo "${CURRENT_TIP:0:7}${DEV_VERSION}" > "${install}/cache/version.txt"
echo "${CURRENT_TIP:0:7}${DEV_VERSION}" | tr -d '\n' > "${install}/cache/version.txt"
echo "${LATEST_TAG_NAME}" | tr -d '\n' > "${install}/cache/tag.txt"

setupExternalLibraries
initGeckoStringsRepo
Expand Down
5 changes: 3 additions & 2 deletions app/views/changelog.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
namespace Transvision;

$output = '';
$output .= $latest_undocumented_release();
foreach ($changelog as $release => $changes) {
// Add release title and initialize variables
$output .= $release_title($release);
$output .= $release_title($release, $releases);
$empty_release = true;
$section = '';
foreach ($changes as $change => $attributes) {
Expand All @@ -28,7 +29,7 @@
$output .= "</div></li>\n";
}
$output .= "</ul>\n";
$output .= $github_link($release);
$output .= $github_link($release, $releases);
}

print($output);
2 changes: 1 addition & 1 deletion app/views/changelog_rss.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

$output .= '<br>';
}
$output .= $github_link($release);
$output .= $github_link($release, $releases);
$output .= ' ]]></description>' . "\n";
$output .= ' </item>' . "\n";
}
Expand Down
6 changes: 6 additions & 0 deletions app/views/templates/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@
} else {
$last_update = "<p>Data last updated: not available.</p>\n";
}

$version_number = '';
if (file_exists(CACHE_PATH . 'tag.txt')) {
$version_number = $title_productname . ' ' . file_get_contents(CACHE_PATH . 'tag.txt');
}
?>
<!doctype html>

Expand Down Expand Up @@ -134,6 +139,7 @@
<div id="footer">
<p>Transvision is a tool provided by the French Mozilla community, <a href="https://www.mozfr.org" title="Home of MozFR, the French Mozilla Community" hreflang="fr">MozFR</a>.</p>
<?= $last_update ?>
<?= $version_number ?>
</div>

<script src="/assets/jquery/jquery.min.js?v=<?= VERSION ?>"></script>
Expand Down

0 comments on commit f8fff54

Please sign in to comment.