release.yml 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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-latest
  10. # need to manually check for a couple things
  11. # - tests passed?
  12. # - we are the most recent commit on master?
  13. if: |
  14. github.event.workflow_run.conclusion == 'success' &&
  15. github.event.workflow_run.head_sha == github.sha
  16. steps:
  17. - uses: actions/checkout@v2
  18. with:
  19. ref: ${{github.event.workflow_run.head_sha}}
  20. # need workflow access since we push branches
  21. # containing workflows
  22. token: ${{secrets.BOT_TOKEN}}
  23. # need all tags
  24. fetch-depth: 0
  25. # try to get results from tests
  26. - uses: dawidd6/action-download-artifact@v2
  27. continue-on-error: true
  28. with:
  29. workflow: ${{github.event.workflow_run.name}}
  30. run_id: ${{github.event.workflow_run.id}}
  31. name: results
  32. path: results
  33. - name: find-version
  34. run: |
  35. # rip version from lfs.h
  36. LFS_VERSION="$(grep -o '^#define LFS_VERSION .*$' lfs.h \
  37. | awk '{print $3}')"
  38. LFS_VERSION_MAJOR="$((0xffff & ($LFS_VERSION >> 16)))"
  39. LFS_VERSION_MINOR="$((0xffff & ($LFS_VERSION >> 0)))"
  40. # find a new patch version based on what we find in our tags
  41. LFS_VERSION_PATCH="$( \
  42. ( git describe --tags --abbrev=0 \
  43. --match="v$LFS_VERSION_MAJOR.$LFS_VERSION_MINOR.*" \
  44. || echo 'v0.0.-1' ) \
  45. | awk -F '.' '{print $3+1}')"
  46. # found new version
  47. LFS_VERSION="v$LFS_VERSION_MAJOR`
  48. `.$LFS_VERSION_MINOR`
  49. `.$LFS_VERSION_PATCH"
  50. echo "LFS_VERSION=$LFS_VERSION"
  51. echo "LFS_VERSION=$LFS_VERSION" >> $GITHUB_ENV
  52. echo "LFS_VERSION_MAJOR=$LFS_VERSION_MAJOR" >> $GITHUB_ENV
  53. echo "LFS_VERSION_MINOR=$LFS_VERSION_MINOR" >> $GITHUB_ENV
  54. echo "LFS_VERSION_PATCH=$LFS_VERSION_PATCH" >> $GITHUB_ENV
  55. # try to find previous version?
  56. - name: find-prev-version
  57. continue-on-error: true
  58. run: |
  59. LFS_PREV_VERSION="$(git describe --tags --abbrev=0 --match 'v*')"
  60. echo "LFS_PREV_VERSION=$LFS_PREV_VERSION"
  61. echo "LFS_PREV_VERSION=$LFS_PREV_VERSION" >> $GITHUB_ENV
  62. # try to find results from tests
  63. - name: collect-results
  64. run: |
  65. [ -e results/code-thumb.csv ] && \
  66. ./scripts/code.py -u results/code-thumb.csv -s \
  67. | awk 'NR==2 {printf "Code size,%d B\n",$2}' \
  68. >> results.csv
  69. [ -e results/code-thumb-readonly.csv ] && \
  70. ./scripts/code.py -u results/code-thumb-readonly.csv -s \
  71. | awk 'NR==2 {printf "Code size (readonly),%d B\n",$2}' \
  72. >> results.csv
  73. [ -e results/code-thumb-threadsafe.csv ] && \
  74. ./scripts/code.py -u results/code-thumb-threadsafe.csv -s \
  75. | awk 'NR==2 {printf "Code size (threadsafe),%d B\n",$2}' \
  76. >> results.csv
  77. [ -e results/code-thumb-migrate.csv ] && \
  78. ./scripts/code.py -u results/code-thumb-migrate.csv -s \
  79. | awk 'NR==2 {printf "Code size (migrate),%d B\n",$2}' \
  80. >> results.csv
  81. [ -e results/coverage.csv ] && \
  82. ./scripts/coverage.py -u results/coverage.csv -s \
  83. | awk 'NR==2 {printf "Coverage,%.1f%% of %d lines\n",$4,$3}' \
  84. >> results.csv
  85. [ -e results.csv ] || exit 0
  86. awk -F ',' '
  87. {label[NR]=$1; value[NR]=$2}
  88. END {
  89. for (r=1; r<=NR; r++) {printf "| %s ",label[r]}; printf "|\n";
  90. for (r=1; r<=NR; r++) {printf "|--:"}; printf "|\n";
  91. for (r=1; r<=NR; r++) {printf "| %s ",value[r]}; printf "|\n"}' \
  92. results.csv > results.txt
  93. echo "RESULTS:"
  94. cat results.txt
  95. # find changes from history
  96. - name: collect-changes
  97. run: |
  98. [ ! -z "$LFS_PREV_VERSION" ] || exit 0
  99. git log --oneline "$LFS_PREV_VERSION.." \
  100. --grep='^Merge' --invert-grep > changes.txt
  101. echo "CHANGES:"
  102. cat changes.txt
  103. # create and update major branches (vN and vN-prefix)
  104. - name: build-major-branches
  105. run: |
  106. # create major branch
  107. git branch "v$LFS_VERSION_MAJOR" HEAD
  108. # create major prefix branch
  109. git config user.name ${{secrets.BOT_USERNAME}}
  110. git config user.email ${{secrets.BOT_EMAIL}}
  111. git fetch "https://github.com/$GITHUB_REPOSITORY.git" \
  112. "v$LFS_VERSION_MAJOR-prefix" || true
  113. ./scripts/prefix.py "lfs$LFS_VERSION_MAJOR"
  114. git branch "v$LFS_VERSION_MAJOR-prefix" $( \
  115. git commit-tree $(git write-tree) \
  116. $(git rev-parse --verify -q FETCH_HEAD | sed -e 's/^/-p /') \
  117. -p HEAD \
  118. -m "Generated v$LFS_VERSION_MAJOR prefixes")
  119. git reset --hard
  120. # push!
  121. git push --atomic origin \
  122. "v$LFS_VERSION_MAJOR" \
  123. "v$LFS_VERSION_MAJOR-prefix"
  124. # build release notes
  125. - name: build-release
  126. run: |
  127. # find changes since last release
  128. #if [ ! -z "$LFS_PREV_VERSION" ]
  129. #then
  130. # export CHANGES="$(git log --oneline "$LFS_PREV_VERSION.." \
  131. # --grep='^Merge' --invert-grep)"
  132. # printf "CHANGES\n%s\n\n" "$CHANGES"
  133. #fi
  134. # create release and patch version tag (vN.N.N)
  135. # only draft if not a patch release
  136. [ -e results.txt ] && export RESULTS="$(cat results.txt)"
  137. [ -e changes.txt ] && export CHANGES="$(cat changes.txt)"
  138. curl -sS -H "authorization: token ${{secrets.BOT_TOKEN}}" \
  139. "$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/releases" \
  140. -d "$(jq -sR '{
  141. tag_name: env.LFS_VERSION,
  142. name: env.LFS_VERSION | rtrimstr(".0"),
  143. target_commitish: "${{github.event.workflow_run.head_sha}}",
  144. draft: env.LFS_VERSION | endswith(".0"),
  145. body: [env.RESULTS, env.CHANGES | select(.)] | join("\n\n")}' \
  146. | tee /dev/stderr)" > /dev/null