| 1 |
#!/bin/bash |
| 2 |
# |
| 3 |
# Copyright (C) 2024 The Phosh developers |
| 4 |
# SPDX-License-Identifier: GPL-3.0-or-later |
| 5 |
# Author: Guido Günther <[email protected]> |
| 6 |
# |
| 7 |
# Check if NEWS, changelog, meson and metainfo are in sync |
| 8 |
|
| 9 |
set -e |
| 10 |
|
| 11 |
COLOR= |
| 12 |
if [ -n "${TERM}" ] && [ "${TERM}" != "dumb" ]; then |
| 13 |
COLOR=1 |
| 14 |
fi |
| 15 |
|
| 16 |
function log |
| 17 |
{ |
| 18 |
local level="${1}" |
| 19 |
local fd=2 |
| 20 |
local use_color |
| 21 |
|
| 22 |
shift |
| 23 |
if [ -n "${COLOR}" ]; then |
| 24 |
[ "${level}" == warn ] || [ "${level}" == error ] || fd=1 |
| 25 |
! [ -t "${fd}" ] || use_color=1 |
| 26 |
|
| 27 |
if [ -n "${use_color}" ]; then |
| 28 |
case "${level}" in |
| 29 |
warn) |
| 30 |
tput setaf 1 |
| 31 |
;; |
| 32 |
error) |
| 33 |
tput bold; tput setaf 1 |
| 34 |
;; |
| 35 |
info) |
| 36 |
tput setaf 2 |
| 37 |
;; |
| 38 |
esac |
| 39 |
fi |
| 40 |
fi |
| 41 |
|
| 42 |
echo "$@" |
| 43 |
|
| 44 |
[ -z "${use_color}" ] || tput sgr0 |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
if [ -f debian/changelog ]; then |
| 49 |
log info "Fetching version from d/changelog" |
| 50 |
VERSION=$(dpkg-parsechangelog -SVersion) |
| 51 |
elif [ -f meson.build ]; then |
| 52 |
log info "Fetching version from meson build file" |
| 53 |
VERSION=$(sed -n "s/.*version\s*:\s*'\([0-9].*\)'.*/\1/p" meson.build) |
| 54 |
else |
| 55 |
log error "E: Don't know how to get version information" |
| 56 |
exit 1 |
| 57 |
fi |
| 58 |
|
| 59 |
echo "I: Checking for '${VERSION}'" |
| 60 |
|
| 61 |
# News |
| 62 |
if ! head -1 NEWS | grep -E -qs "\s+${VERSION}\s*$"; then |
| 63 |
log error "E: Version ${VERSION} not in NEWS file" |
| 64 |
if [[ "${VERSION}" =~ (~|-)dev ]]; then |
| 65 |
log info "I: Unreleased development version, no need to check NEWS" |
| 66 |
else |
| 67 |
exit 1 |
| 68 |
fi |
| 69 |
else |
| 70 |
log info "I: Found matching news entry" |
| 71 |
fi |
| 72 |
|
| 73 |
# meson.build |
| 74 |
MESON_VERSION="${VERSION/\~/.}" |
| 75 |
if [ -f meson.build ]; then |
| 76 |
if ! grep -qs "version\s*:\s*'$MESON_VERSION'" meson.build; then |
| 77 |
log error "E: Version ${MESON_VERSION} not in meson.build file" |
| 78 |
exit 1 |
| 79 |
else |
| 80 |
log info "I: Found matching meson version entry" |
| 81 |
fi |
| 82 |
else |
| 83 |
log info "I: no meson project" |
| 84 |
fi |
| 85 |
|
| 86 |
# appstream info |
| 87 |
METAINFO=$(ls data/*metainfo.xml.in* 2>/dev/null || true) |
| 88 |
if [ -z "${METAINFO}" ]; then |
| 89 |
log warn "W: No metainfo" |
| 90 |
exit 0 |
| 91 |
fi |
| 92 |
|
| 93 |
if ! grep -qs "$MESON_VERSION\"" "${METAINFO}"; then |
| 94 |
log error "E: Version ${MESON_VERSION} not in metainfo ${METAINFO}" |
| 95 |
if [[ "${VERSION}" =~ (~|-)(alpha|beta|dev|rc) ]]; then |
| 96 |
log info "I: Not a stable release, no metainfo is fine" |
| 97 |
else |
| 98 |
exit 1 |
| 99 |
fi |
| 100 |
else |
| 101 |
log info "I: Found matching metainfo entry" |
| 102 |
fi |