diff --git a/.eslintrc.js b/.eslintrc.js index b64856394..3e655c534 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -3,6 +3,7 @@ module.exports = { process: true, module: true, require: true, + DISABLE_DEFAULT_LSF_INIT: true, __dirname: true, }, extends: ['plugin:@heartexlabs/frontend/recommended'], diff --git a/.github/workflows/cicd_pipeline.yml b/.github/workflows/cicd_pipeline.yml index 1699f9e51..eb2003a81 100644 --- a/.github/workflows/cicd_pipeline.yml +++ b/.github/workflows/cicd_pipeline.yml @@ -46,6 +46,16 @@ jobs: with: sha: ${{ github.event.pull_request.head.sha || github.event.after }} + run_functional: + name: "Tests" + if: github.event_name == 'push' || github.event.pull_request.draft == false + uses: heartexlabs/label-studio-frontend/.github/workflows/fun_tests.yml@master + needs: + - build_for_coverage + with: + sha: ${{ github.event.pull_request.head.sha || github.event.after }} + secrets: inherit + run_unit: name: "Tests" if: github.event_name == 'push' || github.event.pull_request.draft == false diff --git a/.github/workflows/e2e_tests.yml b/.github/workflows/e2e_tests.yml index 41fccf75e..260e22549 100644 --- a/.github/workflows/e2e_tests.yml +++ b/.github/workflows/e2e_tests.yml @@ -115,15 +115,3 @@ jobs: name: e2e-tests-coverage path: coverage/ - # - name: Upload coverage to Codecov - # uses: codecov/codecov-action@v3.1.1 - # if: ${{ !github.event.pull_request.head.repo.fork }} - # with: - # fail_ci_if_error: true - # token: ${{ secrets.CODECOV_TOKEN }} - - #- name: Upload coverage to artifact - #uses: actions/upload-artifact@v3 - #with: - #name: e2e-tests-coverage - #path: coverage/ diff --git a/.github/workflows/fun_tests.yml b/.github/workflows/fun_tests.yml new file mode 100644 index 000000000..db7c64450 --- /dev/null +++ b/.github/workflows/fun_tests.yml @@ -0,0 +1,133 @@ +name: "Run Cypress" + +on: + workflow_call: + inputs: + sha: + required: true + type: string + +env: + # increment it in case if you need to reset cache + CACHE_NAME_PREFIX: v3 + NODE: '14' + +jobs: + run: + name: "Cypress Tests" + runs-on: ubuntu-latest + + # ci can be skipped with `[skip ci]` prefix in message + if: "!contains(github.event.head_commit.message, 'skip ci')" + steps: + - uses: hmarr/debug-action@v2.1.0 + + - name: "Checkout codebase" + uses: actions/checkout@v3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + ref: ${{ inputs.sha }} + + - uses: actions/setup-node@v3 + with: + node-version: "${{ env.NODE }}" + + - name: Get CPU info + id: "cpu-info" + run: echo "cores-count=$(cat /proc/cpuinfo | grep processor | wc -l)" >> $GITHUB_OUTPUT + + - name: Setup SSH agent + env: + SSH_AUTH_SOCK: /tmp/ssh_agent.sock + SSH_DIR: /home/runner/.ssh + run: | + mkdir $SSH_DIR + ssh-keyscan github.com >> $SSH_DIR/known_hosts + echo "${{ secrets.SSH_PRIVATE_KEY }}" > $SSH_DIR/package_rsa + chmod 600 $SSH_DIR/package_rsa + ssh-agent -a $SSH_AUTH_SOCK > /dev/null + ssh-add $SSH_DIR/package_rsa + + - name: Upgrade Yarn + run: npm install -g yarn@1.22 + + - name: Get yarn cache directory path + id: yarn-cache-dir-path + run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT + + - name: Configure yarn cache + uses: actions/cache@v3 + with: + path: ${{ steps.yarn-cache-dir-path.outputs.dir }} + key: ${{ env.CACHE_NAME_PREFIX }}-${{ runner.os }}-node-${{ env.NODE }}-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + yarn-${{ env.CACHE_NAME_PREFIX }}-${{ runner.os }}-node-${{ env.NODE }}- + + - name: Print Yarn cache size + run: du -d 0 -h ${{ steps.yarn-cache-dir-path.outputs.dir }} + + - name: "Download bundle" + uses: actions/download-artifact@v3 + with: + name: LSF-coverage-${{ inputs.sha }} + path: build/ + + # run http-server with build in background (will be killed after job ends) + # do this only for master branch (so only for push event) + # because pr can contain unfinished job + - name: "Run server" + run: | + cp -r public/files build/ && + cp -r public/images build/ && + cp -r public/styles build/ && + npx serve -l tcp://localhost:3000 build & + + - id: wait_for_npx_server + name: "Wait for server" + timeout-minutes: 1 + run: | + while [ "$(curl -s -o /dev/null -L -w ''%{http_code}'' "http://localhost:3000/")" != "200" ]; do + echo "=> Waiting for service to become available" && sleep 2s + done + + - name: "Setup Cypress" + timeout-minutes: 1 + env: + SSH_AUTH_SOCK: /tmp/ssh_agent.sock + run: | + set -euo pipefail + cd ./tests/functional + yarn install --frozen-lockfile + + - name: Run Cypress test suite + timeout-minutes: 40 + env: + NODE_ENV: 'production' + COLLECT_COVERAGE: 'true' + CPU_NUMBER: ${{ steps.cpu-info.outputs.cores-count }} + run: | + set -euo pipefail + cd ./tests/functional + yarn run test:parallel + + - name: "Upload suite output" + uses: actions/upload-artifact@v3 + if: ${{ failure() }} + with: + name: failure-result + path: ./tests/functional + + - name: Prepare coverage report + if: ${{ success() }} + run: | + cd ./tests/functional + rm -rf coverage + yarn cvg:report + + - name: Upload coverage to Artifact + uses: actions/upload-artifact@v3 + if: ${{ success() }} + with: + name: cypress-tests-coverage + path: ./tests/functional/coverage/ + diff --git a/.github/workflows/tests_coverage.yml b/.github/workflows/tests_coverage.yml index 924e36a6a..1b14bfc94 100644 --- a/.github/workflows/tests_coverage.yml +++ b/.github/workflows/tests_coverage.yml @@ -55,3 +55,25 @@ jobs: fail_ci_if_error: true token: ${{ secrets.codecov_token }} + run_cypress_coverage_upload: + name: Upload Cypress coverage + runs-on: ubuntu-latest + + if: "!contains(github.event.head_commit.message, 'skip ci')" + + steps: + - name: "Checkout codebase" + uses: actions/checkout@v3 + + - name: "Download Cypress coverage from Artifact" + uses: actions/download-artifact@v3 + with: + name: cypress-tests-coverage + path: coverage/ + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3.1.1 + if: ${{ !github.event.pull_request.head.repo.fork }} + with: + fail_ci_if_error: true + token: ${{ secrets.codecov_token }} diff --git a/public/index.html b/public/index.html index 12db0c7d6..e49228834 100644 --- a/public/index.html +++ b/public/index.html @@ -76,18 +76,24 @@ }