Skip to content

Instantly share code, notes, and snippets.

@shawn111
Created March 1, 2018 06:58
Show Gist options
  • Save shawn111/9155b47e24718d9c321f3f095b584dfb to your computer and use it in GitHub Desktop.
Save shawn111/9155b47e24718d9c321f3f095b584dfb to your computer and use it in GitHub Desktop.
#!/bin/bash
# This script add git commit info in spec `Release`
# https://fedoraproject.org/wiki/Archive:Tools/RPM/VersionComparison?rd=Tools/RPM/VersionComparison
#
# eg.
# (1)
# prev version (tag) 1.5
# new version still 1.5 but we want to modify the spec
# * don't change any version (version/ release)
# * this script would create release like $release_<2>_<hash>
# * once everything good, bump the release
#
# (2)
# prev version (tag) 1.5
# new version 1.6
# * change version as 1.6
# * change release with prefix testing$release
# * this script would create release like $release_<2>_<hash>
# * once everything good, the release init number as 0
filename=$(basename "$1")
extension="${filename##*.}"
filename="${filename%.*}"
echo $extension
if [[ "$extension" != "spec" ]]; then
echo "not a spec file"
exit 1
fi
TAG=$(git describe --tags --dirty --always --abbrev=0)
FULLTAG=$(git describe --tags --dirty --always)
if [[ "$FULLTAG" == "$TAG" ]]; then
echo "run rpmbuild directly"
echo $ rpmbuild -bs $1
exit 0
elif [[ "$FULLTAG" == *"$TAG"* ]]; then
NUM=${#TAG}
DIRTY=${FULLTAG:$NUM:12}
DIRTY=${DIRTY//-/_}
else
echo "you need commit change first, and don't forget to push code"
exit 1
fi
sed '1,${/^Release:/s/$/'"$DIRTY"'/}' $1 > /tmp/$filename.spec
rpmbuild -bs /tmp/$filename.spec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment