update_domdistiller_js.sh 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #!/bin/bash
  2. #
  3. # Copyright 2014 The Chromium Authors. All rights reserved.
  4. # Use of this source code is governed by a BSD-style license that can be
  5. # found in the LICENSE file.
  6. #
  7. # Clones the dom-distiller repo, compiles and extracts its JavaScript. The
  8. # artifact would be uploaded as a CL in dom-distiller/dist repo, and then
  9. # generates a rolling commit to be uploaded.
  10. # This script requires that ant is installed. It takes an optional parameter
  11. # for which SHA1 in dom-distiller repo to roll to. If left unspecified the
  12. # script rolls to HEAD. The second optional parameter is the Gerrit URL of
  13. # the CL in dom-distiller/dist repo to be validated.
  14. (
  15. set -e
  16. dom_distiller_js_path=$(dirname "${BASH_SOURCE[0]}")
  17. src_path=$dom_distiller_js_path/../..
  18. readme_chromium=$dom_distiller_js_path/README.chromium
  19. [ ! -f $readme_chromium ] && echo "$readme_chromium is not found" && exit 1
  20. tmpdir=/tmp/domdistiller-$$
  21. changes=$tmpdir/domdistiller.changes
  22. bugs=$tmpdir/domdistiller.bugs
  23. curr_gitsha=$(grep 'Version:' $readme_chromium | awk '{print $2}')
  24. repo_host=https://chromium.googlesource.com/chromium
  25. rm -rf $tmpdir
  26. mkdir $tmpdir
  27. pushd $tmpdir
  28. function finish {
  29. rm -rf $tmpdir
  30. }
  31. trap finish EXIT
  32. git clone $repo_host/dom-distiller
  33. pushd dom-distiller
  34. # The new git SHA1 is HEAD or the first command line parameter.
  35. [[ -z "$1" ]] && gitsha_target="HEAD" || gitsha_target="$1"
  36. gerrit_url="$2"
  37. new_gitsha=$(git rev-parse --short=10 ${gitsha_target})
  38. git reset --hard ${new_gitsha}
  39. git log --oneline ${curr_gitsha}..${new_gitsha} > $changes
  40. echo -n 'Bug: ' > $bugs
  41. # This extracts BUG= lines from the log, extracts the numbers part, removes
  42. # whitespace and deletes empty lines. Then, split on ',', sort, uniquify and
  43. # rejoin. Finally, remove the trailing ',' and concat to $bugs.
  44. git log ${curr_gitsha}..${new_gitsha} \
  45. | grep -E 'BUG=|Bug:' \
  46. | sed -e 's/.*\(BUG=\|Bug:\)\(.*\)/\2/' -e 's/\s*//g' -e '/^$/d' -e '/None/d' \
  47. | tr ',' '\n' \
  48. | sort \
  49. | uniq \
  50. | tr '\n' ',' \
  51. | sed -e 's/,/, /g' \
  52. | head --bytes=-2 \
  53. >> $bugs
  54. echo >> $bugs # add a newline
  55. ant package
  56. popd # dom-distiller
  57. git clone $repo_host/dom-distiller/dist $tmpdir/dom-distiller-dist
  58. pushd dom-distiller-dist
  59. if [[ -n "$gerrit_url" ]]; then
  60. echo "Validating $gerrit_url"
  61. git cl patch --force $gerrit_url
  62. fi
  63. rm -rf $tmpdir/dom-distiller-dist/*
  64. cp -r $tmpdir/dom-distiller/out/package/* .
  65. git add .
  66. if [[ $(git status --short | wc -l) -ne 0 ]]; then
  67. if [[ -n "$gerrit_url" ]]; then
  68. echo "FAIL. The output is different from $gerrit_url."
  69. exit 1
  70. fi
  71. # For Change-Id footer.
  72. curl -Lo $(git rev-parse --git-dir)/hooks/commit-msg https://gerrit-review.googlesource.com/tools/hooks/commit-msg
  73. chmod +x $(git rev-parse --git-dir)/hooks/commit-msg
  74. gen_message () {
  75. echo "Package for ${new_gitsha}"
  76. echo
  77. echo "This is generated from:"
  78. echo "${repo_host}/dom-distiller/+/${new_gitsha}."
  79. echo
  80. echo "To validate, run the following command in chromium/src:"
  81. echo "third_party/dom_distiller_js/update_domdistiller_js.sh ${new_gitsha} <Gerrit-URL>"
  82. }
  83. message=$tmpdir/message
  84. gen_message > $message
  85. git commit -a -F $message
  86. git push origin main:refs/for/main
  87. else
  88. # No changes to external repo, but need to check if DEPS refers to same SHA1.
  89. if [[ -n "$gerrit_url" ]]; then
  90. echo "PASS. The output is the same as $gerrit_url."
  91. exit 0
  92. fi
  93. echo "WARNING: There were no changes to the distribution package."
  94. fi
  95. new_dist_gitsha=$(git rev-parse HEAD)
  96. popd # dom-distiller-dist
  97. popd # tmpdir
  98. curr_dist_gitsha=$(grep -e "/chromium\/dom-distiller\/dist.git" $src_path/DEPS | sed -e "s/.*'\([A-Za-z0-9]\{40\}\)'.*/\1/g")
  99. if [[ "${new_dist_gitsha}" == "${curr_dist_gitsha}" ]]; then
  100. echo "The roll does not include any changes to the dist package. Exiting."
  101. exit 1
  102. fi
  103. cp $tmpdir/dom-distiller/LICENSE $dom_distiller_js_path/
  104. sed -i "s/Version: [0-9a-f]*/Version: ${new_gitsha}/" $readme_chromium
  105. sed -i -e "s/\('\/chromium\/dom-distiller\/dist.git' + '@' + '\)\([0-9a-f]\+\)'/\1${new_dist_gitsha}'/" $src_path/DEPS
  106. gen_message () {
  107. echo "Roll DOM Distiller JavaScript distribution package"
  108. echo
  109. echo "Diff since last roll:"
  110. echo "https://chromium.googlesource.com/chromium/dom-distiller/+/${curr_gitsha}..${new_gitsha}"
  111. echo
  112. echo "Picked up changes:"
  113. echo "https://chromium.googlesource.com/chromium/dom-distiller/+log/${curr_gitsha}..${new_gitsha}"
  114. cat $changes
  115. echo
  116. cat $bugs
  117. }
  118. message=$tmpdir/message
  119. gen_message > $message
  120. # Run checklicenses.py on the pulled files, but only print the output on
  121. # failures.
  122. $src_path/tools/checklicenses/checklicenses.py third_party/dom_distiller_js > $tmpdir/checklicenses.out || cat $tmpdir/checklicenses.out
  123. git commit -a -F $message
  124. )