release.yml 8.9 KB

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