From d53e244c3dabc170fb65622275bdf23bae97e9ea Mon Sep 17 00:00:00 2001 From: GuyAfik Date: Sun, 17 Dec 2023 21:52:20 +0200 Subject: [PATCH] use composite actions in main.yml --- .github/workflows/main.yml | 199 +++++++++++++++++++++++++++++++++---- 1 file changed, 179 insertions(+), 20 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3d48132157b..167d14d67a7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -14,25 +14,184 @@ concurrency: jobs: - Unit-Tests: - uses: ./.github/workflows/tests.yml - with: - test-type: "Unit" - ignored-file-paths: "demisto_sdk/commands/init/templates,demisto_sdk/tests/integration_tests,demisto_sdk/commands/content_graph,tests_end_to_end" - groups: '["1", "2", "3", "4", "5"]' - splits: "5" - - Integration-Tests: - uses: ./.github/workflows/tests.yml - with: - test-type: "Integration" - file-path: "demisto_sdk/tests/integration_tests" - - Graph-Tests: - uses: ./.github/workflows/tests.yml - with: - test-type: "Graph" - file-path: "demisto_sdk/commands/content_graph" + unit-tests: + name: Unit Tests / ${{ matrix.python-version }} (${{ matrix.group }}) + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [ "3.8", "3.9", "3.10" ] + group: [ 1, 2, 3, 4, 5 ] + fail-fast: false + defaults: + run: + shell: bash + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - uses: ./.github/actions/setup_environment + with: + python-version: ${{ matrix.python-version }} + + - name: Run pytest + run: | + source "$(poetry env info --path)/bin/activate" + + # Due to race conditions in the tests bringing up and down the node server, have the server available + # For all the tests. + node demisto_sdk/commands/common/markdown_server/mdx-parse-server.js & + node_pid=$! + + mkdir test-results + # poetry run pytest --ignore={demisto_sdk/commands/init/templates,demisto_sdk/tests/integration_tests} --store-durations --junitxml=test-results/junit.xml || pytest_exit_code=$ + # mv .test_durations test-results/test_durations + poetry run pytest -v --ignore={demisto_sdk/commands/init/templates,demisto_sdk/tests/integration_tests,demisto_sdk/commands/content_graph} --cov=demisto_sdk --cov-report=html --junitxml=test-results/junit.xml --splits 5 --group ${{ matrix.group }} || pytest_exit_code=$? + echo "PYTEST_EXIT_CODE=$pytest_exit_code" >> $GITHUB_ENV + + kill $node_pid + - name: Upload artifacts + if: always() + uses: actions/upload-artifact@v3 + with: + name: unit-tests-artifacts-${{ matrix.python-version }}-group-${{ matrix.group }} + path: | + test-results/test_durations + test-results/junit.xml + node_versions_info.json + coverage_html_report + .coverage + - name: Print Summary of pytest results in workflow summary + if: always() + uses: pmeier/pytest-results-action@main + with: + path: test-results/junit.xml + summary: true + display-options: fsEX + fail-on-empty: true + - name: Check if tests have passed + if: always() + run: | + if [[ "$PYTEST_EXIT_CODE" -ne 0 ]]; then + echo "There are unit-tests that failed, pytest finished with exit code $PYTEST_EXIT_CODE, to see the tests summary refer to https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}?pr=${{ github.event.pull_request.number }}" + else + echo "All unit-tests have passed, congratulations!" + fi + exit $PYTEST_EXIT_CODE + + integration-tests: + name: Integration Tests / ${{ matrix.python-version }} + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [ "3.8", "3.9", "3.10" ] + fail-fast: false + defaults: + run: + shell: bash + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - uses: ./.github/actions/setup_environment + with: + python-version: ${{ matrix.python-version }} + + - name: Run pytest + run: | + source "$(poetry env info --path)/bin/activate" + + echo $(echo '{"node_version": "'$(node --version)'","npm_list":'$(npm list --json)'}') > node_versions_info.json + + mkdir integration-test-results + poetry run pytest -v demisto_sdk/tests/integration_tests --cov=demisto_sdk --cov-report=html --junitxml=integration-test-results/junit.xml || pytest_exit_code=$? + echo "PYTEST_EXIT_CODE=$pytest_exit_code" >> $GITHUB_ENV + + exit $pytest_exit_code + - name: Upload artifacts + if: always() + uses: actions/upload-artifact@v3 + with: + name: integration-tests-artifacts-${{ matrix.python-version }} + path: | + .test_durations + integration-test-results/junit.xml + node_versions_info.json + coverage_html_report + .coverage + - name: Print Summary of pytest results in workflow summary + if: always() + uses: pmeier/pytest-results-action@main + with: + path: integration-test-results/junit.xml + summary: true + display-options: fsEX + fail-on-empty: true + - name: Check if tests have passed + if: always() + run: | + if [[ "$PYTEST_EXIT_CODE" -ne 0 ]]; then + echo "There are integration-tests that failed, pytest finished with exit code $PYTEST_EXIT_CODE, to see the tests summary refer to https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}?pr=${{ github.event.pull_request.number }}" + else + echo "All integration-tests have passed, congratulations!" + fi + exit $PYTEST_EXIT_CODE + graph-tests: + name: Graph Tests / ${{ matrix.python-version }} (${{ matrix.group }}) + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [ "3.8", "3.9", "3.10" ] + fail-fast: false + defaults: + run: + shell: bash + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - uses: ./.github/actions/setup_environment + with: + python-version: ${{ matrix.python-version }} + + - name: Run pytest + run: | + source "$(poetry env info --path)/bin/activate" + + mkdir graph-test-results + poetry run pytest -v demisto_sdk/commands/content_graph --cov=demisto_sdk --cov-report=html --junitxml=graph-test-results/junit.xml || pytest_exit_code=$? + echo "PYTEST_EXIT_CODE=$pytest_exit_code" >> $GITHUB_ENV + + - name: Upload artifacts + if: always() + uses: actions/upload-artifact@v3 + with: + name: graph-tests-artifacts-${{ matrix.python-version }} + path: | + test-results/test_durations + graph-test-results/junit.xml + node_versions_info.json + coverage_html_report + .coverage + - name: Print Summary of pytest results in workflow summary + if: always() + uses: pmeier/pytest-results-action@main + with: + path: graph-test-results/junit.xml + summary: true + display-options: fsEX + fail-on-empty: true + - name: Check if tests have passed + if: always() + run: | + if [[ "$PYTEST_EXIT_CODE" -ne 0 ]]; then + echo "There are graph-tests that failed, pytest finished with exit code $PYTEST_EXIT_CODE, to see the tests summary refer to https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}?pr=${{ github.event.pull_request.number }}" + else + echo "All graph-tests have passed, congratulations!" + fi + exit $PYTEST_EXIT_CODE coverage: needs: [unit-tests, integration-tests, graph-tests] @@ -52,4 +211,4 @@ jobs: coverage report coverage xml - name: Coveralls - uses: coverallsapp/github-action@v2 + uses: coverallsapp/github-action@v2 \ No newline at end of file