releases/tools/add_release_note_links.sh
Doug Hellmann 4ee77e9dcd reduce meaningless changes when updating release notes links
If the existing link matches the expected link, leave it in place
regardless of where it is in the file.

If the link needs to be updated, try to insert the link after the
"team" entry, assuming that will be closer to the top of the file
than "releases" and avoiding the need to figure out if "branches" comes
before or after "releases".

Change-Id: I4161bb048deba91ccf8170ea5f0b7208bd9a80a3
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
2017-02-16 14:14:18 -05:00

59 lines
1.7 KiB
Bash
Executable File

#!/bin/bash
#
# Add release notes links to deliverable files when they page exists
# and the link is not already in the file.
#
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
if [ -z "$1" ]; then
echo "Usage: $0 SERIES"
exit 1
fi
SERIES="$1"
function url_exists {
local url="$1"
code=$(curl --silent -I -w "%{http_code}" -o /dev/null "$url")
if [[ $code = 200 ]]; then
return 0
else
return 1
fi
}
for filename in deliverables/$SERIES/*.yaml; do
deliverable=$(basename $filename .yaml)
echo -n $deliverable
url="https://docs.openstack.org/releasenotes/${deliverable}/${SERIES}.html"
if ! url_exists $url; then
echo " no release notes page at $url"
else
new_value="release-notes: $url"
if grep -q "$new_value" $filename; then
echo " OK"
else
# Remove any existing links, since they might point to the
# "unreleased" page.
sed -i -e '/release-notes/d' $filename
# Add the link pointing to the series-specific page.
sed -i -e "/team:.*/a \
$new_value" $filename
echo " updated"
fi
fi
done