Skip to content

Commit

Permalink
ci: fix workflow when there are no builds or no tests
Browse files Browse the repository at this point in the history
  • Loading branch information
igrr committed Oct 1, 2024
1 parent 0603d10 commit 53d94d0
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 42 deletions.
22 changes: 12 additions & 10 deletions .github/get_idf_build_apps_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ def main():

modified_files = args.modified_files_list.read().splitlines()
idf_build_apps_args = []
idf_build_apps_args += [
'--modified-files',
';'.join(modified_files)
]
if modified_files:
idf_build_apps_args += [
'--modified-files',
';'.join(modified_files)
]

if args.verbose:
print('Modified files:')
Expand All @@ -32,18 +33,19 @@ def main():
continue
modified_components.add(toplevel)

idf_build_apps_args += [
'--modified-components',
';'.join(modified_components)
]
if modified_components:
idf_build_apps_args += [
'--modified-components',
';'.join(modified_components)
]

args.idf_build_apps_args.write(' '.join(idf_build_apps_args))

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

args.idf_build_apps_args.write(' '.join(idf_build_apps_args))


if __name__ == '__main__':
main()
90 changes: 58 additions & 32 deletions .github/workflows/build_and_run_apps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,20 @@ on:
types: [opened, reopened, synchronize]

jobs:
build:
name: Build Apps
strategy:
fail-fast: false
matrix:
idf_ver:
- "release-v5.0"
- "release-v5.1"
- "release-v5.2"
- "release-v5.3"
- "latest"
parallel_index: [1,2,3,4,5] # Update --parallel-count below when changing this
prepare:
name: Prepare pipeline
runs-on: ubuntu-22.04
container: espressif/idf:${{ matrix.idf_ver }}
permissions:
contents: read
pull-requests: read
outputs:
test_all_apps: ${{ steps.get_labels.outputs.test_all_apps }}
build_only: ${{ steps.get_labels.outputs.build_only }}
idf_build_apps_args: ${{ steps.find_changes.outputs.idf_build_apps_args }}
steps:
- uses: actions/checkout@v4
with:
submodules: 'true'
- name: Install dependencies
shell: bash
run: |
. ${IDF_PATH}/export.sh
pip install --upgrade idf-component-manager 'idf-build-apps>=2.4,<2.5'
- name: Fix git repo permissions
# Needed by the next git diff step.
# See https://github.com/actions/runner/issues/2033
Expand All @@ -39,32 +30,67 @@ jobs:
cd /
git config --global --add safe.directory $build_dir
cd -
- name: Find files and component changed in PR
- name: Install dependencies
run: pip install 'idf-build-apps>=2.4,<2.5'
- name: Get labels
if: github.event_name == 'pull_request'
# For PRs only:
# - find the files changed in the PR
env:
GH_TOKEN: ${{ github.token }}
# Check for labels
# "PR: test all apps"
# "PR: build only"
run: |
gh api --jq '.labels.[].name' /repos/{owner}/{repo}/pulls/${{ github.event.number }} > labels.txt
test_all_apps=$(grep -c 'PR: test all apps' labels.txt || true)
build_only=$(grep -c 'PR: build only' labels.txt || true)
echo "test_all_apps=$test_all_apps" >> $GITHUB_OUTPUT
echo "build_only=$build_only" >> $GITHUB_OUTPUT
- name: Find changes
if: github.event_name == 'pull_request' && steps.get_labels.outputs.test_all_apps == '0'
# - based on the files list, determine which components have changed
# - output both lists as a file of idf-build-apps arguments
run: |
git fetch --recurse-submodules=no origin ${{ github.base_ref }}:base_ref
git fetch --recurse-submodules=no origin pull/${{ github.event.pull_request.number }}/head:pr_ref
git diff --name-only -r base_ref pr_ref > changed_files.txt
python3 .github/get_idf_build_apps_args.py -v changed_files.txt idf_build_apps_args.txt
- name: Find apps
echo "idf_build_apps_args=$(cat idf_build_apps_args.txt)" >> $GITHUB_OUTPUT
build:
name: Build Apps
needs: prepare
strategy:
fail-fast: false
matrix:
idf_ver:
# - "release-v5.0"
# - "release-v5.1"
# - "release-v5.2"
# - "release-v5.3"
- "latest"
parallel_index: [1,2,3,4,5] # Update --parallel-count below when changing this
runs-on: ubuntu-22.04
container: espressif/idf:${{ matrix.idf_ver }}
steps:
- uses: actions/checkout@v4
with:
submodules: 'true'
- name: Install dependencies
shell: bash
run: |
. ${IDF_PATH}/export.sh
idf-build-apps find
pip install --upgrade idf-component-manager 'idf-build-apps>=2.4,<2.5'
- name: Build apps
shell: bash
run: |
. ${IDF_PATH}/export.sh
export PEDANTIC_FLAGS="-DIDF_CI_BUILD -Werror -Werror=deprecated-declarations -Werror=unused-variable -Werror=unused-but-set-variable -Werror=unused-function"
export EXTRA_CFLAGS="${PEDANTIC_FLAGS} -Wstrict-prototypes"
export EXTRA_CXXFLAGS="${PEDANTIC_FLAGS}"
touch idf_build_apps_args.txt
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)
idf-build-apps build --parallel-index ${{ matrix.parallel_index }} --parallel-count 5 --collect-app-info build_info_${{ matrix.idf_ver }}_${{ matrix.parallel_index }}.json ${{ needs.prepare.outputs.idf_build_apps_args }}
- uses: actions/upload-artifact@v4
if: ${{ github.repository_owner == 'espressif' }} && ${{ needs.prepare.outputs.build_only == '0' }}
with:
name: app_binaries_${{ matrix.idf_ver }}_${{ matrix.parallel_index }}
path: |
Expand All @@ -82,16 +108,16 @@ jobs:
run-target:
name: Run apps on target
if: ${{ github.repository_owner == 'espressif' }}
if: ${{ github.repository_owner == 'espressif' }} && ${{ needs.prepare.outputs.build_only == '0' }}
needs: build
strategy:
fail-fast: false
matrix:
idf_ver:
- "release-v5.0"
- "release-v5.1"
- "release-v5.2"
- "release-v5.3"
# - "release-v5.0"
# - "release-v5.1"
# - "release-v5.2"
# - "release-v5.3"
- "latest"
runner:
- runs-on: "esp32"
Expand All @@ -116,12 +142,12 @@ jobs:
- name: Install Python packages
env:
PIP_EXTRA_INDEX_URL: "https://dl.espressif.com/pypi/"
run: pip install --prefer-binary cryptography pytest-embedded pytest-embedded-serial-esp pytest-embedded-idf
run: pip install --prefer-binary cryptography pytest-embedded pytest-embedded-serial-esp pytest-embedded-idf pytest-custom_exit_code
- name: Run apps
run: |
python3 .github/get_pytest_args.py --target=${{ matrix.runner.target }} -v 'build_info*.json' pytest-args.txt
cat pytest-args.txt
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 }}
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 }}
- name: Upload test results
uses: actions/upload-artifact@v4
if: always()
Expand Down

0 comments on commit 53d94d0

Please sign in to comment.