-
-
Notifications
You must be signed in to change notification settings - Fork 537
232 lines (211 loc) · 9.7 KB
/
Copy pathbuild.yml
File metadata and controls
232 lines (211 loc) · 9.7 KB
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
name: "Build"
on:
push:
branches:
- "**"
- "!release"
tags:
- "*"
pull_request:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
env:
DEFAULT_TARGET: f7
FBT_GIT_SUBMODULE_SHALLOW: 1
jobs:
build:
permissions:
issues: write
pull-requests: write
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
target: [f7]
steps:
- name: "Checkout code"
uses: actions/checkout@v4
with:
fetch-depth: 1
ref: ${{ github.event.pull_request.head.sha }}
- name: "Get commit details"
id: names
run: |
BUILD_TYPE='DEBUG=0 COMPACT=1'
if [[ ${{ github.event_name }} == 'pull_request' ]]; then
TYPE="pull"
elif [[ "${{ github.ref }}" == "refs/tags/"* ]]; then
TYPE="tag"
else
TYPE="other"
fi
python3 scripts/get_env.py "--event_file=${{ github.event_path }}" "--type=$TYPE" || cat "${{ github.event_path }}"
echo "event_type=$TYPE" >> $GITHUB_OUTPUT
echo "FBT_BUILD_TYPE=$BUILD_TYPE" >> $GITHUB_ENV
echo "TARGET=${{ matrix.target }}" >> $GITHUB_ENV
echo "TARGET_HW=$(echo "${{ matrix.target }}" | sed 's/f//')" >> $GITHUB_ENV
- name: "Check API versions for consistency between targets"
run: |
set -e
N_API_HEADER_SIGNATURES=`ls -1 targets/f*/api_symbols.csv | xargs -I {} sh -c "head -n2 {} | md5sum" | sort -u | wc -l`
if [ $N_API_HEADER_SIGNATURES != 1 ] ; then
echo API versions aren\'t matching for available targets. Please update!
echo API versions are:
head -n2 targets/f*/api_symbols.csv
exit 1
fi
- name: "Check API version for consistency with OFW release channel"
run: |
set -e
symbols="targets/$TARGET/api_symbols.csv"
ofw_api="$(curl -s "https://raw.githubusercontent.com/flipperdevices/flipperzero-firmware/release/${symbols}" | head -n2)"
our_api="$(head -n2 "${symbols}")"
if [ "$our_api" != "$ofw_api" ] ; then
echo API versions aren\'t matching OFW release channel. Please update!
echo API versions are:
echo "Official: $(tail -n1 <<< "$ofw_api")"
echo "Momentum: $(tail -n1 <<< "$our_api")"
exit 1
fi
- name: "Configure for Devbuild/PR/Upload"
run: |
if ${{ secrets.INDEXER_URL == '' }} ; then
exit
fi
if ${{ github.event_name == 'push' }} ; then
if ${{ github.ref_name == 'dev' }} ; then
SHOULD_DEVBUILD=${{ !contains(github.event.head_commit.message, '--nobuild') }}
SHOULD_UPLOAD=$SHOULD_DEVBUILD
SHOULD_DEPLOY=$SHOULD_DEVBUILD
elif ${{ startsWith(github.ref, 'refs/tags/') }} ; then
SHOULD_UPLOAD=true
fi
elif ${{ !!github.event.pull_request }} ; then
SHOULD_PRBUILD=${{ matrix.target == env.DEFAULT_TARGET }}
SHOULD_UPLOAD=$SHOULD_PRBUILD
SHOULD_DEPLOY=$SHOULD_PRBUILD
else
echo "What?"
exit 1
fi
echo "SHOULD_DEVBUILD=$SHOULD_DEVBUILD" >> $GITHUB_ENV
echo "SHOULD_PRBUILD=$SHOULD_PRBUILD" >> $GITHUB_ENV
echo "SHOULD_UPLOAD=$SHOULD_UPLOAD" >> $GITHUB_ENV
echo "SHOULD_DEPLOY=$SHOULD_DEPLOY" >> $GITHUB_ENV
- name: "Build the firmware and apps"
id: build-fw
run: |
./fbt TARGET_HW=$TARGET_HW $FBT_BUILD_TYPE copro_dist updater_package fap_dist
echo "firmware_api=$(./fbt TARGET_HW=$TARGET_HW get_apiversion)" >> $GITHUB_OUTPUT
- name: "Check for uncommitted changes"
run: |
git diff --exit-code
- name: "Upload artifacts to GitHub"
uses: actions/upload-artifact@v4
with:
path: |
dist/${{ env.TARGET }}-*/flipper-z-${{ env.TARGET }}-update-*
dist/${{ env.TARGET }}-*/flipper-z-${{ env.TARGET }}-sdk-*
- name: "Copy build output"
if: ${{ env.SHOULD_UPLOAD == 'true' }}
run: |
set -e
rm -rf artifacts || true
mkdir artifacts
cp dist/${TARGET}-*/flipper-z-${TARGET}-{update-*.tgz,sdk-*.zip,full-*.dfu} artifacts/
tar czpf "artifacts/flipper-z-${TARGET}-resources-${SUFFIX}.tgz" \
-C build/latest resources
cd dist/${TARGET}-*/${TARGET}-update-*/
ARTIFACT_TAG=flipper-z-"$(basename "$(realpath .)")"
7z a ../../../artifacts/${ARTIFACT_TAG}.zip .
echo "ARTIFACT_TAG=$ARTIFACT_TAG" >> $GITHUB_ENV
VERSION_TAG="$(basename "$(realpath .)" | cut -d- -f3-)"
echo "VERSION_TAG=$VERSION_TAG" >> $GITHUB_ENV
- name: "Copy universal artifacts"
if: ${{ env.SHOULD_UPLOAD == 'true' }}
run: |
tar czpf "artifacts/flipper-z-any-scripts-${SUFFIX}.tgz" scripts
cp build/core2_firmware.tgz "artifacts/flipper-z-any-core2_firmware-${SUFFIX}.tgz"
- name: "Upload artifacts to update server"
if: ${{ env.SHOULD_UPLOAD == 'true' }}
run: |
curl "${{ secrets.INDEXER_URL }}"/firmware/directory.json > previndex.json
FILES=$(for ARTIFACT in $(find artifacts -maxdepth 1 -not -type d); do echo "-F files=@${ARTIFACT}"; done)
curl --fail -L -H "Token: ${{ secrets.INDEXER_TOKEN }}" \
-F "branch=${BRANCH_NAME}" \
-F "version_token=${COMMIT_SHA}" \
${FILES[@]} \
"${{ secrets.INDEXER_URL }}"/firmware/uploadfiles
- name: "Force deploy website to refresh devbuilds"
if: ${{ env.SHOULD_DEPLOY == 'true' }}
uses: Codex-/return-dispatch@v2
id: force-deploy
with:
token: ${{ secrets.REPO_DISPATCH_TOKEN }}
ref: dev
repo: v2.momentum-fw.dev
owner: Next-Flip
workflow: force-deploy.yml
workflow_timeout_seconds: 300
workflow_job_steps_retry_seconds: 5
- name: "Calculate DFU sizes"
if: ${{ env.SHOULD_PRBUILD == 'true' }}
run: |
curl -L "${{ secrets.INDEXER_URL }}"/firmware/development/f7/full_dfu -o dev.dfu
dfu_size_new=$(du --apparent-size -B 1 artifacts/flipper-z-${TARGET}-full-*.dfu | cut -f1)
dfu_size_dev=$(du --apparent-size -B 1 dev.dfu | cut -f1)
dfu_size_diff=$((dfu_size_new - dfu_size_dev))
DFU_SIZE=$(echo $dfu_size_new | numfmt --to=iec-i --format=%.2fB | sed 's/.00B$/B/')
DFU_DIFF=$(echo $dfu_size_diff | numfmt --to=iec-i --format=%.2fB | sed 's/.00B$/B/' | sed -r 's/^([^-])/+\1/')
echo "DFU_SIZE=$DFU_SIZE" >> $GITHUB_ENV
echo "DFU_DIFF=$DFU_DIFF" >> $GITHUB_ENV
tar xzf build/core2_firmware.tgz
radio_addr=$(jq -r '.copro.radio.files[0].address' core2_firmware/Manifest.json)
flash_base=0x8000000
min_gap=$((0 * 4 * 1024))
flash_free_total=$((radio_addr - flash_base - dfu_size_new))
flash_free_usable=$((flash_free_total - min_gap))
FLASH_FREE=$(echo $flash_free_total | numfmt --to=iec-i --format=%.2fB | sed 's/.00B$/B/')
FLASH_USABLE=$(echo $flash_free_usable | numfmt --to=iec-i --format=%.2fB | sed 's/.00B$/B/')
echo "FLASH_FREE=$FLASH_FREE" >> $GITHUB_ENV
echo "FLASH_USABLE=$FLASH_USABLE" >> $GITHUB_ENV
- name: "Find previous comment"
if: ${{ env.SHOULD_PRBUILD == 'true' }}
uses: peter-evans/find-comment@v3
id: find-comment
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: "github-actions[bot]"
body-includes: "Compiled ${{ matrix.target }} firmware for commit"
- name: "Wait for deploy (Run ID ${{ steps.force-deploy.outputs.run_id }})"
if: ${{ env.SHOULD_DEPLOY == 'true' }}
uses: Codex-/await-remote-run@v1
with:
token: ${{ github.token }}
repo: v2.momentum-fw.dev
owner: Next-Flip
run_id: ${{ steps.force-deploy.outputs.run_id }}
run_timeout_seconds: 300
poll_interval_ms: 5000
- name: "Create or update comment"
if: ${{ env.SHOULD_PRBUILD == 'true' }}
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
**Compiled ${{ matrix.target }} firmware for commit `${{steps.names.outputs.commit_sha}}`:**
- [🖥️ Web Updater](https://momentum-fw.dev/update?branch=${{steps.names.outputs.branch_name_urlencoded}})
- [☁️ Flipper Lab/App](https://lab.flipper.net/?url=${{secrets.INDEXER_URL}}/builds/firmware/${{steps.names.outputs.branch_name}}/flipper-z-${{steps.names.outputs.default_target}}-update-${{steps.names.outputs.suffix}}.tgz&channel=mntm-${{steps.names.outputs.branch_name}}&version=${{steps.names.outputs.commit_sha}})
- [📦 qFlipper Package](${{secrets.INDEXER_URL}}/builds/firmware/${{steps.names.outputs.branch_name}}/flipper-z-${{steps.names.outputs.default_target}}-update-${{steps.names.outputs.suffix}}.tgz)
- DFU Size: `${{ env.DFU_SIZE }}` (`${{ env.DFU_DIFF }}` from dev)
- Free Flash: `${{ env.FLASH_FREE }}` (`${{ env.FLASH_USABLE }}` usable)
edit-mode: replace
- name: "Send devbuild webhook"
env:
INDEXER_URL: ${{ secrets.INDEXER_URL }}
BUILD_WEBHOOK: ${{ secrets.BUILD_WEBHOOK }}
if: ${{ env.SHOULD_DEVBUILD == 'true' }}
run: |
python .github/workflow_data/devbuild.py