16bcfe0
#!/bin/bash
4a08e5d
debug=""
56ffd8a
#debug="echo "
5f35bde
branches=( "f25" "f26" "f27" "master" )
53e3240
releases=( "fc26" "fc26" "fc27" "fc28" )
53e3240
branches_count=4
53e3240
releases_regexp=fc25\\\|fc26\\\|fc27\\\|fc28
5f35bde
branches_index=0
0e06071
release_index=0
16bcfe0
722559b
cd `dirname $0`
16bcfe0
LANG=C
16bcfe0
SPEC=vim.spec
56ffd8a
CHANGES=1
87222ef
force=0
87222ef
87222ef
if [ "x$1" == "x--force" ]; then
87222ef
  force=1
87222ef
fi
16bcfe0
16bcfe0
DATE=`date +"%a %b %d %Y"`
5f35bde
fedpkg switch-branch "${branches[@]: $branches_index: 1}"
e51544b
b26d699
b26d699
if [ $? -ne 0 ]; then
b26d699
  echo "Error with switching branch"
b26d699
  exit 1
b26d699
fi
b26d699
16bcfe0
MAJORVERSION=`grep "define baseversion" vim.spec | cut -d ' ' -f 3`
4a08e5d
ORIGPL=`grep "define patchlevel" vim.spec | cut -d ' ' -f 3 | sed -e "s/^0*//g"`
4a08e5d
ORIGPLFILLED=`printf "%03d" $ORIGPL`
16bcfe0
56ffd8a
if [ ! -d vim-upstream ]; then
56ffd8a
   git clone https://github.com/vim/vim.git vim-upstream
bba8e96
else
56ffd8a
   pushd vim-upstream
56ffd8a
   git pull
56ffd8a
   popd
56ffd8a
fi
56ffd8a
56ffd8a
pushd vim-upstream
8710382
# get the latest tag. Might be tricky with other packages, but upstream vim uses just a single branch:
56ffd8a
LASTTAG=$(git describe --tags $(git rev-list --tags --max-count=1))
8710382
# vim upstream tags have the form v7.4.123. Remove the 'v' and get major release and patchlevel:
56ffd8a
UPSTREAMMAJOR=$(echo $LASTTAG | sed -e 's/v\([0-9]*\.[0-9]*\).*/\1/')
73a6a78
LASTPL=`echo $LASTTAG| sed -e 's/.*\.//;s/^0*//'`
56ffd8a
LASTPLFILLED=`printf "%03d" $LASTPL`
87222ef
if [ $force -ne 1 -a "$ORIGPLFILLED" == "$LASTPLFILLED" ]; then
56ffd8a
    echo "No new patchlevel available"
56ffd8a
    CHANGES=0
56ffd8a
fi
56ffd8a
rm -rf dist/* 2>/dev/null
56ffd8a
make unixall
8710382
# include patchlevel in tarball name so that older sources won't get overwritten:
56ffd8a
mv dist/vim-${UPSTREAMMAJOR}.tar.bz2 dist/vim-${UPSTREAMMAJOR}-${LASTPLFILLED}.tar.bz2
8710382
# We don't include the full upstream changelog in the rpm changelog, just ship a file with
8710382
# the changes:
56ffd8a
popd
56ffd8a
56ffd8a
cp -f vim-upstream/dist/vim-${UPSTREAMMAJOR}-${LASTPLFILLED}.tar.bz2 .
ec1b06f
#wget https://raw.githubusercontent.com/ignatenkobrain/vim-spec-plugin/master/ftplugin/spec.vim -O ftplugin-spec.vim
ec1b06f
#wget https://raw.githubusercontent.com/ignatenkobrain/vim-spec-plugin/master/syntax/spec.vim -O syntax-spec.vim
bcbb2a2
if [ $CHANGES -ne 0 ]; then
8710382
   CHLOG="* $DATE Karsten Hopp <karsten@redhat.com> $UPSTREAMMAJOR"
8710382
   $debug sed -i -e "/Release: /cRelease: 1%{?dist}" $SPEC
8710382
   if [ "x$MAJORVERSION" != "x$UPSTREAMMAJOR" ]; then
8710382
      $debug sed -i -s "s/define baseversion: $MAJORVERSION/define baseversion: $UPSTREAMMAJOR=/" $SPEC
8710382
   fi
8710382
   $debug sed -i -e "s/define patchlevel $ORIGPLFILLED/define patchlevel $LASTPLFILLED/" $SPEC
8710382
   $debug sed -i -e "/\%changelog/a$CHLOG.$LASTPLFILLED-1\n- patchlevel $LASTPLFILLED\n" $SPEC
8710382
   $debug fedpkg new-sources vim-${UPSTREAMMAJOR}-${LASTPLFILLED}.tar.bz2
c48460c
   $debug git add vim.spec
8710382
   $debug git commit -m "- patchlevel $LASTPL" 
5f35bde
   # mockbuild
b26d699
   $debug fedpkg mockbuild
d6afc62
   if [ $? -ne 0 ]; then
d6afc62
     echo "Error: fedpkg mockbuild"
d6afc62
     exit 1
5f35bde
   fi
5f35bde
   # push
d6afc62
   $debug fedpkg push
9a6f130
   if [ $? -ne 0 ]; then
d6afc62
     echo "Error: fedpkg push"
d6afc62
     exit 1
e51544b
   fi
5f35bde
   # Check if release has pending or testing update - if not, build package
e68ece3
   # and submit update for testing
5f35bde
   pending_update=`bodhi updates query --packages vim --status pending \
e68ece3
     | grep $releases_regexp`
5f35bde
   testing_update=`bodhi updates query --packages vim --status testing \
e68ece3
     | grep $releases_regexp`
0e06071
   # Cut the head of releases_regexp string
0e06071
   releases_regexp=${releases_regexp#*|}
0e06071
5f35bde
   if [ "$pending_update" == "" ] && [ "$testing_update" == "" ]; then
e68ece3
     fedpkg build
e68ece3
     if [ $? -eq 0 ]; then
5913e8a
       bodhi updates new --user zdohnal --type enhancement --notes "The newest upstream commit" --request testing --autokarma --stable-karma 3 --unstable-karma -3 vim-${UPSTREAMMAJOR}.${LASTPLFILLED}-1.${releases[@]: $release_index: 1}
e68ece3
     else
e68ece3
       echo "Error when building package in $branch"
e68ece3
       exit 1
e68ece3
     fi
53e3240
   else
53e3240
     echo "There are pending/testing updates, do not build package."
5f35bde
   fi
53e3240
9bf4b17
   let "release_index+=1"
9bf4b17
5f35bde
   for branch in "${branches[@]:(1)}";
5f35bde
   do
5f35bde
     # switch to branch
5f35bde
     $debug fedpkg switch-branch $branch
5f35bde
     # merge with previous branch
5f35bde
     $debug bash -c "git merge ${branches[@]: $branches_index: 1} <<<':x'"
5f35bde
     if [ $? -ne 0 ]; then
5f35bde
       echo "Error: git merge ${branches[@]: $branches_index: 1}"
5f35bde
       exit 1
5f35bde
     fi
5f35bde
     # mockbuild
5f35bde
     $debug fedpkg mockbuild
5f35bde
     if [ $? -ne 0 ]; then
5f35bde
       echo "Error: fedpkg mockbuild failed"
5f35bde
       exit 1
5f35bde
     fi
5f35bde
     # push
5f35bde
     $debug fedpkg push
5f35bde
     if [ $? -ne 0 ]; then
5f35bde
       echo "Error: fedpkg push"
5f35bde
       exit 1
5f35bde
     fi
5f35bde
     # Check if release has pending or testing update - if not, build package
e68ece3
     # and submit update for testing
5f35bde
     pending_update=`bodhi updates query --packages vim --status pending \
e68ece3
       | grep $releases_regexp`
5f35bde
     testing_update=`bodhi updates query --packages vim --status testing \
e68ece3
       | grep $releases_regexp`
5f35bde
     if [ "$pending_update" == "" ] && [ "$testing_update" == "" ]; then
e68ece3
       fedpkg build
e68ece3
       if [ $? -eq 0 ]; then
5913e8a
         if [ $branch != "master" ]; then
5913e8a
           bodhi updates new --user zdohnal --type enhancement --notes "The newest upstream commit" --request testing --autokarma --stable-karma 3 --unstable-karma -3 vim-${UPSTREAMMAJOR}.${LASTPLFILLED}-1.${releases[@]: $release_index: 1}
e68ece3
         fi
e68ece3
       else
e68ece3
         echo "Error when building package for $branch"
e68ece3
         exit 1
53e3240
       fi
5f35bde
     fi
53e3240
0e06071
     # Increment index and cut the head of releases_regexp string
8354e62
     let "branches_index+=1"
9bf4b17
     let "release_index+=1"
53e3240
     releases_regexp=${releases_regexp#*|}
5f35bde
   done
b26d699
   #$debug git push
b26d699
   #if [ $? -eq 0 ]; then
b26d699
   #   $debug rm -f $HOME/.koji/config
b26d699
   #   $debug fedpkg build
b26d699
   #   $debug ln -sf ppc-config $HOME/.koji/config
b26d699
   #else
b26d699
   #   echo "GIT push failed"
b26d699
   #fi
bba8e96
fi
d6afc62
exit 0