Thomas Kulik | baa0710 | 2020-11-16 10:43:15 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | #set -x # uncomment for bash script debugging |
| 3 | |
Thomas Kulik | 2c1f5db | 2020-11-17 12:37:08 +0100 | [diff] [blame] | 4 | # branch, e.g. "master" or "guilin" |
Thomas Kulik | baa0710 | 2020-11-16 10:43:15 +0100 | [diff] [blame] | 5 | branch=$1 |
Thomas Kulik | 2c1f5db | 2020-11-17 12:37:08 +0100 | [diff] [blame] | 6 | # logfile produced by checkdocs that contains the list of links |
Thomas Kulik | baa0710 | 2020-11-16 10:43:15 +0100 | [diff] [blame] | 7 | file_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 Kulik | 33cf98f | 2020-11-17 15:09:48 +0100 | [diff] [blame] | 13 | # url |
| 14 | # important! only doc project needs a different url base |
| 15 | url_lang="en" |
Thomas Kulik | baa0710 | 2020-11-16 10:43:15 +0100 | [diff] [blame] | 16 | url_branch=${branch} |
Thomas Kulik | 2c1f5db | 2020-11-17 12:37:08 +0100 | [diff] [blame] | 17 | unique=$(date +%s) |
Thomas Kulik | baa0710 | 2020-11-16 10:43:15 +0100 | [diff] [blame] | 18 | |
Thomas Kulik | 33cf98f | 2020-11-17 15:09:48 +0100 | [diff] [blame] | 19 | # "master" branch documentation is available as "latest" in RTD |
| 20 | if [[ ${url_branch} == "master" ]]; then |
Thomas Kulik | baa0710 | 2020-11-16 10:43:15 +0100 | [diff] [blame] | 21 | url_branch="latest" |
| 22 | fi |
| 23 | |
| 24 | #readarray -t array < ./${branch}_releasenotes.log; |
| 25 | readarray -t array < ${file_to_process}; |
| 26 | for line in "${array[@]}" |
| 27 | do |
| 28 | |
Thomas Kulik | 33cf98f | 2020-11-17 15:09:48 +0100 | [diff] [blame] | 29 | reponame=$(echo ${line} | cut -d "[" -f2 | cut -d "]" -f1) |
Thomas Kulik | ed7d4f6 | 2020-11-18 15:07:29 +0100 | [diff] [blame] | 30 | #reponame="[${reponame}]" |
Thomas Kulik | 33cf98f | 2020-11-17 15:09:48 +0100 | [diff] [blame] | 31 | #echo "DBUG: reponame=${reponame}" |
| 32 | |
Thomas Kulik | baa0710 | 2020-11-16 10:43:15 +0100 | [diff] [blame] | 33 | # 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 Kulik | ed7d4f6 | 2020-11-18 15:07:29 +0100 | [diff] [blame] | 45 | 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 Kulik | baa0710 | 2020-11-16 10:43:15 +0100 | [diff] [blame] | 51 | |
| 52 | # build the full url |
Thomas Kulik | 33cf98f | 2020-11-17 15:09:48 +0100 | [diff] [blame] | 53 | 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 Kulik | ed7d4f6 | 2020-11-18 15:07:29 +0100 | [diff] [blame] | 62 | |
| 63 | #echo "DBUG: url = $url" |
Thomas Kulik | baa0710 | 2020-11-16 10:43:15 +0100 | [diff] [blame] | 64 | |
| 65 | # check with curl if html page is accessible (no content check!) |
Thomas Kulik | 2c1f5db | 2020-11-17 12:37:08 +0100 | [diff] [blame] | 66 | # to prevent (server side) cached results a unique element is added to the request |
| 67 | curl --head --silent --fail "${url}?${unique}" >/dev/null |
Thomas Kulik | baa0710 | 2020-11-16 10:43:15 +0100 | [diff] [blame] | 68 | curl_result=$? |
| 69 | |
| 70 | # "0" and "22" are expected as a curl result |
| 71 | if [ "${curl_result}" = "0" ]; then |
Thomas Kulik | 2c1f5db | 2020-11-17 12:37:08 +0100 | [diff] [blame] | 72 | curl_result="accessible" |
Thomas Kulik | baa0710 | 2020-11-16 10:43:15 +0100 | [diff] [blame] | 73 | elif [ "${curl_result}" = "22" ]; then |
Thomas Kulik | 33cf98f | 2020-11-17 15:09:48 +0100 | [diff] [blame] | 74 | curl_result="does not exist" |
Thomas Kulik | baa0710 | 2020-11-16 10:43:15 +0100 | [diff] [blame] | 75 | fi |
| 76 | |
Thomas Kulik | 2c1f5db | 2020-11-17 12:37:08 +0100 | [diff] [blame] | 77 | #echo -e "DBUG: ${line}" |
| 78 | #echo -e "DBUG: ${curl_result} ${url}" |
| 79 | #echo " " |
| 80 | |
| 81 | echo "${line},${url},${curl_result}" |
Thomas Kulik | baa0710 | 2020-11-16 10:43:15 +0100 | [diff] [blame] | 82 | |
| 83 | ((i++)) |
| 84 | done |
| 85 | unset array |
| 86 | unset i |