Blame update-version

4e3126d
#!/bin/sh
4e3126d
set -o errexit
4e3126d
set -o nounset
4e3126d
4e3126d
REPO='https://gn.googlesource.com/gn'
4e3126d
4e3126d
# Validate the argument
4e3126d
COMMIT=''
4e3126d
if [ "$#" = '1' ]
4e3126d
then
4e3126d
  if echo "$1" | grep -E '^[[:xdigit:]]{40}$' >/dev/null
4e3126d
  then
4e3126d
    COMMIT="$1"
4e3126d
  fi
4e3126d
elif [ "$#" = '0' ]
4e3126d
then
7e350a4
  COMMIT='main'
4e3126d
fi
4e3126d
if [ -z "${COMMIT}" ]
4e3126d
then
4e3126d
  cat 1>&2 <
4e3126d
Usage: $0 [COMMIT]
4e3126d
4e3126d
Parameters:
4e3126d
  COMMIT - full commit hash from upstream git (${REPO});
7e350a4
           otherwise the latest commit in main is used
4e3126d
EOF
4e3126d
  exit 1
4e3126d
fi
4e3126d
4e3126d
# Generate the version header
4e3126d
SRCDIR="$(cd "$(dirname "$0")"; pwd)"
4e3126d
SPEC="${SRCDIR}/gn.spec"
4e3126d
9709817
SPEC_COMMIT="$(
9709817
  awk '/^%global[[:blank:]]+commit[[:blank:]]+[[:xdigit:]]{40}[[:blank:]]*$/ {
9709817
    print $3; exit
9709817
  }' "${SPEC}"
9709817
)"
9709817
9709817
check_equal_commits() {
9709817
  if [ "${1}" = "${SPEC_COMMIT}" ]
9709817
  then
9709817
    cat 1>&2 <
9709817
Spec file is already up to date at ${SPEC_COMMIT}.
9709817
EOF
9709817
    exit
9709817
  fi
9709817
}
9709817
9709817
if echo "${COMMIT}" | grep -E '^[[:xdigit:]]{40}$' >/dev/null
9709817
then
9709817
  check_equal_commits "${COMMIT}"
9709817
fi
9709817
4e3126d
tmpd="$(mktemp -d)"
4e3126d
trap "rm -rf '${tmpd}'" INT TERM EXIT
4e3126d
4e3126d
cd "${tmpd}"
4e3126d
git clone 'https://gn.googlesource.com/gn'
4e3126d
cd gn
4e3126d
if ! echo "${COMMIT}" | grep -E '^[[:xdigit:]]{40}$' >/dev/null
4e3126d
then
4e3126d
  COMMIT="$(git rev-parse "${COMMIT}")"
9709817
  check_equal_commits "${COMMIT}"
4e3126d
fi
4e3126d
git checkout "${COMMIT}"
4e3126d
python3 './build/gen.py'
4e3126d
cp -vp './out/last_commit_position.h' "${SRCDIR}/"
4e3126d
4e3126d
cd "${SRCDIR}"
4e3126d
4e3126d
# Modify the spec file
4e3126d
POSITION="$(
4e3126d
  awk '
4e3126d
    $1 == "#define" && $2 == "LAST_COMMIT_POSITION_NUM" {
4e3126d
      print $3; exit
4e3126d
    }' 'last_commit_position.h'
4e3126d
)"
4e3126d
4e3126d
sed -r -i \
4e3126d
    -e 's/(%global[[:blank:]]+commit[[:blank:]]+)[[:xdigit:]]{40}[[:blank:]]*$/\1'"${COMMIT}/" \
4e3126d
    -e 's/(%global[[:blank:]]+access[[:blank:]]+)[[:digit:]]{8}[[:blank:]]*$/\1'"$(
4e3126d
      date -u '+%Y%m%d'
4e3126d
    )/" \
4e3126d
    -e 's/(Version:[[:blank:]]+)[[:digit:]]+[[:blank:]]*$/\1'"${POSITION}/" \
4e3126d
    "${SPEC}"
4e3126d
4e3126d
# Download the new tarball
4e3126d
spectool --get-files --directory "${SRCDIR}" "${SPEC}"
4e3126d
4e3126d
# Update the local git repo and upload the new source tarball
4e3126d
fedpkg new-sources "$(
4e3126d
  spectool --list-files "${SPEC}" |
4e3126d
    grep -E '^Source0:' |
4e3126d
    sed -r 's|.*/||'
4e3126d
)"
aade52c
fedpkg commit -m "Update to version ${POSITION}"
2c29c4a
git add 'last_commit_position.h' gn.spec
4e3126d
4e3126d
#  vim: tw=78 ts=2 sw=2 sts=2 et ai nojs