Submit release notes to docs project
[releng/builder.git] / jjb / autorelease / generate-release-notes.sh
1 #!/bin/bash -x
2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2017 The Linux Foundation and others.
5 #
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Eclipse Public License v1.0
8 # which accompanies this distribution, and is available at
9 # http://www.eclipse.org/legal/epl-v10.html
10 ##############################################################################
11 # This script generates Service Release notes and appends them to the release
12 # notes in the docs project and submits a patch.
13
14 RELEASE=${RELEASE:-$(echo "$GERRIT_EVENT_COMMENT_TEXT" | grep generate-release-notes | awk '{print $2}')}
15 if [ -z "$RELEASE" ]; then
16     echo "ERROR: The RELEASE variable is not set."
17     exit 1
18 fi
19
20 ./scripts/release-notes-generator.sh "$RELEASE"
21
22 # Archive the notes
23 if [ -f  "$WORKSPACE/release-notes.rst" ]; then
24     mkdir -p "$WORKSPACE/archives"
25     cp -f "$WORKSPACE/release-notes.rst" "$WORKSPACE/archives/${RELEASE,,}"
26 fi
27
28 # Generate a docs patch for the notes
29 DOCS_DIR=$(mktemp -d)
30 git clone -b "$GERRIT_BRANCH" https://git.opendaylight.org/gerrit/docs.git "$DOCS_DIR"
31 cd "$DOCS_DIR" || exit 1
32 cp "$WORKSPACE/release-notes.rst" "docs/release-notes/release-notes-${RELEASE,,}.rst"
33 git add docs/release-notes/
34
35 GERRIT_COMMIT_MESSAGE="Update release notes"
36 GERRIT_TOPIC="autogenerate-release-notes"
37 CHANGE_ID=$(ssh -p 29418 "jenkins-$SILO@git.opendaylight.org" gerrit query \
38                limit:1 owner:self is:open project:docs \
39                message:"$GERRIT_COMMIT_MESSAGE" \
40                topic:"$GERRIT_TOPIC" | \
41                grep 'Change-Id:' | \
42                awk '{{ print $2 }}')
43
44 if [ -z "$CHANGE_ID" ]; then
45     git commit -sm "$GERRIT_COMMIT_MESSAGE"
46 else
47     git commit -sm "$GERRIT_COMMIT_MESSAGE" -m "Change-Id: $CHANGE_ID"
48 fi
49
50 git status
51 git remote add gerrit "ssh://jenkins-$SILO@git.opendaylight.org:29418/docs.git"
52
53 # Don't fail the build if this command fails because it's possible that there
54 # is no changes since last update.
55 git review --yes -t "$GERRIT_TOPIC" || true