Drone: Report front-end test metrics (#27395)

* Drone: Report front-end test metrics

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>

* ci-frontend-metrics.sh: Fix collection bugs; print JSON

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>

* Add Yarn script ci:test-frontend
This commit is contained in:
Arve Knudsen 2020-09-07 13:17:03 +02:00 committed by GitHub
parent b70fefe642
commit 58af541321
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 50 additions and 42 deletions

View File

@ -48,7 +48,7 @@ commands:
- run: - run:
name: "Install Grafana build pipeline tool" name: "Install Grafana build pipeline tool"
command: | command: |
VERSION=0.5.5 VERSION=0.5.6
curl -fLO https://grafana-downloads.storage.googleapis.com/grafana-build-pipeline/v${VERSION}/grabpl curl -fLO https://grafana-downloads.storage.googleapis.com/grafana-build-pipeline/v${VERSION}/grabpl
chmod +x grabpl chmod +x grabpl
mv grabpl /tmp mv grabpl /tmp
@ -852,7 +852,11 @@ jobs:
- node_modules - node_modules
- run: - run:
name: frontend tests 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: - store_test_results:
path: reports/junit path: reports/junit
- run: - run:

View File

@ -26,7 +26,7 @@ steps:
- yarn install --frozen-lockfile --no-progress - yarn install --frozen-lockfile --no-progress
environment: environment:
DOCKERIZE_VERSION: 0.6.1 DOCKERIZE_VERSION: 0.6.1
GRABPL_VERSION: 0.5.5 GRABPL_VERSION: 0.5.6
- name: lint-backend - name: lint-backend
image: grafana/build-container:1.2.26 image: grafana/build-container:1.2.26
@ -74,10 +74,7 @@ steps:
- name: test-frontend - name: test-frontend
image: grafana/build-container:1.2.26 image: grafana/build-container:1.2.26
commands: commands:
- yarn run prettier:check - yarn run ci:test-frontend
- yarn run packages:typecheck
- yarn run typecheck
- yarn run test
environment: environment:
TEST_MAX_WORKERS: 50% TEST_MAX_WORKERS: 50%
depends_on: depends_on:
@ -252,7 +249,7 @@ steps:
- yarn install --frozen-lockfile --no-progress - yarn install --frozen-lockfile --no-progress
environment: environment:
DOCKERIZE_VERSION: 0.6.1 DOCKERIZE_VERSION: 0.6.1
GRABPL_VERSION: 0.5.5 GRABPL_VERSION: 0.5.6
- name: lint-backend - name: lint-backend
image: grafana/build-container:1.2.26 image: grafana/build-container:1.2.26
@ -300,12 +297,11 @@ steps:
- name: test-frontend - name: test-frontend
image: grafana/build-container:1.2.26 image: grafana/build-container:1.2.26
commands: commands:
- yarn run prettier:check - yarn run ci:test-frontend
- yarn run packages:typecheck - ./scripts/ci-frontend-metrics.sh | ./bin/grabpl publish-metrics $${GRAFANA_MISC_STATS_API_KEY}
- yarn run typecheck
- yarn run test
environment: environment:
TEST_MAX_WORKERS: 50% GRAFANA_MISC_STATS_API_KEY:
from_secret: grafana_misc_stats_api_key
depends_on: depends_on:
- initialize - initialize
@ -519,7 +515,7 @@ steps:
- gcloud auth activate-service-account --key-file=gcpkey.json - gcloud auth activate-service-account --key-file=gcpkey.json
- rm gcpkey.json - rm gcpkey.json
- $$ProgressPreference = "SilentlyContinue" - $$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 - 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 . - cp C:\App\nssm-2.24.zip .
- ./grabpl.exe windows-installer --edition oss grafana.zip - ./grabpl.exe windows-installer --edition oss grafana.zip

View File

@ -40,7 +40,8 @@
"themes:generate": "ts-node --project ./scripts/cli/tsconfig.json ./scripts/cli/generateSassVariableFiles.ts", "themes:generate": "ts-node --project ./scripts/cli/tsconfig.json ./scripts/cli/generateSassVariableFiles.ts",
"typecheck": "tsc --noEmit", "typecheck": "tsc --noEmit",
"plugins:build-bundled": "grafana-toolkit plugin:bundle-managed", "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": { "grafana": {
"whatsNewUrl": "https://grafana.com/docs/grafana/latest/guides/whats-new-in-v7-1/", "whatsNewUrl": "https://grafana.com/docs/grafana/latest/guides/whats-new-in-v7-1/",

View File

@ -1,18 +1,18 @@
#!/bin/bash #!/bin/bash
set -eo pipefail
echo -e "Collecting code stats (typescript errors & more)" echo -e "Collecting code stats (typescript errors & more)"
ERROR_COUNT_LIMIT=398 ERROR_COUNT_LIMIT=580
DIRECTIVES_LIMIT=172 DIRECTIVES_LIMIT=172
CONTROLLERS_LIMIT=139 CONTROLLERS_LIMIT=139
ERROR_COUNT="$(./node_modules/.bin/tsc --project tsconfig.json --noEmit --strictNullChecks true | grep -oP 'Found \K(\d+)')" 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)" DIRECTIVES="$(grep -r -o directive public/app/ | wc -l)"
CONTROLLERS="$(grep -r -oP 'class .*Ctrl' 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)" 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)" MDX_COUNT="$(find ./packages/grafana-ui/src/components -name "*.mdx" | wc -l)"
LEGACY_FORMS="$(grep -r -oP 'LegacyForms;' public/app/**/* | wc -l)" LEGACY_FORMS="$(grep -r -oP 'LegacyForms;' public/app | wc -l)"
if [ "$ERROR_COUNT" -gt $ERROR_COUNT_LIMIT ]; then if [ "$ERROR_COUNT" -gt $ERROR_COUNT_LIMIT ]; then
echo -e "Typescript strict errors $ERROR_COUNT exceeded $ERROR_COUNT_LIMIT so failing build" 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 "Documented stories: $MDX_COUNT"
echo -e "Legacy forms: $LEGACY_FORMS" echo -e "Legacy forms: $LEGACY_FORMS"
if [ "${CIRCLE_BRANCH}" == "master" ]; then echo "Metrics: {
./scripts/ci-metrics-publisher.sh \ \"grafana.ci-code.strictErrors\": \"${ERROR_COUNT}\",
grafana.ci-code.strictErrors="$ERROR_COUNT" \ \"grafana.ci-code.directives\": \"${DIRECTIVES}\",
grafana.ci-code.directives="$DIRECTIVES" \ \"grafana.ci-code.controllers\": \"${CONTROLLERS}\",
grafana.ci-code.controllers="$CONTROLLERS" \ \"grafana.ci-code.grafana-ui.stories\": \"${STORIES_COUNT}\",
grafana.ci-code.grafana-ui.stories="$STORIES_COUNT" \ \"grafana.ci-code.grafana-ui.mdx\": \"${MDX_COUNT}\",
grafana.ci-code.grafana-ui.mdx="$MDX_COUNT" \ \"grafana.ci-code.legacyForms\": \"${LEGACY_FORMS}\"
grafana.ci-code.legacyForms="$LEGACY_FORMS" }"
fi

View File

@ -3,7 +3,7 @@ publish_image = 'grafana/grafana-ci-deploy:1.2.5'
grafana_docker_image = 'grafana/drone-grafana-docker:0.2.0' grafana_docker_image = 'grafana/drone-grafana-docker:0.2.0'
alpine_image = 'alpine:3.12' alpine_image = 'alpine:3.12'
windows_image = 'mcr.microsoft.com/windows:1809' windows_image = 'mcr.microsoft.com/windows:1809'
grabpl_version = '0.5.5' grabpl_version = '0.5.6'
def pr_pipelines(edition): def pr_pipelines(edition):
services = [ services = [
@ -82,7 +82,7 @@ def master_pipelines(edition):
codespell_step(), codespell_step(),
shellcheck_step(), shellcheck_step(),
test_backend_step(), test_backend_step(),
test_frontend_step(), test_frontend_step(publish_metrics=True),
build_backend_step(edition=edition), build_backend_step(edition=edition),
build_frontend_step(edition=edition), build_frontend_step(edition=edition),
build_plugins_step(edition=edition), build_plugins_step(edition=edition),
@ -353,8 +353,13 @@ def test_backend_step():
], ],
} }
def test_frontend_step(): def test_frontend_step(publish_metrics=False):
return { 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', 'name': 'test-frontend',
'image': build_image, 'image': build_image,
'depends_on': [ 'depends_on': [
@ -363,13 +368,16 @@ def test_frontend_step():
'environment': { 'environment': {
'TEST_MAX_WORKERS': '50%', 'TEST_MAX_WORKERS': '50%',
}, },
'commands': [ 'commands': cmds,
'yarn run prettier:check',
'yarn run packages:typecheck',
'yarn run typecheck',
'yarn run test',
],
} }
if publish_metrics:
dct['environment'] = {
'GRAFANA_MISC_STATS_API_KEY': {
'from_secret': 'grafana_misc_stats_api_key',
},
}
return dct
def codespell_step(): def codespell_step():
return { return {