Welcome to mirror list, hosted at ThFree Co, Russian Federation.

release.yml « workflows « .github - github.com/littlefs-project/littlefs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 055b54a0ff1104fcd5f6b4aff643ba671f7706c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
name: release
on:
  workflow_run:
    workflows: [test]
    branches: [master]
    types: [completed]

defaults:
  run:
    shell: bash -euv -o pipefail {0}

jobs:
  release:
    runs-on: ubuntu-latest

    # need to manually check for a couple things
    # - tests passed?
    # - we are the most recent commit on master?
    if: ${{github.event.workflow_run.conclusion == 'success' &&
      github.event.workflow_run.head_sha == github.sha}}

    steps:
      - uses: actions/checkout@v2
        with:
          ref: ${{github.event.workflow_run.head_sha}}
          # need workflow access since we push branches
          # containing workflows
          token: ${{secrets.BOT_TOKEN}}
          # need all tags
          fetch-depth: 0

      # try to get results from tests
      - uses: dawidd6/action-download-artifact@v2
        continue-on-error: true
        with:
          workflow: ${{github.event.workflow_run.name}}
          run_id: ${{github.event.workflow_run.id}}
          name: sizes
          path: sizes
      - uses: dawidd6/action-download-artifact@v2
        continue-on-error: true
        with:
          workflow: ${{github.event.workflow_run.name}}
          run_id: ${{github.event.workflow_run.id}}
          name: cov
          path: cov
      - uses: dawidd6/action-download-artifact@v2
        continue-on-error: true
        with:
          workflow: ${{github.event.workflow_run.name}}
          run_id: ${{github.event.workflow_run.id}}
          name: bench
          path: bench

      - name: find-version
        run: |
          # rip version from lfs.h
          LFS_VERSION="$(grep -o '^#define LFS_VERSION .*$' lfs.h \
            | awk '{print $3}')"
          LFS_VERSION_MAJOR="$((0xffff & ($LFS_VERSION >> 16)))"
          LFS_VERSION_MINOR="$((0xffff & ($LFS_VERSION >>  0)))"

          # find a new patch version based on what we find in our tags
          LFS_VERSION_PATCH="$( \
            ( git describe --tags --abbrev=0 \
                --match="v$LFS_VERSION_MAJOR.$LFS_VERSION_MINOR.*" \
              || echo 'v0.0.-1' ) \
            | awk -F '.' '{print $3+1}')"

          # found new version
          LFS_VERSION="v$LFS_VERSION_MAJOR`
            `.$LFS_VERSION_MINOR`
            `.$LFS_VERSION_PATCH"
          echo "LFS_VERSION=$LFS_VERSION"
          echo "LFS_VERSION=$LFS_VERSION" >> $GITHUB_ENV
          echo "LFS_VERSION_MAJOR=$LFS_VERSION_MAJOR" >> $GITHUB_ENV
          echo "LFS_VERSION_MINOR=$LFS_VERSION_MINOR" >> $GITHUB_ENV
          echo "LFS_VERSION_PATCH=$LFS_VERSION_PATCH" >> $GITHUB_ENV

      # try to find previous version?
      - name: find-prev-version
        continue-on-error: true
        run: |
          LFS_PREV_VERSION="$( \
            git describe --tags --abbrev=0 --match 'v*' \
            || true)"
          echo "LFS_PREV_VERSION=$LFS_PREV_VERSION"
          echo "LFS_PREV_VERSION=$LFS_PREV_VERSION" >> $GITHUB_ENV

      # try to find results from tests
      - name: create-table
        run: |
          # previous results to compare against?
          [ -n "$LFS_PREV_VERSION" ] && curl -sS \
            "$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/status/$LFS_PREV_VERSION`
              `?per_page=100" \
            | jq -re 'select(.sha != env.GITHUB_SHA) | .statuses[]' \
            >> prev-status.json \
            || true

          # build table for GitHub
          declare -A table

          # sizes table
          i=0
          j=0
          for c in "" readonly threadsafe multiversion migrate error-asserts
          do
            # per-config results
            c_or_default=${c:-default}
            c_camel=${c_or_default^}
            table[$i,$j]=$c_camel
            ((j+=1))

            for s in code stack structs
            do
              f=sizes/thumb${c:+-$c}.$s.csv
              [ -e $f ] && table[$i,$j]=$( \
                export PREV="$(jq -re '
                    select(.context == "'"sizes (thumb${c:+, $c}) / $s"'").description
                    | capture("(?<prev>[0-9∞]+)").prev' \
                  prev-status.json || echo 0)"
                ./scripts/summary.py $f --max=stack_limit -Y \
                  | awk '
                    NR==2 {$1=0; printf "%s B",$NF}
                    NR==2 && ENVIRON["PREV"]+0 != 0 {
                      printf " (%+.1f%%)",100*($NF-ENVIRON["PREV"])/ENVIRON["PREV"]
                    }' \
                  | sed -e 's/ /\&nbsp;/g')
              ((j+=1))
            done
            ((j=0, i+=1))
          done

          # coverage table
          i=0
          j=4
          for s in lines branches
          do
            table[$i,$j]=${s^}
            ((j+=1))

            f=cov/cov.csv
            [ -e $f ] && table[$i,$j]=$( \
              export PREV="$(jq -re '
                  select(.context == "'"cov / $s"'").description
                  | capture("(?<prev_a>[0-9]+)/(?<prev_b>[0-9]+)")
                  | 100*((.prev_a|tonumber) / (.prev_b|tonumber))' \
                prev-status.json || echo 0)"
              ./scripts/cov.py -u $f -f$s -Y \
                | awk -F '[ /%]+' -v s=$s '
                  NR==2 {$1=0; printf "%d/%d %s",$2,$3,s}
                  NR==2 && ENVIRON["PREV"]+0 != 0 {
                    printf " (%+.1f%%)",$4-ENVIRON["PREV"]
                  }' \
                | sed -e 's/ /\&nbsp;/g')
            ((j=4, i+=1))
          done

          # benchmark table
          i=3
          j=4
          for s in readed proged erased
          do
            table[$i,$j]=${s^}
            ((j+=1))

            f=bench/bench.csv
            [ -e $f ] && table[$i,$j]=$( \
              export PREV="$(jq -re '
                  select(.context == "'"bench / $s"'").description
                  | capture("(?<prev>[0-9]+)").prev' \
                prev-status.json || echo 0)"
              ./scripts/summary.py $f -f$s=bench_$s -Y \
                | awk '
                  NR==2 {$1=0; printf "%s B",$NF}
                  NR==2 && ENVIRON["PREV"]+0 != 0 {
                    printf " (%+.1f%%)",100*($NF-ENVIRON["PREV"])/ENVIRON["PREV"]
                  }' \
                | sed -e 's/ /\&nbsp;/g')
            ((j=4, i+=1))
          done

          # build the actual table
          echo "|   | Code | Stack | Structs |   | Coverage |" >> table.txt
          echo "|:--|-----:|------:|--------:|:--|---------:|" >> table.txt
          for ((i=0; i<6; i++))
          do
            echo -n "|" >> table.txt
            for ((j=0; j<6; j++))
            do
              echo -n " " >> table.txt
              [[ i -eq 2 && j -eq 5 ]] && echo -n "**Benchmarks**" >> table.txt
              echo -n "${table[$i,$j]:-}" >> table.txt
              echo -n " |" >> table.txt
            done
            echo >> table.txt
          done

          cat table.txt

      # find changes from history
      - name: create-changes
        run: |
          [ -n "$LFS_PREV_VERSION" ] || exit 0
          # use explicit link to github commit so that release notes can
          # be copied elsewhere
          git log "$LFS_PREV_VERSION.." \
            --grep='^Merge' --invert-grep \
            --format="format:[\`%h\`](`
              `https://github.com/$GITHUB_REPOSITORY/commit/%h) %s" \
            > changes.txt
          echo "CHANGES:"
          cat changes.txt

      # create and update major branches (vN and vN-prefix)
      - name: create-major-branches
        run: |
          # create major branch
          git branch "v$LFS_VERSION_MAJOR" HEAD

          # create major prefix branch
          git config user.name ${{secrets.BOT_USER}}
          git config user.email ${{secrets.BOT_EMAIL}}
          git fetch "https://github.com/$GITHUB_REPOSITORY.git" \
            "v$LFS_VERSION_MAJOR-prefix" || true
          ./scripts/changeprefix.py --git "lfs" "lfs$LFS_VERSION_MAJOR"
          git branch "v$LFS_VERSION_MAJOR-prefix" $( \
            git commit-tree $(git write-tree) \
              $(git rev-parse --verify -q FETCH_HEAD | sed -e 's/^/-p /') \
              -p HEAD \
              -m "Generated v$LFS_VERSION_MAJOR prefixes")
          git reset --hard

          # push!
          git push --atomic origin \
            "v$LFS_VERSION_MAJOR" \
            "v$LFS_VERSION_MAJOR-prefix"

      # build release notes
      - name: create-release
        run: |
          # create release and patch version tag (vN.N.N)
          # only draft if not a patch release
          touch release.txt
          [ -e table.txt ] && cat table.txt >> release.txt
          echo >> release.txt
          [ -e changes.txt ] && cat changes.txt >> release.txt
          cat release.txt

          curl -sS -X POST -H "authorization: token ${{secrets.BOT_TOKEN}}" \
            "$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/releases" \
            -d "$(jq -n --rawfile release release.txt '{
              tag_name: env.LFS_VERSION,
              name: env.LFS_VERSION | rtrimstr(".0"),
              target_commitish: "${{github.event.workflow_run.head_sha}}",
              draft: env.LFS_VERSION | endswith(".0"),
              body: $release,
            }' | tee /dev/stderr)"