blob: e626dd9c17cc7e7e9828555c60888140b0a806d3 [file] [log] [blame]
Thomas Kulikbaa07102020-11-16 10:43:15 +01001#!/bin/bash
2#set -x # uncomment for bash script debugging
3
Thomas Kulik2c1f5db2020-11-17 12:37:08 +01004# branch, e.g. "master" or "guilin"
Thomas Kulikbaa07102020-11-16 10:43:15 +01005branch=$1
Thomas Kulik2c1f5db2020-11-17 12:37:08 +01006# logfile produced by checkdocs that contains the list of links
Thomas Kulikbaa07102020-11-16 10:43:15 +01007file_to_process=$2
8
9#
10# NOTE: works NOT with elalto release and below because of the submodule structure used for documentation
11#
12
Thomas Kulik33cf98f2020-11-17 15:09:48 +010013# url
14# important! only doc project needs a different url base
15url_lang="en"
Thomas Kulikbaa07102020-11-16 10:43:15 +010016url_branch=${branch}
Thomas Kulik2c1f5db2020-11-17 12:37:08 +010017unique=$(date +%s)
Thomas Kulikbaa07102020-11-16 10:43:15 +010018
Thomas Kulik33cf98f2020-11-17 15:09:48 +010019# "master" branch documentation is available as "latest" in RTD
20if [[ ${url_branch} == "master" ]]; then
Thomas Kulikbaa07102020-11-16 10:43:15 +010021 url_branch="latest"
22fi
23
24#readarray -t array < ./${branch}_releasenotes.log;
25readarray -t array < ${file_to_process};
26for line in "${array[@]}"
27do
28
Thomas Kulik33cf98f2020-11-17 15:09:48 +010029 reponame=$(echo ${line} | cut -d "[" -f2 | cut -d "]" -f1)
Thomas Kuliked7d4f62020-11-18 15:07:29 +010030 #reponame="[${reponame}]"
Thomas Kulik33cf98f2020-11-17 15:09:48 +010031 #echo "DBUG: reponame=${reponame}"
32
Thomas Kulikbaa07102020-11-16 10:43:15 +010033 # example line: [dmaap/messagerouter/messageservice]/docs/release-notes/release-notes.rst
34 # example url: https://docs.onap.org/projects/onap-dmaap-messagerouter-messageservice/en/frankfurt/release-notes/release-notes.html
35
36 # extract repo name which comes in square bracktes ([...]) and convert slash (/) to minus (-)
37 # line: [dmaap/messagerouter/messageservice]/docs/release-notes/release-notes.rst
38 # output: dmaap-messagerouter-messageservice
39 url_repo=$(echo ${line} | sed -r 's/].+$//' | sed -r 's/\[//' | sed -r 's/\//-/g')
40
41 # extract rst filename and its path; replace .rst ending with .html
42 # warning: path does not always contain "docs"!
43 # line: [dmaap/messagerouter/messageservice]/docs/release-notes/release-notes.rst
44 # output: release-notes/release-notes.html
Thomas Kuliked7d4f62020-11-18 15:07:29 +010045 url_file=$(echo ${line} | sed -r 's/^.+\]//' | sed -r 's/^.*\/docs\///' | sed -r 's/\.rst$/\.html/' )
46
47 #echo "DBUG: line = ${line}"
48 #echo "DBUG: url_file = ${url_file}"
49 #echo "DBUG: url_repo = ${url_repo}"
50 #echo "DBUG: reponame = ${reponame}"
Thomas Kulikbaa07102020-11-16 10:43:15 +010051
52 # build the full url
Thomas Kulik33cf98f2020-11-17 15:09:48 +010053 if [[ ${reponame} == "doc" ]]; then
54 # build the full url for the doc project
55 url_start="https://docs.onap.org"
56 url="${url_start}/${url_lang}/${url_branch}/${url_file}"
57 else
58 # build the full url for the other projects
59 url_start="https://docs.onap.org/projects/onap"
60 url="${url_start}-${url_repo}/${url_lang}/${url_branch}/${url_file}"
61 fi
Thomas Kuliked7d4f62020-11-18 15:07:29 +010062
63 #echo "DBUG: url = $url"
Thomas Kulikbaa07102020-11-16 10:43:15 +010064
65 # check with curl if html page is accessible (no content check!)
Thomas Kulik2c1f5db2020-11-17 12:37:08 +010066 # to prevent (server side) cached results a unique element is added to the request
67 curl --head --silent --fail "${url}?${unique}" >/dev/null
Thomas Kulikbaa07102020-11-16 10:43:15 +010068 curl_result=$?
69
70 # "0" and "22" are expected as a curl result
71 if [ "${curl_result}" = "0" ]; then
Thomas Kulik2c1f5db2020-11-17 12:37:08 +010072 curl_result="accessible"
Thomas Kulikbaa07102020-11-16 10:43:15 +010073 elif [ "${curl_result}" = "22" ]; then
Thomas Kulik33cf98f2020-11-17 15:09:48 +010074 curl_result="does not exist"
Thomas Kulikbaa07102020-11-16 10:43:15 +010075 fi
76
Thomas Kulik2c1f5db2020-11-17 12:37:08 +010077 #echo -e "DBUG: ${line}"
78 #echo -e "DBUG: ${curl_result} ${url}"
79 #echo " "
80
81 echo "${line},${url},${curl_result}"
Thomas Kulikbaa07102020-11-16 10:43:15 +010082
83 ((i++))
84done
85unset array
86unset i