series.sh 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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 2 optional parameter. $1 is the software name, $2 is --test or -t if tests are to be run, and $3 is --merge or -m if changes are to be merged into the master branch.
  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. version=`./$1/devscripts/version.sh`
  86. ./wiki.py --series-update $version --dlpage $1 --sites-update $1 || ./wiki.py --series-make $version --dlpage $1 --sites-update $1
  87. cd $1/
  88. echo "Testing..."
  89. if [ "$2" == --test ] || [ "$2" == -t ]; then
  90. echo "Press ^C if you haven't sent through TOR but want to..."
  91. sleep 5
  92. nosetests --verbose --with-coverage --cover-package=youtube_dl --cover-html test --stop || exit 1
  93. else
  94. echo "Skipping Tests..."
  95. fi
  96. SERIES_CURRENT=`echo $version | awk -F . ' { print $1"."$2 } '`
  97. echo "Building Release Packages..."
  98. make pub
  99. #Upload to PyPI
  100. gpg -ab dist/*.tar.gz
  101. twine upload dist/* *.tar.gz.asc
  102. rm *.tar.gz.asc
  103. #Done Upload
  104. mv BINFILES/ ../../
  105. echo "Publishing Files..."
  106. cd ..
  107. git add Patches/Files/ChangeLog
  108. git commit -S -m "Das new ChangeLog" || true
  109. if [ ${@: -1} == "--merge" ] || [ ${@: -1} == "-m" ]; then
  110. series_merge
  111. git push origin master
  112. fi
  113. git push origin $SERIES_CURRENT
  114. git checkout archive
  115. if [ -d $version ]; then
  116. echo "Error: $version already exists. Aborting."
  117. rm -R ../BINFILES
  118. git checkout `echo $version | awk -F . ' { print $1"."$2 } '`
  119. fi
  120. mv ../BINFILES $version
  121. #Update Repo Files
  122. cd repos
  123. cat ../../Wiki/versions.txt | while read lineam
  124. do
  125. if [ "$lineam" == "" ]; then
  126. continue
  127. fi
  128. IFS=$'\t' read tag vrs <<< "$lineam"
  129. tag=`echo $tag | tr -cd [:alpha:]- | tr [:upper:] [:lower:]`
  130. mkdir -p ${tag:0:-1}
  131. cd ${tag:0:-1}
  132. apt-ftparchive packages ../../$vrs > Packages
  133. cat Packages | gzip -9c > Packages.gz
  134. echo "Origin: notabug.org" > Release
  135. echo "Architectures: all" >> Release
  136. echo "Components: main" >> Release
  137. echo "Description: official avideo "`basename $0`" repository" >> Release
  138. echo "SignWith: yes" >> Release
  139. apt-ftparchive release . >> Release
  140. rm Packages
  141. gpg --clearsign -o InRelease Release
  142. gpg -ab -o Release.gpg Release
  143. git add Packages.gz Release.gpg InRelease Release
  144. cd ..
  145. done
  146. cd ..
  147. git add $version/
  148. git commit -S -m "Release $version"
  149. git push origin archive
  150. echo "Posting Publication Information..."
  151. git checkout $SERIES_CURRENT
  152. cp $1/README.md ../Wiki/"User Documentation.md"
  153. cd ../Wiki
  154. git add Downloads.md "Supported Sites.md" "User Documentation.md"
  155. git commit -S -m "Release $version"
  156. git push origin master
  157. }
  158. function series_dep {
  159. #Deprecate a series: takes 2 parameters. $1 is the series to deprecate, and $2 is the software name.
  160. #UNTESTED!!!
  161. echo -n "Are you SURE you want to PERMANENTLY delete series ${1}?"
  162. read -n 1 TEMPANS
  163. if [ "$TEMPANS" != y ]; then
  164. exit
  165. fi
  166. if (cd ../Wiki; [ ! -z "`git status --porcelain`" ]); then
  167. echo "Error: workspace is not clean. Please stash or commit changes before continuing."
  168. exit 4
  169. fi
  170. git checkout master
  171. git branch -D $1
  172. git push origin :$1
  173. echo "Posting Deprecation Information..."
  174. ./wiki.py --series-dep $1 --dlpage $2
  175. cd ../Wiki
  176. git add DOWNLOADS.md
  177. git commit $SIGN_COMMIT -m "Release $version"
  178. git push origin master
  179. }
  180. function series_list {
  181. #List series: takes 0 parameters.
  182. git branch | sed '/r/d; s/\*/\ /g'
  183. }
  184. function series_merge {
  185. #Prepare a specific series branch for (non-destructive) merging into master: takes 0 parameters.
  186. SERIES_CURRENT=`git rev-parse --abbrev-ref HEAD | tail -1`
  187. git stash
  188. git checkout master
  189. git merge $SERIES_CURRENT || true
  190. echo "Giving you a bash shell to resolve any merge conflicts; type 'exit' when done."
  191. bash
  192. for rem_file in youtube-dl.tar.gz InitDate.txt Patches/Bug; do
  193. git rm -r $rem_file || true
  194. done
  195. git commit -S -m "Merging from ${SERIES_CURRENT}" || true
  196. git checkout $SERIES_CURRENT
  197. }
  198. function series_giveHelp {
  199. #Print the help: takes 1 parameter. $1 is the command used to invoke this script.
  200. echo "Usage: $0 command [date marker]"
  201. echo "Command is one of:"
  202. echo " make- make a new series."
  203. echo " dep- deprecate a series."
  204. echo " clean- remove temporary files."
  205. echo " build- build a release package."
  206. echo " pub- publish a release."
  207. echo " list- list all series."
  208. echo " merge- merge to master."
  209. echo " help- print this help message."
  210. echo "A date marker is required for dep, and can be used with make to change the series created; it is ignored elsewhere."
  211. echo "For pub, two optional parameters are available: use --sign to sign commits, followed by --test to run tests. Omit arguments as relevant."
  212. exit
  213. }
  214. REL_BIGPATH=`realpath "$0"`
  215. REL_PATH=`dirname "${REL_BIGPATH}"`
  216. if [ $# -eq 0 ]; then
  217. echo "Error: Insufficient Arguments."
  218. series_giveHelp "$0"
  219. fi
  220. REL_NAME=avideo
  221. cd "${REL_PATH}"
  222. if [ "$1" == dep ]; then
  223. if [ $# -lt 2 ]; then
  224. echo "Error: No Date Marker for 'dep'."
  225. series_giveHelp "$0"
  226. fi
  227. series_dep $2 $REL_NAME
  228. exit
  229. fi
  230. if [ "$1" == make ]; then
  231. series_new "$REL_PATH" $2
  232. exit
  233. fi
  234. if [ "$1" == list ]; then
  235. series_list
  236. exit
  237. fi
  238. if [ "$1" == clean ]; then
  239. release_clean $REL_NAME
  240. exit
  241. fi
  242. if [ "$1" == build ]; then
  243. release_build $REL_NAME
  244. exit
  245. fi
  246. if [ "$1" == pub ]; then
  247. release_pub $REL_NAME $2 $3
  248. exit
  249. fi
  250. if [ "$1" == merge ]; then
  251. series_merge
  252. exit
  253. fi
  254. echo "Error: Command Not Recognized."
  255. series_giveHelp "$0"