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