From 6e0d6ef44a0c46484bb8e960a5aeb5e773f42680 Mon Sep 17 00:00:00 2001 From: Jason Wray Date: Thu, 26 Apr 2018 12:34:56 -0400 Subject: [ios, build] Populate GitHub releases with templated notes Replicates our existing release notes format as an EJS template and Node JS script, then uploads the formatted notes during the deployment process. --- package.json | 1 + platform/ios/scripts/deploy-packages.sh | 4 +++- platform/ios/scripts/release-notes.js | 37 +++++++++++++++++++++++++++++++ platform/ios/scripts/release-notes.md.ejs | 10 +++++++++ 4 files changed, 51 insertions(+), 1 deletion(-) create mode 100755 platform/ios/scripts/release-notes.js create mode 100644 platform/ios/scripts/release-notes.md.ejs diff --git a/package.json b/package.json index 977cd2b09c..208d4e4c4a 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "pixelmatch": "^4.0.2", "pngjs": "^3.0.0", "request": "^2.72.0", + "semver": "^5.5.0", "tape": "^4.5.1" }, "engines": { diff --git a/platform/ios/scripts/deploy-packages.sh b/platform/ios/scripts/deploy-packages.sh index 103e53768c..643475f680 100755 --- a/platform/ios/scripts/deploy-packages.sh +++ b/platform/ios/scripts/deploy-packages.sh @@ -102,10 +102,12 @@ if [[ "${GITHUB_RELEASE}" == true ]]; then if [[ $( echo ${PUBLISH_VERSION} | awk '/[0-9]-/' ) ]]; then PUBLISH_PRE_FLAG='--pre-release' fi + RELEASE_NOTES=$( ./platform/ios/scripts/release-notes.js ) github-release release \ --tag "ios-v${PUBLISH_VERSION}" \ --name "ios-v${PUBLISH_VERSION}" \ - --draft ${PUBLISH_PRE_FLAG} + --draft ${PUBLISH_PRE_FLAG} \ + --description "${RELEASE_NOTES}" fi buildPackageStyle "ipackage" "symbols" diff --git a/platform/ios/scripts/release-notes.js b/platform/ios/scripts/release-notes.js new file mode 100755 index 0000000000..f47242d997 --- /dev/null +++ b/platform/ios/scripts/release-notes.js @@ -0,0 +1,37 @@ +#!/usr/bin/env node + +const fs = require('fs'); +const ejs = require('ejs'); +const _ = require('lodash'); +const semver = require('semver'); + +const changelog = fs.readFileSync('platform/ios/CHANGELOG.md', 'utf8'); + +// This regular expression parses the changelog for individual releases: +// - Matches lines starting with "## ". +// - Groups the version number. +// - Skips the (optional) release date. +// - Groups the changelog content. +// - Ends when another "## " is found. +const regex = /^## (\d+\.\d+\.\d+).*?\n(.+?)(?=\n^## )/gms; + +let releases = []; +while (match = regex.exec(changelog)) { + releases.push({ + 'version': match[1], + 'changelog': match[2].trim(), + }); +} + +const currentRelease = releases[0]; + +const versions = _.map(releases, 'version'); +const previousVersion = semver.maxSatisfying(versions, "<" + currentRelease.version); + +const releaseNotes = ejs.render(fs.readFileSync('platform/ios/scripts/release-notes.md.ejs', 'utf8'), { + 'currentVersion': currentRelease.version, + 'previousVersion': previousVersion, + 'changelog': currentRelease.changelog, +}); + +process.stdout.write(releaseNotes); diff --git a/platform/ios/scripts/release-notes.md.ejs b/platform/ios/scripts/release-notes.md.ejs new file mode 100644 index 0000000000..eedf9a0afa --- /dev/null +++ b/platform/ios/scripts/release-notes.md.ejs @@ -0,0 +1,10 @@ +<% + const CURRENTVERSION = locals.currentVersion; + const PREVIOUSVERSION = locals.previousVersion; + const CHANGELOG = locals.changelog; +-%> +[Changes](https://github.com/mapbox/mapbox-gl-native/compare/ios-v<%-PREVIOUSVERSION%>...ios-v<%-CURRENTVERSION%>) since [Mapbox Maps SDK for iOS v<%-PREVIOUSVERSION%>](https://github.com/mapbox/mapbox-gl-native/releases/tag/ios-v<%-PREVIOUSVERSION%>): + +<%-CHANGELOG%> + +Documentation is [available online](https://www.mapbox.com/ios-sdk/api/<%-CURRENTVERSION%>/) or as part of the download. -- cgit v1.2.1