release.yml 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. name: release
  2. on:
  3. workflow_run:
  4. workflows: [test]
  5. branches: [master]
  6. types: [completed]
  7. jobs:
  8. release:
  9. runs-on: ubuntu-20.04
  10. # need to manually check for a couple things
  11. # - tests passed?
  12. # - we are the most recent commit on master?
  13. if: ${{github.event.workflow_run.conclusion == 'success' &&
  14. github.event.workflow_run.head_sha == github.sha}}
  15. steps:
  16. - uses: actions/checkout@v2
  17. with:
  18. ref: ${{github.event.workflow_run.head_sha}}
  19. # need workflow access since we push branches
  20. # containing workflows
  21. token: ${{secrets.BOT_TOKEN}}
  22. # need all tags
  23. fetch-depth: 0
  24. # try to get results from tests
  25. - uses: dawidd6/action-download-artifact@v2
  26. continue-on-error: true
  27. with:
  28. workflow: ${{github.event.workflow_run.name}}
  29. run_id: ${{github.event.workflow_run.id}}
  30. name: results
  31. path: results
  32. - name: find-version
  33. run: |
  34. # rip version from lfs.h
  35. LFS_VERSION="$(grep -o '^#define LFS_VERSION .*$' lfs.h \
  36. | awk '{print $3}')"
  37. LFS_VERSION_MAJOR="$((0xffff & ($LFS_VERSION >> 16)))"
  38. LFS_VERSION_MINOR="$((0xffff & ($LFS_VERSION >> 0)))"
  39. # find a new patch version based on what we find in our tags
  40. LFS_VERSION_PATCH="$( \
  41. ( git describe --tags --abbrev=0 \
  42. --match="v$LFS_VERSION_MAJOR.$LFS_VERSION_MINOR.*" \
  43. || echo 'v0.0.-1' ) \
  44. | awk -F '.' '{print $3+1}')"
  45. # found new version
  46. LFS_VERSION="v$LFS_VERSION_MAJOR`
  47. `.$LFS_VERSION_MINOR`
  48. `.$LFS_VERSION_PATCH"
  49. echo "LFS_VERSION=$LFS_VERSION"
  50. echo "LFS_VERSION=$LFS_VERSION" >> $GITHUB_ENV
  51. echo "LFS_VERSION_MAJOR=$LFS_VERSION_MAJOR" >> $GITHUB_ENV
  52. echo "LFS_VERSION_MINOR=$LFS_VERSION_MINOR" >> $GITHUB_ENV
  53. echo "LFS_VERSION_PATCH=$LFS_VERSION_PATCH" >> $GITHUB_ENV
  54. # try to find previous version?
  55. - name: find-prev-version
  56. continue-on-error: true
  57. run: |
  58. LFS_PREV_VERSION="$(git describe --tags --abbrev=0 --match 'v*')"
  59. echo "LFS_PREV_VERSION=$LFS_PREV_VERSION"
  60. echo "LFS_PREV_VERSION=$LFS_PREV_VERSION" >> $GITHUB_ENV
  61. # try to find results from tests
  62. - name: collect-results
  63. run: |
  64. # previous results to compare against?
  65. [ -n "$LFS_PREV_VERSION" ] && curl -sS \
  66. "$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/`
  67. `status/$LFS_PREV_VERSION?per_page=100" \
  68. | jq -re 'select(.sha != env.GITHUB_SHA) | .statuses[]' \
  69. >> prev-results.json \
  70. || true
  71. # build table for GitHub
  72. echo "<table>" >> results.txt
  73. echo "<thead>" >> results.txt
  74. echo "<tr>" >> results.txt
  75. echo "<th align=left>Configuration</th>" >> results.txt
  76. for r in Code Stack Structs Coverage
  77. do
  78. echo "<th align=right>$r</th>" >> results.txt
  79. done
  80. echo "</tr>" >> results.txt
  81. echo "</thead>" >> results.txt
  82. echo "<tbody>" >> results.txt
  83. for c in "" readonly threadsafe migrate error-asserts
  84. do
  85. echo "<tr>" >> results.txt
  86. c_or_default=${c:-default}
  87. echo "<td align=left>${c_or_default^}</td>" >> results.txt
  88. for r in code stack structs
  89. do
  90. # per-config results
  91. echo "<td align=right>" >> results.txt
  92. [ -e results/thumb${c:+-$c}.csv ] && ( \
  93. export PREV="$(jq -re '
  94. select(.context == "'"results (thumb${c:+, $c}) / $r"'").description
  95. | capture("(?<result>[0-9∞]+)").result' \
  96. prev-results.json || echo 0)"
  97. ./scripts/summary.py results/thumb${c:+-$c}.csv -f $r -Y | awk '
  98. NR==2 {printf "%s B",$2}
  99. NR==2 && ENVIRON["PREV"]+0 != 0 {
  100. printf " (%+.1f%%)",100*($2-ENVIRON["PREV"])/ENVIRON["PREV"]}
  101. NR==2 {printf "\n"}' \
  102. | sed -e 's/ /\&nbsp;/g' \
  103. >> results.txt)
  104. echo "</td>" >> results.txt
  105. done
  106. # coverage results
  107. if [ -z $c ]
  108. then
  109. echo "<td rowspan=0 align=right>" >> results.txt
  110. [ -e results/coverage.csv ] && ( \
  111. export PREV="$(jq -re '
  112. select(.context == "results / coverage").description
  113. | capture("(?<result>[0-9\\.]+)").result' \
  114. prev-results.json || echo 0)"
  115. ./scripts/coverage.py -u results/coverage.csv -Y | awk -F '[ /%]+' '
  116. NR==2 {printf "%.1f%% of %d lines",$4,$3}
  117. NR==2 && ENVIRON["PREV"]+0 != 0 {
  118. printf " (%+.1f%%)",$4-ENVIRON["PREV"]}
  119. NR==2 {printf "\n"}' \
  120. | sed -e 's/ /\&nbsp;/g' \
  121. >> results.txt)
  122. echo "</td>" >> results.txt
  123. fi
  124. echo "</tr>" >> results.txt
  125. done
  126. echo "</tbody>" >> results.txt
  127. echo "</table>" >> results.txt
  128. cat results.txt
  129. # find changes from history
  130. - name: collect-changes
  131. run: |
  132. [ -n "$LFS_PREV_VERSION" ] || exit 0
  133. # use explicit link to github commit so that release notes can
  134. # be copied elsewhere
  135. git log "$LFS_PREV_VERSION.." \
  136. --grep='^Merge' --invert-grep \
  137. --format="format:[\`%h\`](`
  138. `https://github.com/$GITHUB_REPOSITORY/commit/%h) %s" \
  139. > changes.txt
  140. echo "CHANGES:"
  141. cat changes.txt
  142. # create and update major branches (vN and vN-prefix)
  143. - name: create-major-branches
  144. run: |
  145. # create major branch
  146. git branch "v$LFS_VERSION_MAJOR" HEAD
  147. # create major prefix branch
  148. git config user.name ${{secrets.BOT_USER}}
  149. git config user.email ${{secrets.BOT_EMAIL}}
  150. git fetch "https://github.com/$GITHUB_REPOSITORY.git" \
  151. "v$LFS_VERSION_MAJOR-prefix" || true
  152. ./scripts/prefix.py "lfs$LFS_VERSION_MAJOR"
  153. git branch "v$LFS_VERSION_MAJOR-prefix" $( \
  154. git commit-tree $(git write-tree) \
  155. $(git rev-parse --verify -q FETCH_HEAD | sed -e 's/^/-p /') \
  156. -p HEAD \
  157. -m "Generated v$LFS_VERSION_MAJOR prefixes")
  158. git reset --hard
  159. # push!
  160. git push --atomic origin \
  161. "v$LFS_VERSION_MAJOR" \
  162. "v$LFS_VERSION_MAJOR-prefix"
  163. # build release notes
  164. - name: create-release
  165. run: |
  166. # create release and patch version tag (vN.N.N)
  167. # only draft if not a patch release
  168. [ -e results.txt ] && export RESULTS="$(cat results.txt)"
  169. [ -e changes.txt ] && export CHANGES="$(cat changes.txt)"
  170. curl -sS -X POST -H "authorization: token ${{secrets.BOT_TOKEN}}" \
  171. "$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/releases" \
  172. -d "$(jq -n '{
  173. tag_name: env.LFS_VERSION,
  174. name: env.LFS_VERSION | rtrimstr(".0"),
  175. target_commitish: "${{github.event.workflow_run.head_sha}}",
  176. draft: env.LFS_VERSION | endswith(".0"),
  177. body: [env.RESULTS, env.CHANGES | select(.)] | join("\n\n")}' \
  178. | tee /dev/stderr)"