series.sh 8.2 KB

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