Karsten Hopp 16bcfe
#!/bin/bash
Karsten Hopp 4a08e5
debug=""
Karsten Hopp 56ffd8
#debug="echo "
Zdenek Dohnal ff78c1
branches=( "rawhide" "f35" "f34" )
Zdenek Dohnal ff78c1
releases=( "fc36" "fc35" "fc34" )
Zdenek Dohnal ff78c1
regexps=( "fc36" "\|fc35" "\|fc34" )
Zdenek Dohnal ff78c1
bodhi_enabled=( "0" "1" "1" )
zdohnal 34c6d4
needs_update=()
Zdenek Dohnal 66ccb6
#releases_regexp=fc28\\\|fc27\\\|fc28
Zdenek Dohnal 66ccb6
Zdenek Dohnal 5f35bd
branches_index=0
Zdenek Dohnal 0e0607
release_index=0
Zdenek Dohnal 66ccb6
regexp_index=0
Zdenek Dohnal fbda9b
bodhi_enabled_index=0
Zdenek Dohnal 468749
done_build=0
Zdenek Dohnal 7e14bc
releases_regexp=""
Zdenek Dohnal 66ccb6
let "regexp_index+=1"
Karsten Hopp 16bcfe
Karsten Hopp 722559
cd `dirname $0`
Karsten Hopp 16bcfe
LANG=C
Karsten Hopp 16bcfe
SPEC=vim.spec
Karsten Hopp 56ffd8
CHANGES=1
Karsten Hopp 87222e
force=0
Karsten Hopp 87222e
Karsten Hopp 87222e
if [ "x$1" == "x--force" ]; then
Karsten Hopp 87222e
  force=1
Karsten Hopp 87222e
fi
Karsten Hopp 16bcfe
Karsten Hopp 16bcfe
DATE=`date +"%a %b %d %Y"`
Zdenek Dohnal 6e7834
$debug fedpkg switch-branch "${branches[@]: $branches_index: 1}"
Zdenek Dohnal e51544
Zdenek Dohnal b26d69
Zdenek Dohnal b26d69
if [ $? -ne 0 ]; then
Zdenek Dohnal b26d69
  echo "Error with switching branch"
Zdenek Dohnal b26d69
  exit 1
Zdenek Dohnal b26d69
fi
Zdenek Dohnal b26d69
Karsten Hopp 16bcfe
MAJORVERSION=`grep "define baseversion" vim.spec | cut -d ' ' -f 3`
Zdenek Dohnal 59beea
MAJORVERDIR=$(echo $MAJORVERSION | sed -e 's/\.//')
Zdenek Dohnal c33193
EPOCH=`grep "Epoch:" vim.spec | cut -d ':' -f 2`
Zdenek Dohnal c33193
PACKAGER=`rpmdev-packager`
Karsten Hopp 4a08e5
ORIGPL=`grep "define patchlevel" vim.spec | cut -d ' ' -f 3 | sed -e "s/^0*//g"`
Karsten Hopp 4a08e5
ORIGPLFILLED=`printf "%03d" $ORIGPL`
Karsten Hopp 16bcfe
Karsten Hopp 56ffd8
if [ ! -d vim-upstream ]; then
Karsten Hopp 56ffd8
   git clone https://github.com/vim/vim.git vim-upstream
Karsten Hopp bba8e9
else
Karsten Hopp 56ffd8
   pushd vim-upstream
Karsten Hopp 56ffd8
   git pull
Karsten Hopp 56ffd8
   popd
Karsten Hopp 56ffd8
fi
Karsten Hopp 56ffd8
Karsten Hopp 56ffd8
pushd vim-upstream
Zdenek Dohnal 66ccb6
Karsten Hopp 871038
# get the latest tag. Might be tricky with other packages, but upstream vim uses just a single branch:
Karsten Hopp 56ffd8
LASTTAG=$(git describe --tags $(git rev-list --tags --max-count=1))
Zdenek Dohnal 66ccb6
Karsten Hopp 871038
# vim upstream tags have the form v7.4.123. Remove the 'v' and get major release and patchlevel:
Karsten Hopp 56ffd8
UPSTREAMMAJOR=$(echo $LASTTAG | sed -e 's/v\([0-9]*\.[0-9]*\).*/\1/')
Zdenek Dohnal 59beea
UPSTREAMMAJORDIR=$(echo $UPSTREAMMAJOR | sed -e 's/\.//')
Karsten Hopp 73a6a7
LASTPL=`echo $LASTTAG| sed -e 's/.*\.//;s/^0*//'`
Karsten Hopp 56ffd8
LASTPLFILLED=`printf "%03d" $LASTPL`
Karsten Hopp 87222e
if [ $force -ne 1 -a "$ORIGPLFILLED" == "$LASTPLFILLED" ]; then
Karsten Hopp 56ffd8
    echo "No new patchlevel available"
Karsten Hopp 56ffd8
    CHANGES=0
Karsten Hopp 56ffd8
fi
Karsten Hopp 56ffd8
rm -rf dist/* 2>/dev/null
Karsten Hopp 56ffd8
make unixall
Zdenek Dohnal 66ccb6
Karsten Hopp 871038
# include patchlevel in tarball name so that older sources won't get overwritten:
Karsten Hopp 56ffd8
mv dist/vim-${UPSTREAMMAJOR}.tar.bz2 dist/vim-${UPSTREAMMAJOR}-${LASTPLFILLED}.tar.bz2
Zdenek Dohnal 66ccb6
Karsten Hopp 871038
# We don't include the full upstream changelog in the rpm changelog, just ship a file with
Karsten Hopp 871038
# the changes:
Karsten Hopp 56ffd8
popd
Karsten Hopp 56ffd8
Karsten Hopp 56ffd8
cp -f vim-upstream/dist/vim-${UPSTREAMMAJOR}-${LASTPLFILLED}.tar.bz2 .
Zdenek Dohnal 148131
#wget https://raw.githubusercontent.com/ignatenkobrain/vim-spec-plugin/rawhide/ftplugin/spec.vim -O ftplugin-spec.vim
Zdenek Dohnal 148131
#wget https://raw.githubusercontent.com/ignatenkobrain/vim-spec-plugin/rawhide/syntax/spec.vim -O syntax-spec.vim
Karsten Hopp bcbb2a
if [ $CHANGES -ne 0 ]; then
Zdenek Dohnal f55f59
   CHLOG="* $DATE $PACKAGER -$EPOCH:$UPSTREAMMAJOR"
Karsten Hopp 871038
   $debug sed -i -e "/Release: /cRelease: 1%{?dist}" $SPEC
Karsten Hopp 871038
   if [ "x$MAJORVERSION" != "x$UPSTREAMMAJOR" ]; then
Zdenek Dohnal 59beea
      $debug sed -i -s "s/define baseversion $MAJORVERSION/define baseversion $UPSTREAMMAJOR/" $SPEC
Zdenek Dohnal 59beea
      $debug sed -i -s "s/define vimdir vim$MAJORVERDIR/define vimdir vim$UPSTREAMMAJORDIR/" $SPEC
Karsten Hopp 871038
   fi
Karsten Hopp 871038
   $debug sed -i -e "s/define patchlevel $ORIGPLFILLED/define patchlevel $LASTPLFILLED/" $SPEC
Karsten Hopp 871038
   $debug sed -i -e "/\%changelog/a$CHLOG.$LASTPLFILLED-1\n- patchlevel $LASTPLFILLED\n" $SPEC
Karsten Hopp 871038
   $debug fedpkg new-sources vim-${UPSTREAMMAJOR}-${LASTPLFILLED}.tar.bz2
Zdenek Dohnal c48460
   $debug git add vim.spec
Karsten Hopp 871038
   $debug git commit -m "- patchlevel $LASTPL" 
Zdenek Dohnal 66ccb6
Zdenek Dohnal 5f35bd
   # mockbuild
Zdenek Dohnal b26d69
   $debug fedpkg mockbuild
Zdenek Dohnal d6afc6
   if [ $? -ne 0 ]; then
Zdenek Dohnal d6afc6
     echo "Error: fedpkg mockbuild"
Zdenek Dohnal d6afc6
     exit 1
Zdenek Dohnal 5f35bd
   fi
Zdenek Dohnal 66ccb6
Zdenek Dohnal 5f35bd
   # push
Zdenek Dohnal d6afc6
   $debug fedpkg push
Zdenek Dohnal 9a6f13
   if [ $? -ne 0 ]; then
Zdenek Dohnal d6afc6
     echo "Error: fedpkg push"
Zdenek Dohnal d6afc6
     exit 1
Zdenek Dohnal e51544
   fi
Zdenek Dohnal 66ccb6
Zdenek Dohnal 7e14bc
   $debug fedpkg build
Zdenek Dohnal 7e14bc
   if [ $? -eq 0 ]; then
Zdenek Dohnal 7e14bc
     done_build=1
Zdenek Dohnal 53e324
   else
Zdenek Dohnal 7e14bc
     echo "Error when building package in $branch"
Zdenek Dohnal 7e14bc
     exit 1
Zdenek Dohnal 5f35bd
   fi
Zdenek Dohnal 53e324
Zdenek Dohnal 9bf4b1
   let "release_index+=1"
Zdenek Dohnal fbda9b
   let "bodhi_enabled_index+=1"
Zdenek Dohnal 9bf4b1
Zdenek Dohnal 5f35bd
   for branch in "${branches[@]:(1)}";
Zdenek Dohnal 5f35bd
   do
Zdenek Dohnal 5f35bd
     # switch to branch
Zdenek Dohnal 5f35bd
     $debug fedpkg switch-branch $branch
Zdenek Dohnal 66ccb6
Zdenek Dohnal 5f35bd
     # merge with previous branch
Zdenek Dohnal 5f35bd
     $debug bash -c "git merge ${branches[@]: $branches_index: 1} <<<':x'"
Zdenek Dohnal 5f35bd
     if [ $? -ne 0 ]; then
Zdenek Dohnal 5f35bd
       echo "Error: git merge ${branches[@]: $branches_index: 1}"
Zdenek Dohnal 5f35bd
       exit 1
Zdenek Dohnal 5f35bd
     fi
Zdenek Dohnal 66ccb6
Zdenek Dohnal 5f35bd
     # mockbuild
Zdenek Dohnal 5f35bd
     $debug fedpkg mockbuild
Zdenek Dohnal 5f35bd
     if [ $? -ne 0 ]; then
Zdenek Dohnal 5f35bd
       echo "Error: fedpkg mockbuild failed"
Zdenek Dohnal 5f35bd
       exit 1
Zdenek Dohnal 5f35bd
     fi
Zdenek Dohnal 66ccb6
Zdenek Dohnal 5f35bd
     # push
Zdenek Dohnal 5f35bd
     $debug fedpkg push
Zdenek Dohnal 5f35bd
     if [ $? -ne 0 ]; then
Zdenek Dohnal 5f35bd
       echo "Error: fedpkg push"
Zdenek Dohnal 5f35bd
       exit 1
Zdenek Dohnal 5f35bd
     fi
Zdenek Dohnal 66ccb6
Zdenek Dohnal 7e14bc
     # append next release to regexp if the branch is enabled in bodhi - because we
Zdenek Dohnal 7e14bc
     # need to check if there aren't any testing updates from higher enabled branches
Zdenek Dohnal 7e14bc
     # (lower branch cannot have bigger NVR than higher branch) in next iteration
Zdenek Dohnal 7e14bc
     if [ ${bodhi_enabled[@]: $bodhi_enabled_index: 1} -eq 1 ]
Zdenek Dohnal 7e14bc
     then
Zdenek Dohnal 7e14bc
       releases_regexp="$releases_regexp${regexps[@]: regexp_index: 1}"
Zdenek Dohnal 7e14bc
     fi
Zdenek Dohnal 66ccb6
Zdenek Dohnal 5f35bd
     # Check if release has pending or testing update - if not, build package
Zdenek Dohnal e68ece
     # and submit update for testing
Zdenek Dohnal 0c733d
     #  | grep $releases_regexp`
Zdenek Dohnal fbda9b
     # done_build is checking, if previous branch did build - lower branch can do
Zdenek Dohnal fbda9b
     # a build only when higher branch build was ok.
Zdenek Dohnal 5f35bd
     testing_update=`bodhi updates query --packages vim --status testing \
Zdenek Dohnal e68ece
       | grep $releases_regexp`
Zdenek Dohnal de9328
     if [ "$testing_update" == "" ] && [ $done_build -eq 1 ]; then
Zdenek Dohnal 6e7834
       $debug fedpkg build
Zdenek Dohnal e68ece
       if [ $? -eq 0 ]; then
Zdenek Dohnal 7e14bc
         # if branch isn't rawhide or branch is enabled in bodhi, suggest creating update in the end
Zdenek Dohnal 148131
         if [ $branch != "rawhide" ] || [ ${bodhi_enabled[@]: $bodhi_enabled_index: 1} -eq 1 ]; then
zdohnal 34c6d4
           needs_update+=("bodhi updates new --user $(rpmdev-packager) --type enhancement --notes \"The newest upstream commit\" --request testing --autotime --autokarma --stable-karma 3 --unstable-karma -3 vim-${UPSTREAMMAJOR}.${LASTPLFILLED}-1.${releases[@]: $release_index: 1}")
Zdenek Dohnal e68ece
         fi
Zdenek Dohnal e68ece
       else
Zdenek Dohnal e68ece
         echo "Error when building package for $branch"
Zdenek Dohnal e68ece
         exit 1
Zdenek Dohnal 53e324
       fi
Zdenek Dohnal 468749
     else
Zdenek Dohnal 468749
       done_build=0
Zdenek Dohnal 5f35bd
     fi
Zdenek Dohnal 53e324
Zdenek Dohnal fbda9b
     # Increment index
Zdenek Dohnal 8354e6
     let "branches_index+=1"
Zdenek Dohnal 9bf4b1
     let "release_index+=1"
Zdenek Dohnal 66ccb6
     let "regexp_index+=1"
Zdenek Dohnal fbda9b
     let "bodhi_enabled_index+=1"
Zdenek Dohnal 5f35bd
   done
Zdenek Dohnal b26d69
   #$debug git push
Zdenek Dohnal b26d69
   #if [ $? -eq 0 ]; then
Zdenek Dohnal b26d69
   #   $debug rm -f $HOME/.koji/config
Zdenek Dohnal b26d69
   #   $debug fedpkg build
Zdenek Dohnal b26d69
   #   $debug ln -sf ppc-config $HOME/.koji/config
Zdenek Dohnal b26d69
   #else
Zdenek Dohnal b26d69
   #   echo "GIT push failed"
Zdenek Dohnal b26d69
   #fi
Karsten Hopp bba8e9
fi
Zdenek Dohnal 85fe8c
Zdenek Dohnal 148131
#go back to rawhide
Zdenek Dohnal 148131
$debug fedpkg switch-branch rawhide
Zdenek Dohnal 85fe8c
Zdenek Dohnal fd9785
# clean up the downloaded vim-upstream repo - to prevent changes in it and breaking update process
Zdenek Dohnal fd9785
# prevents #1931099
Zdenek Dohnal fd9785
$debug rm -rf vim-upstream
Zdenek Dohnal fd9785
zdohnal 34c6d4
if [ ${#needs_update[@]} -eq 0 ]
zdohnal 34c6d4
then
zdohnal 34c6d4
  exit 0
zdohnal 34c6d4
fi
zdohnal 34c6d4
zdohnal 34c6d4
echo "Issue the following commands once its gating tests pass:"
zdohnal 34c6d4
zdohnal 34c6d4
for update in "${needs_update[@]}"
zdohnal 34c6d4
do
zdohnal 34c6d4
  echo $update
zdohnal 34c6d4
done
zdohnal 34c6d4
Zdenek Dohnal d6afc6
exit 0