From 213792f85b83e33bf069c5e7f25ee40100b8ec0b Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Thu, 2 Feb 2023 12:52:08 -0800 Subject: [PATCH] [github-actions] update `toranj-ncp` to trigger on pull request only (#8648) This commit updates the github actions `toranj` workflow and the toranj `start.sh` script to trigger `toranj-ncp` tests on a Pull Request only if there are changes in any of the `src/ncp` files. --- .github/workflows/toranj.yml | 30 +++--------------------- tests/toranj/start.sh | 44 ++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 27 deletions(-) diff --git a/.github/workflows/toranj.yml b/.github/workflows/toranj.yml index dc1548785..bfb4339ab 100644 --- a/.github/workflows/toranj.yml +++ b/.github/workflows/toranj.yml @@ -55,6 +55,8 @@ jobs: env: COVERAGE: 1 TORANJ_RADIO : ${{ matrix.TORANJ_RADIO }} + TORANJ_NCP : 1 + TORANJ_EVENT_NAME: ${{ github.event_name }} steps: - name: Harden Runner uses: step-security/harden-runner@18bf8ad2ca49c14cbb28b91346d626ccfb00c518 # v2.1.0 @@ -69,35 +71,10 @@ jobs: GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" run: | sudo rm /etc/apt/sources.list.d/* && sudo apt-get update - sudo apt-get --no-install-recommends install -y dbus libdbus-1-dev - sudo apt-get --no-install-recommends install -y autoconf-archive - sudo apt-get --no-install-recommends install -y libarchive-tools - sudo apt-get --no-install-recommends install -y libtool - sudo apt-get --no-install-recommends install -y libglib2.0-dev - sudo apt-get --no-install-recommends install -y lcov - - sudo add-apt-repository universe - sudo apt-get update - sudo apt-get --no-install-recommends install -y libboost-all-dev python2 - - script/git-tool clone --depth=1 --branch=master https://github.com/openthread/wpantund.git - cd wpantund - ./bootstrap.sh - ./configure - sudo make -j2 - sudo make install - name: Build & Run run: | top_builddir=$(pwd)/build/toranj ./tests/toranj/start.sh - - name: Generate Coverage - if: "matrix.TORANJ_RADIO != 'multi'" - run: | - ./script/test generate_coverage gcc - - uses: actions/upload-artifact@83fd05a356d7e2593de66fc9913b3002723633cb # v3.1.1 - if: "matrix.TORANJ_RADIO != 'multi'" - with: - name: cov-toranj-ncp-${{ matrix.TORANJ_RADIO }} - path: tmp/coverage.info + toranj-cli: name: toranj-cli-${{ matrix.TORANJ_RADIO }} @@ -166,7 +143,6 @@ jobs: upload-coverage: needs: - - toranj-ncp - toranj-cli runs-on: ubuntu-20.04 steps: diff --git a/tests/toranj/start.sh b/tests/toranj/start.sh index 9e4f325b0..04347f9f1 100755 --- a/tests/toranj/start.sh +++ b/tests/toranj/start.sh @@ -75,8 +75,52 @@ run() done } +install_wpantund() +{ + echo "Installing wpantund" + sudo apt-get --no-install-recommends install -y dbus libdbus-1-dev + sudo apt-get --no-install-recommends install -y autoconf-archive + sudo apt-get --no-install-recommends install -y libarchive-tools + sudo apt-get --no-install-recommends install -y libtool + sudo apt-get --no-install-recommends install -y libglib2.0-dev + sudo apt-get --no-install-recommends install -y lcov + + sudo add-apt-repository universe + sudo apt-get update + sudo apt-get --no-install-recommends install -y libboost-all-dev python2 + + git clone --depth=1 --branch=master https://github.com/openthread/wpantund.git || die "wpandtund clone" + cd wpantund || die "cd wpantund failed" + ./bootstrap.sh + ./configure + sudo make -j2 || die "wpantund make failed" + sudo make install || die "wpantund make install failed" + cd .. || die "cd .. failed" +} + cd "$(dirname "$0")" || die "cd failed" +if [ "$TORANJ_NCP" = 1 ]; then + echo "========================================================================" + echo "Running toranj-ncp triggered by event ${TORANJ_EVENT_NAME}" + + if [ "$TORANJ_EVENT_NAME" = "pull_request" ]; then + cd ../.. + OT_SHA_OLD="$(git cat-file -p HEAD | grep 'parent ' | head -n1 | cut -d' ' -f2)" + git fetch --depth 1 --no-recurse-submodules origin "${OT_SHA_OLD}" + if git diff --name-only --exit-code "${OT_SHA_OLD}" -- src/ncp; then + echo "No changes to any of src/ncp files - skip running tests." + echo "========================================================================" + exit 0 + fi + cd tests/toranj || die "cd tests/toranj failed" + echo "There are change in src/ncp files, running toranj-ncp tests" + fi + + echo "========================================================================" + install_wpantund +fi + if [ -z "${top_builddir}" ]; then top_builddir=. fi