diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index dd919b228c..3709719823 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,4 +22,4 @@ jobs: - name: Run tests run: | cd $GITHUB_WORKSPACE - ./.github/workflows/scripts/run-build.sh + ./.github/workflows/scripts/run_build.sh diff --git a/.github/workflows/scripts/run-tests.sh b/.github/workflows/scripts/run-tests.sh deleted file mode 100755 index 85eace7010..0000000000 --- a/.github/workflows/scripts/run-tests.sh +++ /dev/null @@ -1,73 +0,0 @@ -#!/bin/bash - -backend_test_failed=0 -browser_test_failed=0 - -setupClient() { - cd $GITHUB_WORKSPACE/client # to install frontend dependencies - npm install -d - ./node_modules/grunt/bin/grunt build_and_instrument -} - -setupBackend() { - cd $GITHUB_WORKSPACE/backend # to install backend dependencies - pip3 install -r requirements/requirements-$(lsb_release -cs).txt -} - -echo "Running setup" -sudo apt-get update -sudo apt-get install -y tor -npm install -g grunt grunt-cli -pip install coverage -setupClient -setupBackend - -# Running Backend Unit Tests -echo "Running backend unit tests" -cd $GITHUB_WORKSPACE/backend && coverage run setup.py test -if [ $? -ne 0 ]; then - echo "Backend unit tests failed!" - backend_test_failed=1 -else - echo "Backend unit tests succeeded!" -fi - -$GITHUB_WORKSPACE/backend/bin/globaleaks -z -sleep 5 - -# Running BrowserTesting Locally -echo "Running BrowserTesting locally collecting code coverage" -cd $GITHUB_WORKSPACE/client && npm test -if [ $? -ne 0 ]; then - echo "Browser tests failed!" - browser_test_failed=1 -else - echo "Browser tests succeeded!" -fi - -cd $GITHUB_WORKSPACE/backend && coverage xml -bash <(curl -Ls https://coverage.codacy.com/get.sh) report -l Python -r $GITHUB_WORKSPACE/backend/coverage.xml -bash <(curl -Ls https://coverage.codacy.com/get.sh) report -l TypeScript -r $GITHUB_WORKSPACE/client/cypress/coverage/lcov.info - -# At the end, check if any of the critical tests failed -echo "Test Results Summary:" -if [ $backend_test_failed -eq 1 ]; then - echo " - Backend unit tests: FAILED" -else - echo " - Backend unit tests: PASSED" -fi - -if [ $browser_test_failed -eq 1 ]; then - echo " - Browser tests: FAILED" -else - echo " - Browser tests: PASSED" -fi - -# Final exit based on the test results -if [ $backend_test_failed -eq 1 ] || [ $browser_test_failed -eq 1 ]; then - echo "One or both critical tests failed." - exit 1 # Exit with failure if either critical test failed -else - echo "Script completed successfully." - exit 0 # Exit successfully if no critical test failed -fi diff --git a/.github/workflows/scripts/run-build.sh b/.github/workflows/scripts/run_build.sh similarity index 100% rename from .github/workflows/scripts/run-build.sh rename to .github/workflows/scripts/run_build.sh diff --git a/.github/workflows/scripts/run_tests_backend.sh b/.github/workflows/scripts/run_tests_backend.sh new file mode 100755 index 0000000000..ee3289ae04 --- /dev/null +++ b/.github/workflows/scripts/run_tests_backend.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +backend_test_failed=0 + +setupBackend() { + cd $GITHUB_WORKSPACE/backend # to install backend dependencies + pip3 install -r requirements/requirements-$(lsb_release -cs).txt +} + +setupClient() { + cd $GITHUB_WORKSPACE/client # to install frontend dependencies + npm install -d + ./node_modules/grunt/bin/grunt build_and_instrument +} + +echo "Running setup" +sudo apt-get update +sudo apt-get install -y tor +npm install -g grunt grunt-cli +setupBackend +setupClient + +# Running backend tests +echo "Running backend tests" +cd $GITHUB_WORKSPACE/backend && coverage run setup.py test +if [ $? -ne 0 ]; then + backend_test_failed=1 +fi + +cd $GITHUB_WORKSPACE/backend && coverage xml +bash <(curl -Ls https://coverage.codacy.com/get.sh) report -l Python -r $GITHUB_WORKSPACE/backend/coverage.xml + +if [ $backend_test_failed -eq 1 ]; then + echo "Backend unit tests: FAILED" + exit 1 +else + echo "Backend unit tests: PASSED" + exit 0 +fi diff --git a/.github/workflows/scripts/run_tests_client.sh b/.github/workflows/scripts/run_tests_client.sh new file mode 100755 index 0000000000..c6be9e8ccf --- /dev/null +++ b/.github/workflows/scripts/run_tests_client.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +client_test_failed=0 + +setupBackend() { + cd $GITHUB_WORKSPACE/backend # to install backend dependencies + pip3 install -r requirements/requirements-$(lsb_release -cs).txt +} + +setupClient() { + cd $GITHUB_WORKSPACE/client # to install frontend dependencies + npm install -d + ./node_modules/grunt/bin/grunt build_and_instrument +} + +echo "Running setup" +sudo apt-get update +sudo apt-get install -y tor +npm install -g grunt grunt-cli +setupBackend +setupClient + +$GITHUB_WORKSPACE/backend/bin/globaleaks -z +sleep 5 + +# Running client tests locally +echo "Running client tests locally collecting code coverage" +cd $GITHUB_WORKSPACE/client && npm test +if [ $? -ne 0 ]; then + client_test_failed=1 +fi + +bash <(curl -Ls https://coverage.codacy.com/get.sh) report -l TypeScript -r $GITHUB_WORKSPACE/client/cypress/coverage/lcov.info + +if [ $client_test_failed -eq 1 ]; then + echo "Client tests: FAILED" + exit 1 +else + echo "Client tests: PASSED" + exit 0 +fi diff --git a/.github/workflows/test-backend.yml b/.github/workflows/test-backend.yml new file mode 100644 index 0000000000..e447b9c90e --- /dev/null +++ b/.github/workflows/test-backend.yml @@ -0,0 +1,28 @@ +name: Tests (B) + +on: [ push, pull_request ] + +# Declare default permissions as read only. +permissions: read-all + +env: + CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }} + +jobs: + run_tests: + runs-on: "ubuntu-latest" + steps: + - name: Check out repository code + uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + with: + fetch-depth: 1 + + - name: Install git + run: | + sudo apt-get update -q + sudo apt-get install -y git + + - name: Run tests + run: | + cd $GITHUB_WORKSPACE + ./.github/workflows/scripts/run_tests_backend.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test-client.yml similarity index 88% rename from .github/workflows/test.yml rename to .github/workflows/test-client.yml index 499cfb257b..7b9810b686 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test-client.yml @@ -1,4 +1,4 @@ -name: Test +name: Tests (C) on: [ push, pull_request ] @@ -25,4 +25,4 @@ jobs: - name: Run tests run: | cd $GITHUB_WORKSPACE - ./.github/workflows/scripts/run-tests.sh + ./.github/workflows/scripts/run_tests_client.sh