1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
summary: Ensure that the output of snap interface <interface-name> contains an existing url
details: |
Each interface should contain a url pointing to a documentation page found on
snapcraft.io as https://snapcraft.io/docs/<interface-name>-interface. That page
must also exist.
systems: [ubuntu-24.04-64]
execute: |
# Checks to see if the url supplied as the first argument returns an OK HTML status code
webpage_exists() {
local url=$1
local status_code
local num_retries=3
for _ in $(seq $num_retries); do
# Make a HEAD request to the URL and capture the HTTP status code
status_code=$(curl --retry 5 --retry-connrefused -I -o /dev/null -s -w "%{http_code}\n" -k -L --connect-timeout 10 "$url")
# If the status code is 2xx the url is ok
if [ "$status_code" -ge 200 ] && [ "$status_code" -lt 300 ]; then
return 0
fi
# If status code is 500 means the server is not working properly
if [ "$status_code" == 500 ]; then
return 0
fi
# we've sent too many requests. A manual check showed that the server
# doesn't include a Retry-After header so for now just wait a few seconds
# so just wait a couple of seconds before retrying
if [ "$status_code" == 429 ]; then
sleep 5
fi
done
# If status code 4xx is returned then the page is not found, return error
return 1
}
# The exclusion_map contains interfaces that are missing
# documentation. Each key is the name of the interface, while its
# value is the date by which it should have a working URL.
# The expiry date is <expiration year>/<expiration month>
declare -A exclusion_map
# TODO: add documentation page for firmware-updater-support and snap-fde-control
exclusion_map["firmware-updater-support"]="2026/02"
exclusion_map["snap-fde-control"]="2026/02"
exclusion_map["usb-gadget"]="2026/02"
exclusion_map["kerberos-tickets"]="2026/02"
exclusion_map["gbm-driver-libs"]="2026/02"
exclusion_map["opengl-driver-libs"]="2026/02"
exclusion_map["opengles-driver-libs"]="2026/02"
# If the interface is in the exclusion_map and it is currently sooner
# than its specified expiration date, then return true
exclude() {
if [ -v "exclusion_map[$1]" ]; then
local expire_date="${exclusion_map[$1]}"
local year=${expire_date%%/*}
local month=${expire_date#*/}
if [[ $(date '+%Y') -lt $year ]]; then
return 0
fi
if [[ $(date '+%Y') -eq $year ]] && [[ $((10#$(date '+%m'))) -le $((10#$month)) ]]; then
return 0
fi
fi
return 1
}
bad=""
nodoc=""
# Loop through all interfaces
for iface in $(snap interface --all | awk 'NR > 1 {print $1}' | tr '\n' ' '); do
echo "Checking presence of documentation url for interface $iface"
url="https://snapcraft.io/docs/${iface}-interface"
actual="$( snap interface "$iface" )"
if MATCH "documentation: $url" <<<"$actual"; then
if exclude "$iface"; then
echo "Interface $iface excluded"
elif webpage_exists "$url"; then
echo "Interface $iface has webpage"
else
nodoc="$nodoc $iface"
echo "ERROR: Could not find help url for $iface at $url"
fi
else
bad="$bad $iface"
echo
echo "ERROR: The output of 'snap interface $iface' does not contain a documentation entry for $url:"
echo "----------------"
echo "$actual"
echo "----------------"
fi
done
if [ -n "$bad" ]; then
echo "The output of the following interfaces do not contain a documentation entry: $bad"
fi
if [ -n "$nodoc" ]; then
echo "The following interfaces do not have a documentation webpage: $nodoc"
fi
test -z "$bad"
test -z "$nodoc"
|