Skip to content

Commit d509bb0

Browse files
committed
ci: fix workflow when there are no builds or no tests
1 parent 0603d10 commit d509bb0

File tree

2 files changed

+79
-42
lines changed

2 files changed

+79
-42
lines changed

.github/get_idf_build_apps_args.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ def main():
1212

1313
modified_files = args.modified_files_list.read().splitlines()
1414
idf_build_apps_args = []
15-
idf_build_apps_args += [
16-
'--modified-files',
17-
';'.join(modified_files)
18-
]
15+
if modified_files:
16+
idf_build_apps_args += [
17+
'--modified-files',
18+
'"' + ';'.join(modified_files) + '"'
19+
]
1920

2021
if args.verbose:
2122
print('Modified files:')
@@ -32,18 +33,24 @@ def main():
3233
continue
3334
modified_components.add(toplevel)
3435

35-
idf_build_apps_args += [
36-
'--modified-components',
37-
';'.join(modified_components)
38-
]
39-
40-
args.idf_build_apps_args.write(' '.join(idf_build_apps_args))
36+
if modified_components:
37+
idf_build_apps_args += [
38+
'--modified-components',
39+
'"' + ';'.join(modified_components) + '"'
40+
]
41+
else:
42+
idf_build_apps_args += [
43+
'--modified-components',
44+
'dummy_component'
45+
]
4146

4247
if args.verbose:
4348
print('Modified components:')
4449
for component in sorted(modified_components):
4550
print(f' - {component}')
4651

52+
args.idf_build_apps_args.write(' '.join(idf_build_apps_args))
53+
4754

4855
if __name__ == '__main__':
4956
main()

.github/workflows/build_and_run_apps.yml

Lines changed: 62 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,20 @@ on:
77
types: [opened, reopened, synchronize]
88

99
jobs:
10-
build:
11-
name: Build Apps
12-
strategy:
13-
fail-fast: false
14-
matrix:
15-
idf_ver:
16-
- "release-v5.0"
17-
- "release-v5.1"
18-
- "release-v5.2"
19-
- "release-v5.3"
20-
- "latest"
21-
parallel_index: [1,2,3,4,5] # Update --parallel-count below when changing this
10+
prepare:
11+
name: Prepare pipeline
2212
runs-on: ubuntu-22.04
23-
container: espressif/idf:${{ matrix.idf_ver }}
13+
permissions:
14+
contents: read
15+
pull-requests: read
16+
outputs:
17+
test_all_apps: ${{ steps.get_labels.outputs.test_all_apps }}
18+
build_only: ${{ steps.get_labels.outputs.build_only }}
19+
idf_build_apps_args: ${{ steps.find_changes.outputs.idf_build_apps_args }}
2420
steps:
2521
- uses: actions/checkout@v4
2622
with:
2723
submodules: 'true'
28-
- name: Install dependencies
29-
shell: bash
30-
run: |
31-
. ${IDF_PATH}/export.sh
32-
pip install --upgrade idf-component-manager 'idf-build-apps>=2.4,<2.5'
3324
- name: Fix git repo permissions
3425
# Needed by the next git diff step.
3526
# See https://github.com/actions/runner/issues/2033
@@ -39,32 +30,70 @@ jobs:
3930
cd /
4031
git config --global --add safe.directory $build_dir
4132
cd -
42-
- name: Find files and component changed in PR
33+
- name: Install dependencies
34+
run: pip install 'idf-build-apps>=2.4,<2.5'
35+
- name: Get labels
36+
id: get_labels
4337
if: github.event_name == 'pull_request'
44-
# For PRs only:
45-
# - find the files changed in the PR
38+
env:
39+
GH_TOKEN: ${{ github.token }}
40+
# Check for labels
41+
# "PR: test all apps"
42+
# "PR: build only"
43+
run: |
44+
gh api --jq '.labels.[].name' /repos/{owner}/{repo}/pulls/${{ github.event.number }} > labels.txt
45+
test_all_apps=$(grep -c 'PR: test all apps' labels.txt || true)
46+
build_only=$(grep -c 'PR: build only' labels.txt || true)
47+
echo "test_all_apps=$test_all_apps" >> $GITHUB_OUTPUT
48+
echo "build_only=$build_only" >> $GITHUB_OUTPUT
49+
50+
- name: Find changed files and components
51+
id: find_changes
52+
if: github.event_name == 'pull_request' && steps.get_labels.outputs.test_all_apps == '0'
4653
# - based on the files list, determine which components have changed
4754
# - output both lists as a file of idf-build-apps arguments
4855
run: |
4956
git fetch --recurse-submodules=no origin ${{ github.base_ref }}:base_ref
5057
git fetch --recurse-submodules=no origin pull/${{ github.event.pull_request.number }}/head:pr_ref
5158
git diff --name-only -r base_ref pr_ref > changed_files.txt
5259
python3 .github/get_idf_build_apps_args.py -v changed_files.txt idf_build_apps_args.txt
53-
- name: Find apps
60+
echo "idf_build_apps_args=$(cat idf_build_apps_args.txt)" >> $GITHUB_OUTPUT
61+
echo "idf_build_apps_args=$(cat idf_build_apps_args.txt)"
62+
63+
build:
64+
name: Build Apps
65+
needs: prepare
66+
strategy:
67+
fail-fast: false
68+
matrix:
69+
idf_ver:
70+
# - "release-v5.0"
71+
# - "release-v5.1"
72+
# - "release-v5.2"
73+
# - "release-v5.3"
74+
- "latest"
75+
parallel_index: [1] #,2,3,4,5] # Update --parallel-count below when changing this
76+
runs-on: ubuntu-22.04
77+
container: espressif/idf:${{ matrix.idf_ver }}
78+
steps:
79+
- uses: actions/checkout@v4
80+
with:
81+
submodules: 'true'
82+
- name: Install dependencies
5483
shell: bash
5584
run: |
5685
. ${IDF_PATH}/export.sh
57-
idf-build-apps find
86+
pip install --upgrade idf-component-manager 'idf-build-apps>=2.4,<2.5'
5887
- name: Build apps
5988
shell: bash
6089
run: |
6190
. ${IDF_PATH}/export.sh
6291
export PEDANTIC_FLAGS="-DIDF_CI_BUILD -Werror -Werror=deprecated-declarations -Werror=unused-variable -Werror=unused-but-set-variable -Werror=unused-function"
6392
export EXTRA_CFLAGS="${PEDANTIC_FLAGS} -Wstrict-prototypes"
6493
export EXTRA_CXXFLAGS="${PEDANTIC_FLAGS}"
65-
touch idf_build_apps_args.txt
66-
idf-build-apps build --parallel-index ${{ matrix.parallel_index }} --parallel-count 5 --collect-app-info build_info_${{ matrix.idf_ver }}_${{ matrix.parallel_index }}.json $(cat idf_build_apps_args.txt)
94+
idf-build-apps build --parallel-index ${{ matrix.parallel_index }} --parallel-count 1 --collect-app-info build_info_${{ matrix.idf_ver }}_${{ matrix.parallel_index }}.json ${{ needs.prepare.outputs.idf_build_apps_args }}
6795
- uses: actions/upload-artifact@v4
96+
if: ${{ github.repository_owner == 'espressif' }} && ${{ needs.prepare.outputs.build_only == '0' }}
6897
with:
6998
name: app_binaries_${{ matrix.idf_ver }}_${{ matrix.parallel_index }}
7099
path: |
@@ -82,16 +111,16 @@ jobs:
82111
83112
run-target:
84113
name: Run apps on target
85-
if: ${{ github.repository_owner == 'espressif' }}
114+
if: ${{ github.repository_owner == 'espressif' }} && ${{ needs.prepare.outputs.build_only == '0' }}
86115
needs: build
87116
strategy:
88117
fail-fast: false
89118
matrix:
90119
idf_ver:
91-
- "release-v5.0"
92-
- "release-v5.1"
93-
- "release-v5.2"
94-
- "release-v5.3"
120+
# - "release-v5.0"
121+
# - "release-v5.1"
122+
# - "release-v5.2"
123+
# - "release-v5.3"
95124
- "latest"
96125
runner:
97126
- runs-on: "esp32"
@@ -116,12 +145,12 @@ jobs:
116145
- name: Install Python packages
117146
env:
118147
PIP_EXTRA_INDEX_URL: "https://dl.espressif.com/pypi/"
119-
run: pip install --prefer-binary cryptography pytest-embedded pytest-embedded-serial-esp pytest-embedded-idf
148+
run: pip install --prefer-binary cryptography pytest-embedded pytest-embedded-serial-esp pytest-embedded-idf pytest-custom_exit_code
120149
- name: Run apps
121150
run: |
122151
python3 .github/get_pytest_args.py --target=${{ matrix.runner.target }} -v 'build_info*.json' pytest-args.txt
123152
cat pytest-args.txt
124-
pytest $(cat pytest-args.txt) --ignore-glob '*/managed_components/*' --ignore=test_app --ignore=.github --junit-xml=${{ env.TEST_RESULT_FILE }} --target=${{ matrix.runner.target }} -m ${{ matrix.runner.marker }} --build-dir=build_${{ matrix.runner.target }}
153+
pytest --suppress-no-test-exit-code $(cat pytest-args.txt) --ignore-glob '*/managed_components/*' --ignore=test_app --ignore=.github --junit-xml=${{ env.TEST_RESULT_FILE }} --target=${{ matrix.runner.target }} -m ${{ matrix.runner.marker }} --build-dir=build_${{ matrix.runner.target }}
125154
- name: Upload test results
126155
uses: actions/upload-artifact@v4
127156
if: always()
@@ -145,3 +174,4 @@ jobs:
145174
uses: EnricoMi/publish-unit-test-result-action@v2
146175
with:
147176
files: test_results/**/*.xml
177+

0 commit comments

Comments
 (0)