From 58af541321f8cd737260a11da7954acb95c99229 Mon Sep 17 00:00:00 2001 From: Arve Knudsen Date: Mon, 7 Sep 2020 13:17:03 +0200 Subject: [PATCH] Drone: Report front-end test metrics (#27395) * Drone: Report front-end test metrics Signed-off-by: Arve Knudsen * ci-frontend-metrics.sh: Fix collection bugs; print JSON Signed-off-by: Arve Knudsen * Add Yarn script ci:test-frontend --- .circleci/config.yml | 8 ++++++-- .drone.yml | 20 ++++++++------------ package.json | 3 ++- scripts/ci-frontend-metrics.sh | 33 ++++++++++++++++----------------- scripts/lib.star | 28 ++++++++++++++++++---------- 5 files changed, 50 insertions(+), 42 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 2fb9503dfdd..49529f67ce6 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -48,7 +48,7 @@ commands: - run: name: "Install Grafana build pipeline tool" command: | - VERSION=0.5.5 + VERSION=0.5.6 curl -fLO https://grafana-downloads.storage.googleapis.com/grafana-build-pipeline/v${VERSION}/grabpl chmod +x grabpl mv grabpl /tmp @@ -852,7 +852,11 @@ jobs: - node_modules - run: name: frontend tests - command: "./scripts/circle-test-frontend.sh" + command: | + yarn run ci:test-frontend + if [[ $CIRCLE_BRANCH == "master" ]]; then + ./scripts/ci-frontend-metrics.sh | ./bin/grabpl publish-metrics ${GRAFANA_MISC_STATS_API_KEY} + fi - store_test_results: path: reports/junit - run: diff --git a/.drone.yml b/.drone.yml index 2e090d5c087..923ea5a7509 100644 --- a/.drone.yml +++ b/.drone.yml @@ -26,7 +26,7 @@ steps: - yarn install --frozen-lockfile --no-progress environment: DOCKERIZE_VERSION: 0.6.1 - GRABPL_VERSION: 0.5.5 + GRABPL_VERSION: 0.5.6 - name: lint-backend image: grafana/build-container:1.2.26 @@ -74,10 +74,7 @@ steps: - name: test-frontend image: grafana/build-container:1.2.26 commands: - - yarn run prettier:check - - yarn run packages:typecheck - - yarn run typecheck - - yarn run test + - yarn run ci:test-frontend environment: TEST_MAX_WORKERS: 50% depends_on: @@ -252,7 +249,7 @@ steps: - yarn install --frozen-lockfile --no-progress environment: DOCKERIZE_VERSION: 0.6.1 - GRABPL_VERSION: 0.5.5 + GRABPL_VERSION: 0.5.6 - name: lint-backend image: grafana/build-container:1.2.26 @@ -300,12 +297,11 @@ steps: - name: test-frontend image: grafana/build-container:1.2.26 commands: - - yarn run prettier:check - - yarn run packages:typecheck - - yarn run typecheck - - yarn run test + - yarn run ci:test-frontend + - ./scripts/ci-frontend-metrics.sh | ./bin/grabpl publish-metrics $${GRAFANA_MISC_STATS_API_KEY} environment: - TEST_MAX_WORKERS: 50% + GRAFANA_MISC_STATS_API_KEY: + from_secret: grafana_misc_stats_api_key depends_on: - initialize @@ -519,7 +515,7 @@ steps: - gcloud auth activate-service-account --key-file=gcpkey.json - rm gcpkey.json - $$ProgressPreference = "SilentlyContinue" - - Invoke-WebRequest https://grafana-downloads.storage.googleapis.com/grafana-build-pipeline/v0.5.5/windows/grabpl.exe -OutFile grabpl.exe + - Invoke-WebRequest https://grafana-downloads.storage.googleapis.com/grafana-build-pipeline/v0.5.6/windows/grabpl.exe -OutFile grabpl.exe - Invoke-WebRequest https://grafana-downloads.storage.googleapis.com/oss/master/grafana-7.2.0-9fffe273pre.windows-amd64.zip -OutFile grafana.zip - cp C:\App\nssm-2.24.zip . - ./grabpl.exe windows-installer --edition oss grafana.zip diff --git a/package.json b/package.json index 4e760b4cd1d..0275c873fad 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,8 @@ "themes:generate": "ts-node --project ./scripts/cli/tsconfig.json ./scripts/cli/generateSassVariableFiles.ts", "typecheck": "tsc --noEmit", "plugins:build-bundled": "grafana-toolkit plugin:bundle-managed", - "watch": "yarn start -d watch,start core:start --watchTheme " + "watch": "yarn start -d watch,start core:start --watchTheme", + "ci:test-frontend": "yarn run prettier:check && yarn run packages:typecheck && yarn run typecheck && yarn run test" }, "grafana": { "whatsNewUrl": "https://grafana.com/docs/grafana/latest/guides/whats-new-in-v7-1/", diff --git a/scripts/ci-frontend-metrics.sh b/scripts/ci-frontend-metrics.sh index f7bfd5e376e..f347f123b69 100755 --- a/scripts/ci-frontend-metrics.sh +++ b/scripts/ci-frontend-metrics.sh @@ -1,18 +1,18 @@ #!/bin/bash +set -eo pipefail echo -e "Collecting code stats (typescript errors & more)" -ERROR_COUNT_LIMIT=398 +ERROR_COUNT_LIMIT=580 DIRECTIVES_LIMIT=172 CONTROLLERS_LIMIT=139 -ERROR_COUNT="$(./node_modules/.bin/tsc --project tsconfig.json --noEmit --strictNullChecks true | grep -oP 'Found \K(\d+)')" -DIRECTIVES="$(grep -r -o directive public/app/**/* | wc -l)" -CONTROLLERS="$(grep -r -oP 'class .*Ctrl' public/app/**/* | wc -l)" -STORIES_COUNT="$(find ./packages/grafana-ui/src/components -name "*.story.tsx" | wc -l)" -MDX_COUNT="$(find ./packages/grafana-ui/src/components -name "*.mdx" | wc -l)" -LEGACY_FORMS="$(grep -r -oP 'LegacyForms;' public/app/**/* | wc -l)" - +ERROR_COUNT="$(./node_modules/.bin/tsc --project tsconfig.json --noEmit --strict true | grep -oP 'Found \K(\d+)')" +DIRECTIVES="$(grep -r -o directive public/app/ | wc -l)" +CONTROLLERS="$(grep -r -oP 'class .*Ctrl' public/app/ | wc -l)" +STORIES_COUNT="$(find ./packages/grafana-ui/src/components -name "*.story.tsx" | wc -l)" +MDX_COUNT="$(find ./packages/grafana-ui/src/components -name "*.mdx" | wc -l)" +LEGACY_FORMS="$(grep -r -oP 'LegacyForms;' public/app | wc -l)" if [ "$ERROR_COUNT" -gt $ERROR_COUNT_LIMIT ]; then echo -e "Typescript strict errors $ERROR_COUNT exceeded $ERROR_COUNT_LIMIT so failing build" @@ -36,12 +36,11 @@ echo -e "Stories: $STORIES_COUNT" echo -e "Documented stories: $MDX_COUNT" echo -e "Legacy forms: $LEGACY_FORMS" -if [ "${CIRCLE_BRANCH}" == "master" ]; then - ./scripts/ci-metrics-publisher.sh \ - grafana.ci-code.strictErrors="$ERROR_COUNT" \ - grafana.ci-code.directives="$DIRECTIVES" \ - grafana.ci-code.controllers="$CONTROLLERS" \ - grafana.ci-code.grafana-ui.stories="$STORIES_COUNT" \ - grafana.ci-code.grafana-ui.mdx="$MDX_COUNT" \ - grafana.ci-code.legacyForms="$LEGACY_FORMS" -fi +echo "Metrics: { + \"grafana.ci-code.strictErrors\": \"${ERROR_COUNT}\", + \"grafana.ci-code.directives\": \"${DIRECTIVES}\", + \"grafana.ci-code.controllers\": \"${CONTROLLERS}\", + \"grafana.ci-code.grafana-ui.stories\": \"${STORIES_COUNT}\", + \"grafana.ci-code.grafana-ui.mdx\": \"${MDX_COUNT}\", + \"grafana.ci-code.legacyForms\": \"${LEGACY_FORMS}\" +}" diff --git a/scripts/lib.star b/scripts/lib.star index 45634f3bf88..233526f7ba3 100644 --- a/scripts/lib.star +++ b/scripts/lib.star @@ -3,7 +3,7 @@ publish_image = 'grafana/grafana-ci-deploy:1.2.5' grafana_docker_image = 'grafana/drone-grafana-docker:0.2.0' alpine_image = 'alpine:3.12' windows_image = 'mcr.microsoft.com/windows:1809' -grabpl_version = '0.5.5' +grabpl_version = '0.5.6' def pr_pipelines(edition): services = [ @@ -82,7 +82,7 @@ def master_pipelines(edition): codespell_step(), shellcheck_step(), test_backend_step(), - test_frontend_step(), + test_frontend_step(publish_metrics=True), build_backend_step(edition=edition), build_frontend_step(edition=edition), build_plugins_step(edition=edition), @@ -353,8 +353,13 @@ def test_backend_step(): ], } -def test_frontend_step(): - return { +def test_frontend_step(publish_metrics=False): + cmds = [ + 'yarn run ci:test-frontend', + ] + if publish_metrics: + cmds.append('./scripts/ci-frontend-metrics.sh | ./bin/grabpl publish-metrics $${GRAFANA_MISC_STATS_API_KEY}') + dct = { 'name': 'test-frontend', 'image': build_image, 'depends_on': [ @@ -363,13 +368,16 @@ def test_frontend_step(): 'environment': { 'TEST_MAX_WORKERS': '50%', }, - 'commands': [ - 'yarn run prettier:check', - 'yarn run packages:typecheck', - 'yarn run typecheck', - 'yarn run test', - ], + 'commands': cmds, } + if publish_metrics: + dct['environment'] = { + 'GRAFANA_MISC_STATS_API_KEY': { + 'from_secret': 'grafana_misc_stats_api_key', + }, + } + + return dct def codespell_step(): return {