expand 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. #!/bin/bash
  2. set -e
  3. version="$1"
  4. type="$2"
  5. ### CONFIGURATION OPTIONS
  6. # Profiles to package in addition to the profile releng for the make target "dist-branches"
  7. branches_dist_branches=(baseline gnome toolkit)
  8. # Profiles to package in addition to the profile releng for the make target "dist"
  9. branches_dist=(baseline)
  10. ### END OF CONFIGURATION OPTIONS
  11. error() {
  12. echo "${@}. Stop." >&2
  13. exit 1
  14. }
  15. dist_branches() {
  16. branches="${branches_dist_branches}"
  17. # Refs to package (the branches)
  18. refs="${branches[@]}"
  19. # Ref of the releng profile to package
  20. releng="master"
  21. # Release branch. This branch only has commits to prepare the package.
  22. release_branch="release-branches"
  23. # Release ref. It is a branch for dist_branches. The package is created from this ref.
  24. release="${release_branch}"
  25. # Refs that should exist for the make target dist-branches. This branches will be packaged.
  26. allrefs=( ${releng} ${branches[@]} )
  27. }
  28. dist() {
  29. branches="${branches_dist}"
  30. # Refs to package (branch names appending the date, like "baseline/2013.08.12")
  31. refs="${branches_dist[@]/%//${version}}"
  32. # Ref of the releng profile to package
  33. releng="master/${version}"
  34. # Release branch. This branch only has commits to prepare the package.
  35. release_branch="release"
  36. # Release ref. Tag of commit in release_branch. The package is created from this ref.
  37. release="release/${version}"
  38. # These refs should exist to package for the make target dist.
  39. allrefs=( ${releng} ${refs[@]} )
  40. }
  41. expand() {
  42. ref="$1"
  43. dir="$2"
  44. GIT_INDEX_FILE="${index}" git read-tree --empty
  45. GIT_INDEX_FILE="${index}".release git read-tree --empty
  46. # Find the current head of ${ref}
  47. head="$(git show-ref --hash "refs/${ref_type}/${ref}")"
  48. # Find the current head of the release branch.
  49. head_release="$(git show-ref --hash refs/heads/"${release_branch}")"
  50. if [[ $dir == releng ]] ; then
  51. # Read the tree of "$ref" with profile path rename into an index file.
  52. git ls-tree -z -r "${head}" | sed -z "s|configs/profile|configs/${dir}|" | GIT_INDEX_FILE="${index}" git update-index -z --index-info
  53. # Remove the master branch from the release index, that is, leave everything from configs/ excluding configs/releng
  54. git ls-tree -z -r "${head_release}" | grep -zZP 'configs/(?!releng)' | GIT_INDEX_FILE="${index}".release git update-index -z --index-info
  55. # This combines the two indexes (obtained in the last two commands).
  56. GIT_INDEX_FILE="${index}".release git ls-files -z -s | GIT_INDEX_FILE="${index}" git update-index -z --add --index-info
  57. else
  58. # Read only paths configs/profile of "$ref" with profile path rename into an index file.
  59. git ls-tree -z -r "${head}" -- configs/profile | sed -z "s|configs/profile|configs/${dir}|" | GIT_INDEX_FILE="${index}" git update-index -z --index-info
  60. # Remove configs/${dir} from the release index.
  61. git ls-tree -z -r "${head_release}" | grep -zZv configs/"${dir}" | GIT_INDEX_FILE="${index}".release git update-index -z --index-info
  62. # This combines the two indexes (obtained in the last two commands).
  63. GIT_INDEX_FILE="${index}".release git ls-files -z -s | GIT_INDEX_FILE="${index}" git update-index -z --add --index-info
  64. fi
  65. # Write the index file into the repo as a tree.
  66. tree="$(GIT_INDEX_FILE="${index}" git write-tree)"
  67. # Write a commit to the repo.
  68. commit="$(echo "Update profile ${dir}" | git commit-tree "$tree" -p "${head_release}")"
  69. # Update the head of the repository to be the new commit.
  70. git update-ref refs/heads/"${release_branch}" "$commit" "${head_release}"
  71. }
  72. expand_empty() {
  73. ref="${releng}"
  74. dir="releng"
  75. GIT_INDEX_FILE="${index}" git read-tree --empty
  76. # Find the current head of ${ref}
  77. head="$(git show-ref --hash "refs/${ref_type}/${ref}")"
  78. # Read the tree of "$ref" with profile path rename into an index file.
  79. git ls-tree -z -r "${head}" | sed -z "s|configs/profile|configs/${dir}|" | GIT_INDEX_FILE="${index}" git update-index -z --index-info
  80. # Write the index file into the repo as a tree.
  81. tree="$(GIT_INDEX_FILE="${index}" git write-tree)"
  82. # Write a commit to the repo.
  83. commit="$(echo "Update profile ${dir}" | git commit-tree "$tree")"
  84. # Update the head of the repository to be the new commit.
  85. git update-ref refs/heads/"${release_branch}" "$commit" 0000000000000000000000000000000000000000
  86. }
  87. ref_test() {
  88. es=0
  89. git show-ref --quiet "$1" || es=$?
  90. if [[ $es == 1 ]] ; then
  91. error "$2"
  92. elif [[ $es > 1 ]] ; then
  93. error "$3"
  94. fi
  95. }
  96. ref_test_negative() {
  97. es=0
  98. git show-ref --quiet "$1" || es=$?
  99. if [[ $es == 0 ]] ; then
  100. error "$2"
  101. elif [[ $es > 1 ]] ; then
  102. error "$3"
  103. fi
  104. }
  105. release_prepare() {
  106. ref_test_negative "refs/tags/${release}" "Release tag ${release} can not be created because it already exists" "Error testing the release tag"
  107. }
  108. show_ref() {
  109. for ref in ${allrefs[@]} ; do
  110. ref_test "refs/${ref_type}/${ref}" "Git reference refs/${ref_type}/${ref} should exist" "Error testing git reference refs/${ref_type}/${ref}"
  111. done
  112. }
  113. archive_ref() {
  114. git archive --format=tar.gz --prefix=parabolaiso-"${version}"/ "refs/${ref_type}/${release}" > parabolaiso-"${version}".tar.gz
  115. }
  116. archive() {
  117. git tag -s -m "tag ${release}" "${release}" "${release_branch}"
  118. archive_ref
  119. gpg --detach-sign --use-agent parabolaiso-"${version}".tar.gz
  120. }
  121. dist_expand() {
  122. index="$(mktemp)"
  123. es=0
  124. git show-ref --quiet "refs/heads/${release_branch}" || es=$?
  125. if [[ $es == 0 ]] ; then
  126. expand "${releng}" releng
  127. elif [[ $es == 1 ]] ; then
  128. expand_empty
  129. echo "Release branch created."
  130. elif [[$es > 1 ]] ; then
  131. error "Error testing the release branch"
  132. fi
  133. for i in ${!branches[@]} ; do
  134. expand ${refs[$i]} ${branches[$i]}
  135. done
  136. }
  137. if [[ ${type} == dist ]] ; then
  138. ref_type="tags"
  139. dist
  140. release_prepare
  141. show_ref
  142. dist_expand
  143. archive
  144. elif [[ ${type} == dist-branches ]] ; then
  145. ref_type="heads"
  146. dist_branches
  147. show_ref
  148. dist_expand
  149. archive_ref
  150. else
  151. error "Second argument is not correct"
  152. fi