delete ALL old tags
This commit is contained in:
parent
4ddb8de08e
commit
eaf957da50
147
git-retag.sh
Executable file
147
git-retag.sh
Executable file
@ -0,0 +1,147 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# $1 = Module name e.g. smeserver-ddclient
|
||||
# $2 = Organisation (smeserver or smecontrib)e
|
||||
# optional (can be in any order)
|
||||
# <local> will use parameters set for local repository else it will use remote
|
||||
# <debug> turn on debug regardless of ~/.smegit/config
|
||||
# <noisy> print a line showing how it was called
|
||||
# Module name must exist
|
||||
#
|
||||
|
||||
if [[ -z $1 ]] ; then
|
||||
echo "************git-retag.sh <modulename> <organization> [<local> | <debug>]"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
#
|
||||
# Pull in parameters from a config file ~/.smegit/config
|
||||
#
|
||||
inifilename=$(echo ~)"/.smegit/config"
|
||||
if [ ! -e $inifilename ] ; then
|
||||
# Not here, look at system default
|
||||
if [ ! -e /etc/smegit.ini ] ; then
|
||||
echo "No ini file found $inifiename or /etc/smegit.ini"
|
||||
echo "git-retag.sh <modulename> <organization> [<local> | <debug>]"
|
||||
exit 1
|
||||
else
|
||||
initfilename="/etc/smegit.ini"
|
||||
fi
|
||||
fi
|
||||
|
||||
while read -r line || [[ -n "$line" ]]; do
|
||||
if [[ $line =~ ^\[.*\]$ ]]
|
||||
then
|
||||
section=${line#*[}
|
||||
section=${section%]*}
|
||||
else
|
||||
if [[ $line =~ ^[^#]*= ]]
|
||||
then
|
||||
key=${line%=*}
|
||||
value=${line#*=}
|
||||
declare "${section}_${key}=$value"
|
||||
fi
|
||||
fi
|
||||
done < "$inifilename"
|
||||
DEBUG=
|
||||
if [ ${smegit_DEBUG} == "true" ] ; then DEBUG=true ; fi
|
||||
|
||||
GITEAUser=${remote_USER}
|
||||
GITEAACCESSTOKEN=${remote_GITEAACCESSTOKEN}
|
||||
GITEAHOST=${remote_GITEAHOST}
|
||||
NOISY=
|
||||
EXTRAPARAMS=
|
||||
for param in $3 $4 $5 $6 ; do
|
||||
if [ $param ] ; then
|
||||
case $param in
|
||||
local )
|
||||
GITEAUser=${local_USER}
|
||||
GITEAACCESSTOKEN=${local_GITEAACCESSTOKEN}
|
||||
GITEAHOST=${local_GITEAHOST}
|
||||
;;
|
||||
debug )
|
||||
DEBUG=true ;;
|
||||
noisy )
|
||||
NOISY=true ;;
|
||||
* )
|
||||
echo "Unkown parameter: $param"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
else
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [ $NOISY ] ; then echo "git-retag.sh $1 $2 $3 $4 $5 $6" ; fi
|
||||
if [ $DEBUG ] ; then echo "************found ini file: $inifilename" ; fi
|
||||
# Make this null if you want lots of output. Still quite a bit anyway
|
||||
QUIET="-q"
|
||||
SILENT4CURL="-s"
|
||||
SILENT4MAKE="-s"
|
||||
if [ $DEBUG ] ; then
|
||||
QUIET=
|
||||
SILENT4CURL="-v"
|
||||
SILENT4MAKE=
|
||||
fi
|
||||
# Make this null to get curl to check ssl cert
|
||||
checkSSL="-k"
|
||||
|
||||
LOCALUser=${local_USER}
|
||||
if [[ $smegit_WORKDIR == ~* ]] ; then
|
||||
# relative to users home dir
|
||||
WORKDIR=$(echo ~)${smegit_WORKDIR:1}
|
||||
else
|
||||
# absolute path
|
||||
WORKDIR=${smegit_WORKDIR}
|
||||
fi
|
||||
if [ $DEBUG ] ; then echo "WORKDIR=$WORKDIR" ; fi
|
||||
RemoteRepoURL="$GITEAHOST/$2/$1"
|
||||
|
||||
# Make sure credentials taken from store
|
||||
# The first time you pull or push it will ask for credentials and then save them in a file.
|
||||
git config --global credential.helper store
|
||||
|
||||
# Create the local Git repository
|
||||
GITFiles=$WORKDIR/$ORGGITEA
|
||||
mkdir -p $GITFiles
|
||||
cd $GITFiles
|
||||
|
||||
# Delete the local first
|
||||
if [ -d "$1" ] ; then
|
||||
if [ $DEBUG ] ; then echo "************Deleting local GIT files" ; fi
|
||||
rm -Rf $GITFiles/$1
|
||||
fi
|
||||
|
||||
# See if it exists on the Gitea host
|
||||
REPO_NAME=$1
|
||||
if [ $DEBUG ] ; then echo "check that $GITEAHOST/$ORGGITEA/$REPO_NAME exists" ; fi
|
||||
RESPONSE=$(curl $checkSSL $SILENT4CURL -o /dev/null -w "%{http_code}" "$GITEAHOST/api/v1/repos/$ORGGITEA/$REPO_NAME")
|
||||
if [ "$RESPONSE" == "200" ]; then
|
||||
if [ $DEBUG ] ; then echo "************Repository for $1 exists, cloning!" ; fi
|
||||
# If so, clone it (just want the README.md)
|
||||
if [ $DEBUG ] ; then echo "git clone $GITEAHOST/$ORGGITEA/$1.git" ; fi
|
||||
cd $GITFiles
|
||||
git clone "$GITEAHOST/$ORGGITEA/$1.git"
|
||||
else
|
||||
echo "************Repository for $2/$1 does not exist. Aborting"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cd $GITFiles/$1
|
||||
# read the existing tags
|
||||
OLDTAGS=$(git tag --list)
|
||||
# delete old tag/s
|
||||
for tag in $OLDTAGS ; do
|
||||
git tag --delete $tag
|
||||
done
|
||||
# Now create the version and release tag from the specfile
|
||||
RELEASE=`rpm --queryformat '%{release}\n' --specfile $NAME.spec | head -n 1`
|
||||
# Release is not reliable - if you run on Rocky it comes back EL8, centos 7 - EL7
|
||||
# So, we need to just take the build part (first word)
|
||||
TAG=$VERSION"-"${RELEASE%.*}
|
||||
git tag -a $TAG -m "Setting tag to current Version-Release in spec file: $TAG"
|
||||
git push origin $TAG $QUIET
|
||||
|
||||
echo "Created $1 Repo: $HTTP_URL - Comment:$COMMENT tag:$TAG"
|
||||
exit 0
|
Loading…
Reference in New Issue
Block a user