series.sh 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. #!/bin/bash -e
  2. #
  3. #Copyright (C) 2017 avideo authors (see AUTHORS)
  4. #
  5. # This file is part of AVideo.
  6. #
  7. # AVideo is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # AVideo is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with AVideo. If not, see <http://www.gnu.org/licenses/>.
  19. function series_new {
  20. #Create a new series: takes 2 parameters. $1 is this directory's path, and $2 is the date marker.
  21. if [ -z $2 ]; then
  22. REL_DATE=`date '+%Y.%-m'`
  23. else
  24. echo "Using alternative month data..."
  25. REL_DATE=$2
  26. fi
  27. #Set Up Workspace, Aborting if This Month's Release Already Exists
  28. if [ ! -z "`git branch | grep ${REL_DATE}`" ]; then
  29. echo "This Month's Release Already Exists; Aborting."
  30. exit 3
  31. fi
  32. git checkout master
  33. #Create repository to test for fatal error
  34. git checkout -b $REL_DATE
  35. if [ $? != 0 ]; then
  36. echo "Branch-Creation Error Encountered; Aborting."
  37. exit 4
  38. fi
  39. TZ=UTC date +%s > InitDate.txt
  40. cd ../Clone
  41. tar -czf "$1"/youtube-dl.tar.gz --exclude '.git' --exclude '.github' youtube-dl/
  42. cd "$1"
  43. git add youtube-dl.tar.gz InitDate.txt
  44. echo "Committing changes..."
  45. git commit -S -m "INIT for repos $2."
  46. }
  47. function release_clean {
  48. #Clean up non-release junk: takes 1 optional parameter. $1 is the software name.
  49. rm -f temp.txt tmp-output
  50. rm -Rf "$1"/ youtube-dl/
  51. }
  52. function release_build {
  53. #Build a release from patches: takes 1 parameter. $1 is the software name.
  54. release_clean $1
  55. tar -xzf youtube-dl.tar.gz
  56. #Copy in patch files, and remove evil files
  57. cat Patches/ban.txt | while read DEL_FILE
  58. do
  59. rm -R youtube-dl/${DEL_FILE}
  60. done
  61. cp -R Patches/Files/* youtube-dl/
  62. #Add some important files
  63. mv youtube-dl/AUTHORS tempauth
  64. echo "Youtube-DL Contributors:" > youtube-dl/AUTHORS
  65. cat tempauth >> youtube-dl/AUTHORS; rm tempauth
  66. echo -e "\nAVideo Contributors:" >> youtube-dl/AUTHORS
  67. cat AUTHORS >> youtube-dl/AUTHORS
  68. #List files in temp.txt and filter out references to interpreters
  69. find youtube-dl -type f -print > temp.txt
  70. xargs -a temp.txt sed -i '/swfinterp/d; /jsinterp/d'
  71. #Set up Git and version info...
  72. cd youtube-dl/
  73. devscripts/version.sh > /dev/null
  74. cd ..
  75. #Apply code patches and rebrand
  76. ./func.py youtube-dl/ $1
  77. mkdir $1/BINFILES/
  78. diff expected_output.txt tmp-output
  79. }
  80. function release_pub {
  81. #Publish a release: takes 1 required parameter, and 1 optional parameter. $1 is the software name, $2 is --test if tests are to be run.
  82. read -p "Is ChangeLog up to date? (y/n) " -n 1 REPLY2
  83. if [[ ! $REPLY2 =~ ^[Yy]$ ]]; then exit 9; fi
  84. release_build $1
  85. cd $1/
  86. echo "Testing..."
  87. if [ "$2" == --test ]; then
  88. echo "Press ^C if you haven't sent through TOR..."
  89. sleep 5
  90. nosetests --verbose --with-coverage --cover-package=youtube_dl --cover-html test --stop || exit 1
  91. else
  92. echo "Skipping Tests..."
  93. fi
  94. version=`devscripts/version.sh`
  95. SERIES_CURRENT=`echo $version | awk -F . ' { print $1"."$2 } '`
  96. echo "Building Release Packages..."
  97. make pub
  98. mv BINFILES/ ../../
  99. echo "Publishing Files..."
  100. cd ..
  101. series_merge
  102. git push origin master
  103. git push origin $SERIES_CURRENT
  104. git checkout archive
  105. if [ -d $version ]; then
  106. echo "Error: $version already exists. Aborting."
  107. rm -R ../BINFILES
  108. git checkout `echo $version | awk -F . ' { print $1"."$2 } '`
  109. fi
  110. mv ../BINFILES $version
  111. git add $version/
  112. git commit -S -m "Release $version"
  113. git push origin archive
  114. echo "Posting Publication Information..."
  115. git checkout $SERIES_CURRENT
  116. ./wiki.py --series-update $version --dlpage $1 --sites-update $1 || ./wiki.py --series-make $version --dlpage $1 --sites-update $1
  117. cp $1/README.md ../Wiki/"User Documentation.md"
  118. cd ../Wiki
  119. git add Downloads.md "Supported Sites.md" "User Documentation.md"
  120. git commit -S -m "Release $version"
  121. git push origin master
  122. }
  123. function series_dep {
  124. #Deprecate a series: takes 2 parameters. $1 is the series to deprecate, and $2 is the software name.
  125. #UNTESTED!!!
  126. echo -n "Are you SURE you want to PERMANENTLY delete series ${1}?"
  127. read -n 1 TEMPANS
  128. if [ "$TEMPANS" != y ]; then
  129. exit
  130. fi
  131. if (cd ../Wiki; [ ! -z "`git status --porcelain`" ]); then
  132. echo "Error: workspace is not clean. Please stash or commit changes before continuing."
  133. exit 4
  134. fi
  135. git checkout master
  136. git branch -D $1
  137. git push origin :$1
  138. echo "Posting Deprecation Information..."
  139. ./wiki.py --series-dep $1 --dlpage $2
  140. cd ../Wiki
  141. git add DOWNLOADS.md
  142. git commit $SIGN_COMMIT -m "Release $version"
  143. git push origin master
  144. }
  145. function series_list {
  146. #List series: takes 0 parameters.
  147. git branch | sed '/r/d; s/\*/\ /g'
  148. }
  149. function series_merge {
  150. #Prepare a specific series branch for (non-destructive) merging into master: takes 0 parameters.
  151. SERIES_CURRENT=`git rev-parse --abbrev-ref HEAD | tail -1`
  152. git stash
  153. git checkout master
  154. git merge $SERIES_CURRENT || true
  155. echo "Giving you a bash shell to resolve any merge conflicts; type 'exit' when done."
  156. bash
  157. for rem_file in youtube-dl.tar.gz InitDate.txt Patches/Bug; do
  158. git rm -r $rem_file || true
  159. done
  160. git commit -S -m "Merging from ${SERIES_CURRENT}" || true
  161. git checkout $SERIES_CURRENT
  162. }
  163. function series_giveHelp {
  164. #Print the help: takes 1 parameter. $1 is the command used to invoke this script.
  165. echo "Usage: $0 command [date marker]"
  166. echo "Command is one of:"
  167. echo " make- make a new series."
  168. echo " dep- deprecate a series."
  169. echo " clean- remove temporary files."
  170. echo " build- build a release package."
  171. echo " pub- publish a release."
  172. echo " list- list all series."
  173. echo " merge- merge to master."
  174. echo " help- print this help message."
  175. echo "A date marker is required for dep, and can be used with make to change the series created; it is ignored elsewhere."
  176. echo "For pub, two optional parameters are available: use --sign to sign commits, followed by --test to run tests. Omit arguments as relevant."
  177. exit
  178. }
  179. REL_BIGPATH=`realpath "$0"`
  180. REL_PATH=`dirname "${REL_BIGPATH}"`
  181. if [ $# -eq 0 ]; then
  182. echo "Error: Insufficient Arguments."
  183. series_giveHelp "$0"
  184. fi
  185. REL_NAME=avideo
  186. cd "${REL_PATH}"
  187. if [ "$1" == dep ]; then
  188. if [ $# -lt 2 ]; then
  189. echo "Error: No Date Marker for 'dep'."
  190. series_giveHelp "$0"
  191. fi
  192. series_dep $2 $REL_NAME
  193. exit
  194. fi
  195. if [ "$1" == make ]; then
  196. series_new "$REL_PATH" $2
  197. exit
  198. fi
  199. if [ "$1" == list ]; then
  200. series_list
  201. exit
  202. fi
  203. if [ "$1" == clean ]; then
  204. release_clean $REL_NAME
  205. exit
  206. fi
  207. if [ "$1" == build ]; then
  208. release_build $REL_NAME
  209. exit
  210. fi
  211. if [ "$1" == pub ]; then
  212. release_pub $REL_NAME $2
  213. exit
  214. fi
  215. if [ "$1" == merge ]; then
  216. series_merge
  217. exit
  218. fi
  219. echo "Error: Command Not Recognized."
  220. series_giveHelp "$0"