Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #!/bin/bash
  2.  
  3. usage() {
  4. cat <<<EOF
  5.  
  6. USAGE: $0 OPTIONS
  7. Prépare une application à la mise en Prod
  8. Crée un tag qui correspond à la prochaine version à publier
  9. Doit être lancé dans le répertoire de base des sources de l'application
  10.     (celui qui contient le.git)
  11. OPTIONS:
  12.     -h      affiche ce message
  13.     -m      Incrémente la version mineure
  14.     -M      Incrémente la version majeure
  15.     -p      publier en preprod (TODO)
  16.     -P      publier en Prod    (TODO)
  17. EOF
  18. }
  19.  
  20. b='$3+1'; m='$2'; M='$1';
  21.  
  22. while getopts "mMhPpl" OPTION
  23. do
  24.         case $OPTION in
  25.                 h)
  26.                         usage
  27.                         exit 1
  28.                         ;;
  29.                 m)      b='0'; m='$2+1'; M='$1';
  30.                         ;;
  31.                 M)      b='0'; m='0'; M='$1+1';
  32.                         ;;
  33.                 p)      preprod=1
  34.                         ;;
  35.                 P)      prod=1;
  36.                         ;;
  37.          esac
  38. done
  39.  
  40. # vérification que tout est à jour
  41. # on ne peut publier de nouvelle version que si on est à jour par rapport
  42. # au dépôt distant et qu'il n'y a pas de modifs en cours
  43. test=$(git fetch --dry-run | wc -l)
  44. if [ "$test" -ne "0" ]
  45. then
  46.     echo "la copie locale n'est pas à jour. git -> remote -> pull"
  47.     exit 1
  48. fi
  49.  
  50. test=$(git push --dry-run 2>&1 | grep "Everything up-to-date" | wc -l)
  51. if [ "$test" -ne "1" ]
  52. then
  53.     echo "le repository distant n'est pas a jour. git -> remote -> push"
  54.     exit 1
  55. fi
  56.  
  57. test=$(git commit --dry-run | grep "nothing to commit" | wc -l)
  58. if [ "$test" -ne "1" ]
  59. then
  60.     echo "Des modifications sont en cours. git -> commit"
  61.     exit 1
  62. fi
  63.  
  64. # récupération du dernier numéro de version de la forme Vx.y.z
  65. # last_ver=$(git describe --tags)
  66. last_ver=$(git tag --list | grep "V[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*" | sort -V | tail -n1)
  67. new_ver=$(echo $last_ver | sed -e 's/V//'| awk -F\. "{ printf(\"V%d.%d.%d\n\", $M,$m,$b); }")
  68. git tag $new_ver
  69. git push --tags