Skip to content

Commit

Permalink
Automatic changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
Erwin Tratar authored and erwint committed Dec 3, 2018
1 parent 205bc8b commit c8461d7
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 67 deletions.
17 changes: 7 additions & 10 deletions .travis.yml
@@ -1,16 +1,19 @@
language: java
sudo: false

git:
depth: 9999999

branches:
only:
- develop
- /^\d+\.\d+\.\d+$/

script:
- xvfb-run mvn --batch-mode clean verify
- xvfb-run mvn --batch-mode clean verify

before_install:
- if [ -n "$TRAVIS_TAG" ]; then ./tools/update_version.sh $TRAVIS_TAG.$(date +%Y%m%d%H%M)-r; fi
- if [ -n "$TRAVIS_TAG" ]; then . ./tools/prepare_release.sh $TRAVIS_TAG.$(date +%Y%m%d%H%M)-r master; fi

install: true

Expand All @@ -33,14 +36,8 @@ deploy:
target_branch: gh-pages
on:
all_branches: true
- provider: releases
api_key:
secure: $GITHUB_TOKEN
file_glob: true
file: com.basistech.m2e.code.quality.site/target/com.basistech.m2e.code.quality.site-*.zip
- provider: script
script: ./tools/release.sh master
skip_cleanup: true
on:
tags: true

after_deploy:
- if [ -n "$TRAVIS_TAG" ]; then ./tools/increment_version.sh $TRAVIS_TAG; fi
18 changes: 10 additions & 8 deletions doc/release.md
@@ -1,7 +1,7 @@
m2e-code-quality build and release
==================================

m2e-code-quality is built with Tycho.
m2e-code-quality is built with Tycho.

To make a release:

Expand All @@ -13,19 +13,21 @@ Tycho has some stupid bug that goes off if you don't start from clean.
3. The index.html at the top of the gh-pages for the m2e-code-quality has some general explanation,
maintain it.

4. When you're satified and all changes are pushed to the develop branch, tag the head
4. Release notes are generated automatically from merged PR and closed issues. If you want some custom
[release summary](https://github.com/github-changelog-generator/github-changelog-generator#using-the-summary-section-feature),
create a new GitHub Issue, set the label `release-summary` and add it to a GitHub milestone named after the inteded
release version (see next section). The description of the issue will then be used as the release summary.

5. When you're satified and all changes are pushed to the develop branch, tag the head
commit with a 3-digit version number (e.g. 1.1.0). This will automatically build a site,
publish it to
publish it to
[https://m2e-code-quality.github.io/m2e-code-quality-p2-site/](https://m2e-code-quality.github.io/m2e-code-quality-p2-site/),
and update the development branch to the next version number. Please note that the produced artifacts
will always have a 4 digit version number, otherwise the release build would be newer then the last snapshot build
in OSGi's version ordering. A release build is marked with a -r version qualifier. This will also produce a
[release](https://github.com/m2e-code-quality/m2e-code-quality/releases) in github.

5. Just in case something failed you can repeat step 4 by moving the tag. A re-spin will completely replace the version
in the P2 repository.

6. Edit the [release](https://github.com/m2e-code-quality/m2e-code-quality/releases) in github and provide some
meaningful release notes.
6. Just in case something failed you can repeat step 5 by moving the tag. A re-spin will completely replace the version
in the P2 repository.

That's it!
10 changes: 5 additions & 5 deletions tools/before_deploy.sh
Expand Up @@ -12,19 +12,19 @@ SITE_NAME="M2E Code Quality - Eclipse Update Site"

##
## adapted from
## https://github.com/jbosstools/jbosstools-build-ci/blob/jbosstools-4.4.x/util/cleanup/jbosstools-cleanup.sh#L255
## https://github.com/jbosstools/jbosstools-build-ci/blob/jbosstools-4.4.x/util/cleanup/jbosstools-cleanup.sh#L255
##
function regenCompositeMetadata () {
subdirs=$1
targetFolder=$2

now=$(date +%s000)

countChildren=0
for sd in $subdirs; do
countChildren=$((countChildren + 1))
done

echo "<?xml version='1.0' encoding='UTF-8'?><?compositeArtifactRepository version='1.0.0'?>
<repository name='${SITE_NAME}' type='org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepository' version='1.0.0'>
<properties size='2'><property name='p2.timestamp' value='${now}'/><property name='p2.compressed' value='true'/></properties>
Expand Down Expand Up @@ -54,7 +54,7 @@ git clone https://github.com/${TRAVIS_REPO_SLUG}-p2-site.git -b ${SITE_GITHUB_BR

## -- integrate (copy) new version to the site
if [ ! -z "$TRAVIS_TAG" ]; then
mkdir ${CURRENT_SITE_FOLDER}/${TRAVIS_TAG} && cp -R ${NEW_SITE_FOLDER}/* ${CURRENT_SITE_FOLDER}/${TRAVIS_TAG}/
rm -rf ${CURRENT_SITE_FOLDER}/${TRAVIS_TAG} && mkdir ${CURRENT_SITE_FOLDER}/${TRAVIS_TAG} && cp -R ${NEW_SITE_FOLDER}/* ${CURRENT_SITE_FOLDER}/${TRAVIS_TAG}/
else
rm -rf ${CURRENT_SITE_FOLDER}/snapshot && mkdir ${CURRENT_SITE_FOLDER}/snapshot && cp -R ${NEW_SITE_FOLDER}/* ${CURRENT_SITE_FOLDER}/snapshot/
fi
Expand Down
37 changes: 0 additions & 37 deletions tools/increment_version.sh

This file was deleted.

68 changes: 68 additions & 0 deletions tools/prepare_release.sh
@@ -0,0 +1,68 @@
#!/bin/bash -eu

[ "$#" -ne "2" ] && echo "usage: $0 <new version> <release branch name>" && exit 1

# stop on first error
set -eu

# configure git
git config --global user.email "travis@travis-ci.org"
git config --global user.name "Travis CI"

# setup origin
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"

# verify same commit as branch
HEAD=$(git rev-parse --verify HEAD)
export GITHUB_BRANCH=$(git ls-remote -q --refs | grep $HEAD | awk '{print $2}' | sed -e 's/^refs\/heads\///')

C=$(echo $GITHUB_BRANCH | wc -w)
if [ "$C" -ne "1" ]; then echo "Tag cannot be resolved to branch name" && exit 1; fi

# make sure no stale stuff before checkout
git reset --hard

# checkout release branch
echo "checkout $2"
git fetch origin > /dev/null 2>&1
git checkout -B $2 origin/$2

# merge develop into release
git merge --no-ff -X ours origin/$GITHUB_BRANCH

# set version and add all changed POMs and add them to the merge commit
echo "changing version to $1"
mvn org.eclipse.tycho:tycho-versions-plugin:set-version -DnewVersion=$1 -Dtycho.mode=maven

# Install github_changelog_generator
gem install github_changelog_generator

# Generate and add CHANGELOG.md
echo "Generating CHANGELOG"
github_changelog_generator -t ${GITHUB_TOKEN} --since-tag 0.12.0.201101081422
git add CHANGELOG.md

# commit changes to branch (will be pushed after release)
git commit -a --amend --message "Release $1 [skip ci]" > /dev/null 2>&1

# Get latest (soon to be previous) release
previous_release_tag=$(curl -s \
https://${GITHUB_TOKEN}@api.github.com/repos/${TRAVIS_REPO_SLUG}/releases/latest | \
jq -r .tag_name)

# Create release notes
github_changelog_generator -t ${GITHUB_TOKEN} --output /tmp/CHANGELOG-$1.md --since-tag ${previous_release_tag}
export RELEASE_CHANGELOG=$(< /tmp/CHANGELOG-$1.md)

# move tag to release branch
git tag -a -f $TRAVIS_TAG -m "Release $TRAVIS_TAG"

# checkout original branch
echo "checkout $GITHUB_BRANCH"
git checkout -B $GITHUB_BRANCH

# merge back release branch to develop
git merge $2

# reset options
set +eu
51 changes: 51 additions & 0 deletions tools/release.sh
@@ -0,0 +1,51 @@
#!/bin/bash -eu

[ "$#" -ne "1" ] && echo "usage: $0 <release branch name>" && exit 1

# move tag and push release branches
git push https://${GITHUB_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git :refs/tags/$TRAVIS_TAG
git push --quiet --atomic --tags https://${GITHUB_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git $1

# Overwrite CHANGELOG.md with JSON data for GitHub API
jq -n \
--arg body "$RELEASE_CHANGELOG" \
--arg name "Release $TRAVIS_TAG" \
--arg tag_name "$TRAVIS_TAG" \
--arg target_commitish "$1" \
'{
body: $body,
name: $name,
tag_name: $tag_name,
target_commitish: $target_commitish,
draft: false,
prerelease: false
}' > /tmp/release.json

# Create release in github
echo "Create release $TRAVIS_TAG for repo: $TRAVIS_REPO_SLUG, branch: $GITHUB_BRANCH"
upload_url=$(curl -s -H "Authorization: token $GITHUB_TOKEN" --data @/tmp/release.json "https://api.github.com/repos/${TRAVIS_REPO_SLUG}/releases" \
| jq -r '.upload_url')

# upload p2 site to release
upload_url="${upload_url%\{*}"

FILES=./com.basistech.m2e.code.quality.site/target/com.basistech.m2e.code.quality.site-*.zip
for f in $FILES
do
echo "uploading $f to $upload_url"
curl -s -H "Authorization: token $GITHUB_TOKEN" \
-H "Content-Type: application/zip" \
--data-binary @"$f" \
"$upload_url?name=$(basename $f)&label=P2%20Repository"
done

# increment version
NEW_VERSION=$(echo $TRAVIS_TAG | awk 'BEGIN { FS="." } { $3++; } { printf "%d.%d.%d\n", $1, $2, $3 }')-SNAPSHOT
echo "changing version to $NEW_VERSION"
mvn org.eclipse.tycho:tycho-versions-plugin:set-version -DnewVersion=$NEW_VERSION -Dtycho.mode=maven

# commit the updated version
git commit -a --message "Next version: $NEW_VERSION" > /dev/null 2>&1

# push updated and development branche
git push --quiet https://${GITHUB_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git $GITHUB_BRANCH
7 changes: 0 additions & 7 deletions tools/update_version.sh

This file was deleted.

0 comments on commit c8461d7

Please sign in to comment.