Merge "Update cloud image Ubuntu18.04 mininet ovs"
[releng/builder.git] / jjb / autorelease / generate-release-notes.sh
1 #!/bin/bash -l
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 set -x
15
16 # shellcheck disable=SC1090
17 . ~/lf-env.sh
18
19 lf-activate-venv --python python3 "git-review==2.3.1"
20
21 RELEASE=${RELEASE:-$(echo "$GERRIT_EVENT_COMMENT_TEXT" | base64 -d | grep generate-release-notes | awk '{print $2}')}
22 if [ -z "$RELEASE" ]; then
23     echo "ERROR: The RELEASE variable is not set."
24     exit 1
25 fi
26
27 ./scripts/release-notes-generator.sh "$RELEASE"
28
29 # Archive the notes
30 if [ -f  "$WORKSPACE/release-notes.rst" ]; then
31     mkdir -p "$WORKSPACE/archives"
32     cp -f "$WORKSPACE/release-notes.rst" "$WORKSPACE/archives/${RELEASE,,}"
33 fi
34
35 # Generate a docs patch for the notes
36 DOCS_DIR=$(mktemp -d)
37 git clone -b "$GERRIT_BRANCH" https://git.opendaylight.org/gerrit/docs.git "$DOCS_DIR"
38 cd "$DOCS_DIR" || exit 1
39 cp "$WORKSPACE/release-notes.rst" "docs/release-notes/release-notes-${RELEASE,,}.rst"
40 git add docs/release-notes/
41
42 GERRIT_COMMIT_MESSAGE="Update release notes for $RELEASE"
43 GERRIT_TOPIC="autogenerate-release-notes"
44 CHANGE_ID=$(ssh -p 29418 "jenkins-$SILO@git.opendaylight.org" gerrit query \
45                limit:1 owner:self is:open project:docs \
46                message:"$GERRIT_COMMIT_MESSAGE" \
47                topic:"$GERRIT_TOPIC" | \
48                grep 'Change-Id:' | \
49                awk '{{ print $2 }}')
50
51 if [ -z "$CHANGE_ID" ]; then
52     git commit -sm "$GERRIT_COMMIT_MESSAGE"
53 else
54     git commit -sm "$GERRIT_COMMIT_MESSAGE" -m "Change-Id: $CHANGE_ID"
55 fi
56
57 git status
58 git remote add gerrit "ssh://jenkins-$SILO@git.opendaylight.org:29418/docs.git"
59
60 # Workaround for git-review failing to copy the commit-msg hook to submodules
61 git config core.hooksPath "$(git rev-parse --show-toplevel)/.git/hooks"
62
63 # Don't fail the build if this command fails because it's possible that there
64 # is no changes since last update.
65 git review --yes -t "$GERRIT_TOPIC" "$GERRIT_BRANCH" || true