-
Notifications
You must be signed in to change notification settings - Fork 10
/
action.yml
223 lines (192 loc) · 7.62 KB
/
action.yml
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
name: "Build Flipper Application Package (.fap)"
author: "@flipperdevices"
description: |
Provides a composite action to install `ufbt`, build and lint applications for Flipper Zero.
branding:
icon: 'cpu'
color: 'orange'
inputs:
app-dir:
description: Path to application's source code (if not the root of repository)
required: false
default: "."
task:
description: "Task to run. Valid values: 'build', 'lint', 'setup'"
required: false
default: build
ufbt-args:
description: Extra arguments to pass to 'ufbt' for build and lint tasks. Default is '-s' to suppress ufbt output and only show subprocess output
required: false
default: "-s"
skip-setup:
description: Skip ufbt setup. Useful for multiple invocation of the action
required: false
default: ${{ false }}
sdk-channel:
description: Release channel to use. Matches argument "--channel" for ufbt update
required: false
default: ""
sdk-branch:
description: Branch to use for updates. Matches argument "--branch" for ufbt update
required: false
default: ""
sdk-index-url:
description: Index URL to use for updates. Matches argument "--index-url" for ufbt update
required: false
default: ""
sdk-file:
description: Path to SDK archive. Matches argument "--local" for ufbt update
required: false
default: ""
sdk-url:
description: URL to SDK archive. Matches argument "--url" for ufbt update
required: false
default: ""
sdk-hw-target:
description: Hardware target to use. Matches argument "--hw-target" for ufbt update
required: false
default: ""
ufbt-version:
description: ufbt version to use. Can be 'latest', 'prerelease' or a specific version from PyPI (e.g. '==0.2.1')
required: false
default: latest
outputs:
fap-artifacts:
description: "Build artifacts"
value: ${{ steps.build-fap.outputs.build_artifacts }}
fap-dir:
description: "Directory containing application build artifacts"
value: ${{ steps.build-fap.outputs.dist_dir }}
api-version:
description: "API version. Set by build task"
value: ${{ steps.build-fap.outputs.api_version }}
suffix:
description: "String, combination of hardware target, API version & SDK version. Set by build task"
value: ${{ steps.build-fap.outputs.suffix }}
lint-messages:
description: Linter output. Set by lint task
value: ${{ steps.lint-app.outputs.lint-messages }}
build-errors:
description: Build errors. Set by build task
value: ${{ steps.build-fap.outputs.build-messages }}
ufbt-status:
description: JSON status object for ufbt. Use with fromJSON()
value: ${{ steps.ufbt-status.outputs.json }}
toolchain-version:
description: Toolchain version
value: ${{ steps.get-tooclhain-version.outputs.required-version }}
runs:
using: composite
steps:
- name: Set up Python
uses: actions/setup-python@v5
if: inputs.skip-setup == 'false'
with:
python-version: '3.11'
- name: Install ufbt
if: inputs.skip-setup == 'false'
shell: bash
run: |
python3 -m pip install --upgrade pip
if [ "${{ inputs.ufbt-version }}" == "prerelease" ]; then
python3 -m pip install --upgrade --pre ufbt
elif [ "${{ inputs.ufbt-version }}" == "latest" ]; then
python3 -m pip install --upgrade ufbt
else
python3 -m pip install --upgrade ufbt${{ inputs.ufbt-version }}
fi
- name: Update ufbt
shell: bash
run: |
UFBT_UPDATE_ARGS=""
if [ -n "${{ inputs.sdk-hw-target }}" ]; then
UFBT_UPDATE_ARGS="$UFBT_UPDATE_ARGS --hw-target ${{ inputs.sdk-hw-target }}"
fi
if [ -n "${{ inputs.sdk-channel }}" ]; then
UFBT_UPDATE_ARGS="$UFBT_UPDATE_ARGS --channel ${{ inputs.sdk-channel }}"
fi
if [ -n "${{ inputs.sdk-branch }}" ]; then
UFBT_UPDATE_ARGS="$UFBT_UPDATE_ARGS --branch ${{ inputs.sdk-branch }}"
fi
if [ -n "${{ inputs.sdk-index-url }}" ]; then
UFBT_UPDATE_ARGS="$UFBT_UPDATE_ARGS --index-url ${{ inputs.sdk-index-url }}"
fi
if [ -n "${{ inputs.sdk-file }}" ]; then
UFBT_UPDATE_ARGS="$UFBT_UPDATE_ARGS --local ${{ inputs.sdk-file }}"
fi
if [ -n "${{ inputs.sdk-url }}" ]; then
UFBT_UPDATE_ARGS="$UFBT_UPDATE_ARGS --url ${{ inputs.sdk-url }}"
fi
ufbt update $UFBT_UPDATE_ARGS
- name: Get ufbt status as JSON
id: ufbt-status
shell: bash
run: |
echo "json=$(ufbt status --json)" >> $GITHUB_OUTPUT
- name: Check toolchain version
id: get-tooclhain-version
shell: bash
run: |
echo "required-version=`bash -c "export $(grep FBT_TOOLCHAIN_VERSION\= ${{ fromJSON(steps.ufbt-status.outputs.json).sdk_dir }}/scripts/toolchain/fbtenv.sh) printenv FBT_TOOLCHAIN_VERSION"`" >> $GITHUB_OUTPUT
echo "deployed-version=`cat ${{ fromJSON(steps.ufbt-status.outputs.json).toolchain_dir }}/*/VERSION 2>/dev/null || echo 0`" >> $GITHUB_OUTPUT
- name: Cache toolchain
uses: actions/cache@v4
if: steps.get-tooclhain-version.outputs.required-version != steps.get-tooclhain-version.outputs.deployed-version
with:
path: ${{ fromJSON(steps.ufbt-status.outputs.json).toolchain_dir }}
key: ${{ runner.os }}-fbt-toolchain-${{ steps.get-tooclhain-version.outputs.required-version }}
- name: Add problem matcher
shell: bash
run: |
echo "::add-matcher::${{ github.action_path }}/ufbt-problem-matcher.json"
- name: Build app
id: build-fap
if: inputs.task == 'build'
shell: bash
run: |
set +e
FAP_SRC_PATH=`realpath ${{ inputs.app-dir }}`
DIST_PATH=$FAP_SRC_PATH/dist
cd $FAP_SRC_PATH
BUILD_MESSAGES="$(ufbt ${{ inputs.ufbt-args }} 2>&1 | tee /dev/stderr)"
BUILD_STATUS=${PIPESTATUS[0]}
if [ "$BUILD_STATUS" -ne 0 ]; then
# Save multiline output
echo "build-messages<<EOF" >> $GITHUB_OUTPUT
echo "$BUILD_MESSAGES" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
printf "Build errors:\n\`\`\`\n" >> $GITHUB_STEP_SUMMARY
echo "$BUILD_MESSAGES" >> $GITHUB_STEP_SUMMARY
printf "\n\`\`\`\n" >> $GITHUB_STEP_SUMMARY
# Exit with error code
exit $BUILD_STATUS
fi
API_VERSION=$(ufbt -s get_apiversion || echo 0.0)
echo "build_artifacts<<EOF" >> $GITHUB_OUTPUT
echo "$(ls $DIST_PATH/*.fa[pl] || echo '')" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "api_version=$API_VERSION" >> $GITHUB_OUTPUT
echo "dist_dir=$DIST_PATH" >> $GITHUB_OUTPUT
echo "suffix=${{ fromJSON(steps.ufbt-status.outputs.json).target }}-api-$API_VERSION-${{ fromJSON(steps.ufbt-status.outputs.json).version }}" >> $GITHUB_OUTPUT
- name: Lint sources
id: lint-app
if: inputs.task == 'lint'
shell: bash
run: |
set +e
cd ${{ inputs.app-dir }}
LINT_MESSAGES="$(ufbt lint ${{ inputs.ufbt-args }} 2>&1 | tee /dev/stderr)"
LINT_STATUS=${PIPESTATUS[0]}
if [ "$LINT_STATUS" -eq 0 ]; then
echo "Lint: all good ✨" >> $GITHUB_STEP_SUMMARY
else
# Save multiline output
echo "lint-messages<<EOF" >> $GITHUB_OUTPUT
echo "$LINT_MESSAGES" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
printf "Lint errors:\n\`\`\`\n" >> $GITHUB_STEP_SUMMARY
echo "$LINT_MESSAGES" >> $GITHUB_STEP_SUMMARY
printf "\n\`\`\`\n" >> $GITHUB_STEP_SUMMARY
# Exit with error code
exit $LINT_STATUS
fi