release.yml 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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-22.04
  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="$(git describe --tags --abbrev=0 --match 'v*')"
  76. echo "LFS_PREV_VERSION=$LFS_PREV_VERSION"
  77. echo "LFS_PREV_VERSION=$LFS_PREV_VERSION" >> $GITHUB_ENV
  78. # try to find results from tests
  79. - name: create-table
  80. run: |
  81. # previous results to compare against?
  82. [ -n "$LFS_PREV_VERSION" ] && curl -sS \
  83. "$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/status/$LFS_PREV_VERSION`
  84. `?per_page=100" \
  85. | jq -re 'select(.sha != env.GITHUB_SHA) | .statuses[]' \
  86. >> prev-status.json \
  87. || true
  88. # build table for GitHub
  89. declare -A table
  90. # sizes table
  91. i=0
  92. j=0
  93. for c in "" readonly threadsafe migrate error-asserts
  94. do
  95. # per-config results
  96. c_or_default=${c:-default}
  97. c_camel=${c_or_default^}
  98. table[$i,$j]=$c_camel
  99. ((j+=1))
  100. for s in code stack struct
  101. do
  102. f=sizes/thumb${c:+-$c}.$s.csv
  103. [ -e $f ] && table[$i,$j]=$( \
  104. export PREV="$(jq -re '
  105. select(.context == "'"sizes (thumb${c:+, $c}) / $s"'").description
  106. | capture("(?<prev>[0-9∞]+)").prev' \
  107. prev-status.json || echo 0)"
  108. ./scripts/summary.py $f --max=stack_limit -Y \
  109. | awk '
  110. NR==2 {$1=0; printf "%s B",$NF}
  111. NR==2 && ENVIRON["PREV"]+0 != 0 {
  112. printf " (%+.1f%%)",100*($NF-ENVIRON["PREV"])/ENVIRON["PREV"]
  113. }' \
  114. | sed -e 's/ /\&nbsp;/g')
  115. ((j+=1))
  116. done
  117. ((j=0, i+=1))
  118. done
  119. # coverage table
  120. i=0
  121. j=4
  122. for s in lines branches
  123. do
  124. table[$i,$j]=${s^}
  125. ((j+=1))
  126. f=cov/cov.csv
  127. [ -e $f ] && table[$i,$j]=$( \
  128. export PREV="$(jq -re '
  129. select(.context == "'"cov / $s"'").description
  130. | capture("(?<prev_a>[0-9]+)/(?<prev_b>[0-9]+)")
  131. | 100*((.prev_a|tonumber) / (.prev_b|tonumber))' \
  132. prev-status.json || echo 0)"
  133. ./scripts/cov.py -u $f -f$s -Y \
  134. | awk -F '[ /%]+' -v s=$s '
  135. NR==2 {$1=0; printf "%d/%d %s",$2,$3,s}
  136. NR==2 && ENVIRON["PREV"]+0 != 0 {
  137. printf " (%+.1f%%)",$4-ENVIRON["PREV"]
  138. }' \
  139. | sed -e 's/ /\&nbsp;/g')
  140. ((j=4, i+=1))
  141. done
  142. # benchmark table
  143. i=3
  144. j=4
  145. for s in readed proged erased
  146. do
  147. table[$i,$j]=${s^}
  148. ((j+=1))
  149. f=bench/bench.csv
  150. [ -e $f ] && table[$i,$j]=$( \
  151. export PREV="$(jq -re '
  152. select(.context == "'"bench / $s"'").description
  153. | capture("(?<prev>[0-9]+)").prev' \
  154. prev-status.json || echo 0)"
  155. ./scripts/summary.py $f -f$s=bench_$s -Y \
  156. | awk '
  157. NR==2 {$1=0; printf "%s B",$NF}
  158. NR==2 && ENVIRON["PREV"]+0 != 0 {
  159. printf " (%+.1f%%)",100*($NF-ENVIRON["PREV"])/ENVIRON["PREV"]
  160. }' \
  161. | sed -e 's/ /\&nbsp;/g')
  162. ((j=4, i+=1))
  163. done
  164. # build the actual table
  165. echo "| | Code | Stack | Structs | | Coverage |" >> table.txt
  166. echo "|:--|-----:|------:|--------:|:--|---------:|" >> table.txt
  167. for ((i=0; i<6; i++))
  168. do
  169. echo -n "|" >> table.txt
  170. for ((j=0; j<6; j++))
  171. do
  172. echo -n " " >> table.txt
  173. [[ i -eq 2 && j -eq 5 ]] && echo -n "**Benchmarks**" >> table.txt
  174. echo -n "${table[$i,$j]:-}" >> table.txt
  175. echo -n " |" >> table.txt
  176. done
  177. echo >> table.txt
  178. done
  179. cat table.txt
  180. # find changes from history
  181. - name: create-changes
  182. run: |
  183. [ -n "$LFS_PREV_VERSION" ] || exit 0
  184. # use explicit link to github commit so that release notes can
  185. # be copied elsewhere
  186. git log "$LFS_PREV_VERSION.." \
  187. --grep='^Merge' --invert-grep \
  188. --format="format:[\`%h\`](`
  189. `https://github.com/$GITHUB_REPOSITORY/commit/%h) %s" \
  190. > changes.txt
  191. echo "CHANGES:"
  192. cat changes.txt
  193. # create and update major branches (vN and vN-prefix)
  194. - name: create-major-branches
  195. run: |
  196. # create major branch
  197. git branch "v$LFS_VERSION_MAJOR" HEAD
  198. # create major prefix branch
  199. git config user.name ${{secrets.BOT_USER}}
  200. git config user.email ${{secrets.BOT_EMAIL}}
  201. git fetch "https://github.com/$GITHUB_REPOSITORY.git" \
  202. "v$LFS_VERSION_MAJOR-prefix" || true
  203. ./scripts/changeprefix.py --git "lfs" "lfs$LFS_VERSION_MAJOR"
  204. git branch "v$LFS_VERSION_MAJOR-prefix" $( \
  205. git commit-tree $(git write-tree) \
  206. $(git rev-parse --verify -q FETCH_HEAD | sed -e 's/^/-p /') \
  207. -p HEAD \
  208. -m "Generated v$LFS_VERSION_MAJOR prefixes")
  209. git reset --hard
  210. # push!
  211. git push --atomic origin \
  212. "v$LFS_VERSION_MAJOR" \
  213. "v$LFS_VERSION_MAJOR-prefix"
  214. # build release notes
  215. - name: create-release
  216. run: |
  217. # create release and patch version tag (vN.N.N)
  218. # only draft if not a patch release
  219. [ -e table.txt ] && cat table.txt >> release.txt
  220. echo >> release.txt
  221. [ -e changes.txt ] && cat changes.txt >> release.txt
  222. cat release.txt
  223. curl -sS -X POST -H "authorization: token ${{secrets.BOT_TOKEN}}" \
  224. "$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/releases" \
  225. -d "$(jq -n --rawfile release release.txt '{
  226. tag_name: env.LFS_VERSION,
  227. name: env.LFS_VERSION | rtrimstr(".0"),
  228. target_commitish: "${{github.event.workflow_run.head_sha}}",
  229. draft: env.LFS_VERSION | endswith(".0"),
  230. body: $release,
  231. }' | tee /dev/stderr)"