From 1a5deecf8770d032dea63d99229c15a459877689 Mon Sep 17 00:00:00 2001 From: Jan Prochazka <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Tue, 7 May 2024 13:28:36 +0200 Subject: [PATCH 1/3] feat(ci): Run Wokwi tests on PR --- .github/workflows/wokwi.yml | 121 ++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 .github/workflows/wokwi.yml diff --git a/.github/workflows/wokwi.yml b/.github/workflows/wokwi.yml new file mode 100644 index 00000000000..04e780e8879 --- /dev/null +++ b/.github/workflows/wokwi.yml @@ -0,0 +1,121 @@ +name: Run tests in wokwi on PR + +on: + workflow_run: + workflows: [Run tests] + types: + - completed + +permissions: + statuses: write + +env: + MAX_CHUNKS: 15 + WOKWI_TIMEOUT: 600000 # Milliseconds + WOKWI_CLI_TOKEN: ${{ secrets.WOKWI_CLI_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + +concurrency: + group: hil-${{github.event.pull_request.number || github.ref}} + cancel-in-progress: true + +jobs: + gen_chunks: + if: github.event.workflow_run.event == 'pull_request' + name: Generate Chunks matrix + runs-on: ubuntu-latest + outputs: + chunks: ${{ steps.gen-chunks.outputs.chunks }} + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + with: + ref: ${{ github.event.workflow_run.head_sha }} # Check out the code of the PR to generate accurate chunks + + - name: Generate Chunks matrix + id: gen-chunks + run: | + set +e + .github/scripts/sketch_utils.sh count tests + sketches=$? + if [[ $sketches -ge ${{env.MAX_CHUNKS}} ]]; then + $sketches=${{env.MAX_CHUNKS}} + fi + set -e + rm sketches.txt + CHUNKS=$(jq -c -n '$ARGS.positional' --args `seq 0 1 $((sketches - 1))`) + echo "chunks=${CHUNKS}" >>$GITHUB_OUTPUT + + wokwi-test: + needs: [gen_chunks] + name: ${{matrix.chip}}-Wokwi_Test#${{matrix.chunks}} + strategy: + fail-fast: false + matrix: + chip: ['esp32', 'esp32s2', 'esp32s3', 'esp32c3', 'esp32c6', 'esp32h2'] + chunks: ${{fromJson(needs.gen_chunks.outputs.chunks)}} + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + ref: ${{ github.event.workflow_run.head_sha }} # Check out the code of the PR to get correct pytest files + + - name: Download ${{matrix.chip}}-${{matrix.chunks}} artifacts + uses: actions/download-artifact@v4 + with: + name: ${{matrix.chip}}-${{matrix.chunks}}.artifacts + path: ~/.arduino/tests/ + run-id: ${{github.event.workflow_run.id}} + github-token: ${{env.GITHUB_TOKEN}} + + - name: Install Wokwi CLI + run: curl -L https://wokwi.com/ci/install.sh | sh + + - name: Install dependencies + run: | + pip install -U pip + pip install -r tests/requirements.txt --extra-index-url https://dl.espressif.com/pypi + sudo apt update && sudo apt install -y -qq jq + + - name: Run Tests + run: | + bash .github/scripts/tests_run.sh -c -t ${{matrix.chip}} -i ${{matrix.chunks}} -m ${{env.MAX_CHUNKS}} -w ${{env.WOKWI_TIMEOUT}} + + - name: Upload test result artifacts + uses: actions/upload-artifact@v4 + if: always() + with: + name: wokwi_results-${{matrix.chip}}-${{matrix.chunks}} + path: tests/*/*.xml + + report-result: + name: Report wokwi test result + runs-on: ubuntu-latest + needs: wokwi-test + if: always() && github.event.workflow_run.event == 'pull_request' + steps: + - name: Report result + uses: actions/github-script@v7 + with: + debug: true + script: | + const owner = '${{ github.repository_owner }}'; + const repo = '${{ github.repository }}'.split('/')[1]; + const sha = '${{ github.event.workflow_run.head_sha }}'; + const result = '${{ needs.wokwi-test.result }}'; + core.debug(`owner: ${owner}`); + core.debug(`repo: ${repo}`); + core.debug(`sha: ${sha}`); + core.debug(`result: ${result}`); + const { context: name, state } = (await github.rest.repos.createCommitStatus({ + context: 'Wokwi tests', + description: 'Wokwi simulator tests', + owner: owner, + repo: repo, + sha: sha, + state: result, + target_url: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}' + })).data; + core.info(`${name} is ${state}`); + From 42adbee97cb4b11bfbf12b7a42e2c112daab46e6 Mon Sep 17 00:00:00 2001 From: Jan Prochazka <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Tue, 7 May 2024 13:45:23 +0200 Subject: [PATCH 2/3] fix(ci): Concurrency change to wokwi --- .github/workflows/wokwi.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/wokwi.yml b/.github/workflows/wokwi.yml index 04e780e8879..c1cb7621293 100644 --- a/.github/workflows/wokwi.yml +++ b/.github/workflows/wokwi.yml @@ -16,7 +16,7 @@ env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} concurrency: - group: hil-${{github.event.pull_request.number || github.ref}} + group: wokwi-${{github.event.pull_request.number || github.ref}} cancel-in-progress: true jobs: From 208e028b8b1239650b52f254bacee7cb3d32a869 Mon Sep 17 00:00:00 2001 From: Jan Prochazka <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Tue, 7 May 2024 14:34:43 +0200 Subject: [PATCH 3/3] ci(wokwi): Fix skipped tests --- .github/workflows/wokwi.yml | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/.github/workflows/wokwi.yml b/.github/workflows/wokwi.yml index c1cb7621293..c4f3ec2ff66 100644 --- a/.github/workflows/wokwi.yml +++ b/.github/workflows/wokwi.yml @@ -65,7 +65,7 @@ jobs: uses: actions/download-artifact@v4 with: name: ${{matrix.chip}}-${{matrix.chunks}}.artifacts - path: ~/.arduino/tests/ + path: ~/ run-id: ${{github.event.workflow_run.id}} github-token: ${{env.GITHUB_TOKEN}} @@ -82,12 +82,21 @@ jobs: run: | bash .github/scripts/tests_run.sh -c -t ${{matrix.chip}} -i ${{matrix.chunks}} -m ${{env.MAX_CHUNKS}} -w ${{env.WOKWI_TIMEOUT}} + - name: Check if tests were skipped + id: check-test-skipped + run: | + if [ -f ~/.test_skipped ]; then + echo "skipped=true" >> $GITHUB_OUTPUT + else + echo "skipped=false" >> $GITHUB_OUTPUT + fi + - name: Upload test result artifacts uses: actions/upload-artifact@v4 - if: always() + if: ${{ always() && steps.check-test-skipped.outputs.skipped == 'false' }} with: name: wokwi_results-${{matrix.chip}}-${{matrix.chunks}} - path: tests/*/*.xml + path: tests/**/*.xml report-result: name: Report wokwi test result