Skip to content

Commit

Permalink
Adding automatic release notes from changelog file. (#16)
Browse files Browse the repository at this point in the history
* Adding automatic release notes from changelog file.

* PR fixes
  • Loading branch information
gpcastro committed Mar 26, 2019
1 parent 5a8338e commit 7b2559f
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
@@ -0,0 +1,9 @@

[//]: # (This file contains all the changes that should be displayed in our releases.)
[//]: # (In order to use it, add new lines below this comment session, above existing ones.)
[//]: # (The build and release systems will only add the new lines to the release, so NEVER edit an existing line,)
[//]: # (since it would make it appear again in the release.)
[//]: # (Add meaningful description of your changes, and if relevant how to make use of a new feature you're adding,)
[//]: # (as well as pointers to relevant documentation in our docs folder.)

- Officially releasing on GitHub.
8 changes: 8 additions & 0 deletions build/release.txt
@@ -0,0 +1,8 @@

[//]: # (This file contains all the changes that should be displayed in our releases.)
[//]: # (In order to use it, add new lines below this comment session, leaving the remaining lines in the file.)
[//]: # (The build and release systems will only add the new lines to the release, so NEVER edit an existing line,)
[//]: # (since it would make it appear again in the release.)
[//]: # (Add meaningful description of your changes, and if relevant how to make use of a new feature you're adding,)
[//]: # (as well as pointers to relevant documentation in our docs folder.)

6 changes: 6 additions & 0 deletions vsts/pipelines/_buildTemplate.yml
Expand Up @@ -178,6 +178,12 @@ steps:
scriptPath: ./vsts/scripts/dockerCleanup.sh
condition: or(eq(variables['TestBuildImages'], 'true'), eq(variables['TestRuntimeImages'], 'true'), eq(variables['TestIntegration'], 'true'))

- task: ShellScript@2
displayName: 'Generate release notes'
inputs:
scriptPath: ./vsts/scripts/generate-release-notes.sh
condition: and(succeeded(), eq(variables['PushBuildImages'], 'true'), eq(variables['BuildBuildImages'], 'true'))

- task: ArchiveFiles@2
displayName: 'Archive docker files and scripts for Oryx build and runtime images'
inputs:
Expand Down
42 changes: 42 additions & 0 deletions vsts/scripts/generate-release-notes.sh
@@ -0,0 +1,42 @@
#!/bin/bash
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT license.
# --------------------------------------------------------------------------------------------

# This script reads `./CHANGELOG.md` file and produces a file that is added as a build artifact which
# contains the changes only to a partcular build.
# To achieve this, we use the tags that the release adds to the git repo, and do a `git diff` between the
# changelog file in that tag and HEAD. The output of this diff is later parsed to only output the new lines.
# In order for this script to work, the agent running it should have the full git repo available.

set -e

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
CHANGELOG_FILE="$DIR/../CHANGELOG.md"

OUTPUT_FILE=$1
if [ -z "$OUTPUT_FILE" ]; then
# Create a default file using DevOps' pipeline artifacts directory
OUTPUT_FILE=$BUILD_ARTIFACTSTAGINGDIRECTORY/Release-notes.md
fi

echo "Release notes will be placed in $OUTPUT_FILE"

# First, we look for the latest tag that was pushed. Since our builds numbers are lexicographically ordered,
# YYYYMMDD.P, we just take the latest value that starts with a `2` to avoid other tags that might be in the repo.
# Optimistic note: yes, this script will break in year 3000, but we can fix it then.
LAST_TAG=$(git tag --sort=committerdate | tail -n 1)

if [ -z "$LAST_TAG" ]; then
echo "Couldn't find a base tag, will output the entire file"
# Ignore the lines starting with [//] which we're using as comments.
cat $CHANGELOG_FILE | grep -v -e '^\[//\]' > $OUTPUT_FILE
else
echo "Getting the diff from latest tag, $LAST_TAG"
# Get the diff for the changelog file
# The regex ^+[^+] is used to capture only the added lines, and the [^+], which means "exclude '+', removes the
# lines that git adds to the diff output containing the file name. Finally, we remove the '+' from the beginning
# of the selected lines.
git diff $LAST_TAG HEAD | grep -e ^+[^+] | sed 's/^+//' > $OUTPUT_FILE
fi

0 comments on commit 7b2559f

Please sign in to comment.