From c18432971b4e5c4fba12c8aef0f8db8f71f14c46 Mon Sep 17 00:00:00 2001 From: Dimitris Sotirakis Date: Wed, 21 Sep 2022 14:05:19 +0300 Subject: [PATCH] CI: Introduce `lint-backend` pipeline (#55476) * Introduce lint-backend pipeline * Use go image and install make * Don't run lint pipeline on .drone.yml changes --- .drone.yml | 162 +++++++++++++++++----- scripts/drone/events/main.star | 6 + scripts/drone/events/pr.star | 6 + scripts/drone/pipelines/lint_backend.star | 31 +++++ scripts/drone/pipelines/test_backend.star | 7 - scripts/drone/steps/lib.star | 3 +- 6 files changed, 172 insertions(+), 43 deletions(-) create mode 100644 scripts/drone/pipelines/lint_backend.star diff --git a/.drone.yml b/.drone.yml index 55c113fd29b..e2f5c4a48a1 100644 --- a/.drone.yml +++ b/.drone.yml @@ -152,12 +152,6 @@ steps: - echo $DRONE_RUNNER_NAME image: alpine:3.15.6 name: identify-runner -- commands: - - mkdir -p bin - - curl -fL -o bin/grabpl https://grafana-downloads.storage.googleapis.com/grafana-build-pipeline/v3.0.7/grabpl - - chmod +x bin/grabpl - image: byrnedo/alpine-curl:0.1.8 - name: grabpl - commands: - go build -o ./bin/build -ldflags '-extldflags -static' ./pkg/build/cmd depends_on: [] @@ -180,14 +174,6 @@ steps: - verify-gen-cue image: grafana/build-container:1.6.2 name: wire-install -- commands: - - make lint-go - depends_on: - - wire-install - environment: - CGO_ENABLED: "1" - image: grafana/build-container:1.6.2 - name: lint-backend - commands: - go test -short -covermode=atomic -timeout=30m ./pkg/... depends_on: @@ -228,6 +214,66 @@ depends_on: [] image_pull_secrets: - dockerconfigjson kind: pipeline +name: pr-lint-backend +node: + type: no-parallel +platform: + arch: amd64 + os: linux +services: [] +steps: +- commands: + - echo $DRONE_RUNNER_NAME + image: alpine:3.15.6 + name: identify-runner +- commands: + - go build -o ./bin/build -ldflags '-extldflags -static' ./pkg/build/cmd + depends_on: [] + environment: + CGO_ENABLED: 0 + image: golang:1.19.1 + name: compile-build-cmd +- commands: + - make gen-go + depends_on: [] + image: grafana/build-container:1.6.2 + name: wire-install +- commands: + - apt-get update && apt-get install make + - make lint-go + depends_on: + - wire-install + environment: + CGO_ENABLED: "1" + image: golang:1.19.1 + name: lint-backend +trigger: + event: + - pull_request + paths: + exclude: + - docs/** + - '*.md' + include: + - pkg/** + - packaging/** + - conf/** + - go.sum + - go.mod + - public/app/plugins/**/plugin.json + - devenv/** +type: docker +volumes: +- host: + path: /var/run/docker.sock + name: docker +--- +clone: + retries: 3 +depends_on: [] +image_pull_secrets: +- dockerconfigjson +kind: pipeline name: pr-build-e2e node: type: no-parallel @@ -908,12 +954,6 @@ steps: - echo $DRONE_RUNNER_NAME image: alpine:3.15.6 name: identify-runner -- commands: - - mkdir -p bin - - curl -fL -o bin/grabpl https://grafana-downloads.storage.googleapis.com/grafana-build-pipeline/v3.0.7/grabpl - - chmod +x bin/grabpl - image: byrnedo/alpine-curl:0.1.8 - name: grabpl - commands: - go build -o ./bin/build -ldflags '-extldflags -static' ./pkg/build/cmd depends_on: [] @@ -936,14 +976,6 @@ steps: - verify-gen-cue image: grafana/build-container:1.6.2 name: wire-install -- commands: - - make lint-go - depends_on: - - wire-install - environment: - CGO_ENABLED: "1" - image: grafana/build-container:1.6.2 - name: lint-backend - commands: - go test -short -covermode=atomic -timeout=30m ./pkg/... depends_on: @@ -956,6 +988,60 @@ steps: - wire-install image: grafana/build-container:1.6.2 name: test-backend-integration +trigger: + branch: main + event: + - push + paths: + exclude: + - '*.md' + - docs/** + - latest.json +type: docker +volumes: +- host: + path: /var/run/docker.sock + name: docker +--- +clone: + retries: 3 +depends_on: [] +image_pull_secrets: +- dockerconfigjson +kind: pipeline +name: main-lint-backend +node: + type: no-parallel +platform: + arch: amd64 + os: linux +services: [] +steps: +- commands: + - echo $DRONE_RUNNER_NAME + image: alpine:3.15.6 + name: identify-runner +- commands: + - go build -o ./bin/build -ldflags '-extldflags -static' ./pkg/build/cmd + depends_on: [] + environment: + CGO_ENABLED: 0 + image: golang:1.19.1 + name: compile-build-cmd +- commands: + - make gen-go + depends_on: [] + image: grafana/build-container:1.6.2 + name: wire-install +- commands: + - apt-get update && apt-get install make + - make lint-go + depends_on: + - wire-install + environment: + CGO_ENABLED: "1" + image: golang:1.19.1 + name: lint-backend - commands: - ./bin/build verify-drone depends_on: @@ -2115,12 +2201,13 @@ steps: image: golang:1.19.1 name: compile-build-cmd - commands: + - apt-get update && apt-get install make - make lint-go depends_on: - wire-install environment: CGO_ENABLED: "1" - image: grafana/build-container:1.6.2 + image: golang:1.19.1 name: lint-backend - commands: - yarn run prettier:check @@ -2772,12 +2859,13 @@ steps: image: grafana/build-container:1.6.2 name: verify-gen-cue - commands: + - apt-get update && apt-get install make - make lint-go depends_on: - wire-install environment: CGO_ENABLED: "1" - image: grafana/build-container:1.6.2 + image: golang:1.19.1 name: lint-backend - commands: - yarn run prettier:check @@ -2811,12 +2899,13 @@ steps: image: grafana/build-container:1.6.2 name: test-frontend - commands: + - apt-get update && apt-get install make - make lint-go depends_on: - wire-install environment: CGO_ENABLED: "1" - image: grafana/build-container:1.6.2 + image: golang:1.19.1 name: lint-backend-enterprise2 - commands: - go test -tags=pro -covermode=atomic -timeout=30m ./pkg/... @@ -4080,12 +4169,13 @@ steps: image: golang:1.19.1 name: compile-build-cmd - commands: + - apt-get update && apt-get install make - make lint-go depends_on: - wire-install environment: CGO_ENABLED: "1" - image: grafana/build-container:1.6.2 + image: golang:1.19.1 name: lint-backend - commands: - yarn run prettier:check @@ -4701,12 +4791,13 @@ steps: image: grafana/build-container:1.6.2 name: verify-gen-cue - commands: + - apt-get update && apt-get install make - make lint-go depends_on: - wire-install environment: CGO_ENABLED: "1" - image: grafana/build-container:1.6.2 + image: golang:1.19.1 name: lint-backend - commands: - yarn run prettier:check @@ -4740,12 +4831,13 @@ steps: image: grafana/build-container:1.6.2 name: test-frontend - commands: + - apt-get update && apt-get install make - make lint-go depends_on: - wire-install environment: CGO_ENABLED: "1" - image: grafana/build-container:1.6.2 + image: golang:1.19.1 name: lint-backend-enterprise2 - commands: - go test -tags=pro -covermode=atomic -timeout=30m ./pkg/... @@ -5178,6 +5270,6 @@ kind: secret name: packages_secret_access_key --- kind: signature -hmac: b08cb03f133c943a789bf6abf7f2645536598e4d8a5a86b34b9231db8afc8ff4 +hmac: a17adc518f8ba4ea5c123bf440adf9aceec5e7ba5d9fdae9e467dbd1ec91fd46 ... diff --git a/scripts/drone/events/main.star b/scripts/drone/events/main.star index 8a26aa0898e..3c8387a943f 100644 --- a/scripts/drone/events/main.star +++ b/scripts/drone/events/main.star @@ -47,6 +47,11 @@ load( 'enterprise_downstream_pipeline', ) +load( + 'scripts/drone/pipelines/lint_backend.star', + 'lint_backend_pipeline', +) + load('scripts/drone/vault.star', 'from_secret') @@ -84,6 +89,7 @@ def main_pipelines(edition): docs_pipelines(edition, ver_mode, trigger_docs_main()), test_frontend(trigger, ver_mode), test_backend(trigger, ver_mode), + lint_backend_pipeline(trigger, ver_mode), build_e2e(trigger, ver_mode, edition), integration_tests(trigger, ver_mode, edition), windows(trigger, edition, ver_mode), diff --git a/scripts/drone/events/pr.star b/scripts/drone/events/pr.star index 5769f71e6f1..6e8e0802cfd 100644 --- a/scripts/drone/events/pr.star +++ b/scripts/drone/events/pr.star @@ -39,6 +39,11 @@ load( 'shellcheck_pipeline', ) +load( + 'scripts/drone/pipelines/lint_backend.star', + 'lint_backend_pipeline', +) + ver_mode = 'pr' trigger = { 'event': [ @@ -59,6 +64,7 @@ def pr_pipelines(edition): verify_drone(get_pr_trigger(include_paths=['scripts/drone/**', '.drone.yml', '.drone.star']), ver_mode), test_frontend(get_pr_trigger(exclude_paths=['pkg/**', 'packaging/**', 'go.sum', 'go.mod']), ver_mode), test_backend(get_pr_trigger(include_paths=['pkg/**', 'packaging/**', '.drone.yml', 'conf/**', 'go.sum', 'go.mod', 'public/app/plugins/**/plugin.json', 'devenv/**']), ver_mode), + lint_backend_pipeline(get_pr_trigger(include_paths=['pkg/**', 'packaging/**', 'conf/**', 'go.sum', 'go.mod', 'public/app/plugins/**/plugin.json', 'devenv/**']), ver_mode), build_e2e(trigger, ver_mode, edition), integration_tests(get_pr_trigger(include_paths=['pkg/**', 'packaging/**', '.drone.yml', 'conf/**', 'go.sum', 'go.mod', 'public/app/plugins/**/plugin.json']), ver_mode, edition), docs_pipelines(edition, ver_mode, trigger_docs_pr()), diff --git a/scripts/drone/pipelines/lint_backend.star b/scripts/drone/pipelines/lint_backend.star new file mode 100644 index 00000000000..f127f655db4 --- /dev/null +++ b/scripts/drone/pipelines/lint_backend.star @@ -0,0 +1,31 @@ +load( + 'scripts/drone/steps/lib.star', + 'identify_runner_step', + 'wire_install_step', + 'lint_backend_step', + 'lint_drone_step', + 'compile_build_cmd', +) + +load( + 'scripts/drone/utils/utils.star', + 'pipeline', +) + +def lint_backend_pipeline(trigger, ver_mode): + wire_step = wire_install_step() + wire_step.update({ 'depends_on': [] }) + init_steps = [ + identify_runner_step(), + compile_build_cmd(), + wire_step, + ] + test_steps = [ + lint_backend_step(edition="oss"), + ] + if ver_mode == 'main': + test_steps.extend([lint_drone_step()]) + + return pipeline( + name='{}-lint-backend'.format(ver_mode), edition="oss", trigger=trigger, services=[], steps=init_steps + test_steps, + ) diff --git a/scripts/drone/pipelines/test_backend.star b/scripts/drone/pipelines/test_backend.star index c5982c1507e..1c7c8babe7e 100644 --- a/scripts/drone/pipelines/test_backend.star +++ b/scripts/drone/pipelines/test_backend.star @@ -1,10 +1,7 @@ load( 'scripts/drone/steps/lib.star', 'identify_runner_step', - 'download_grabpl_step', 'wire_install_step', - 'lint_backend_step', - 'lint_drone_step', 'test_backend_step', 'test_backend_integration_step', 'verify_gen_cue_step', @@ -19,18 +16,14 @@ load( def test_backend(trigger, ver_mode): init_steps = [ identify_runner_step(), - download_grabpl_step(), compile_build_cmd(), verify_gen_cue_step(edition="oss"), wire_install_step(), ] test_steps = [ - lint_backend_step(edition="oss"), test_backend_step(edition="oss"), test_backend_integration_step(edition="oss"), ] - if ver_mode == 'main': - test_steps.extend([lint_drone_step()]) return pipeline( name='{}-test-backend'.format(ver_mode), edition="oss", trigger=trigger, services=[], steps=init_steps + test_steps, diff --git a/scripts/drone/steps/lib.star b/scripts/drone/steps/lib.star index d4364986ee9..792955c6c24 100644 --- a/scripts/drone/steps/lib.star +++ b/scripts/drone/steps/lib.star @@ -207,7 +207,7 @@ def enterprise_downstream_step(edition, ver_mode): def lint_backend_step(edition): return { 'name': 'lint-backend' + enterprise2_suffix(edition), - 'image': build_image, + 'image': go_image, 'environment': { # We need CGO because of go-sqlite3 'CGO_ENABLED': '1', @@ -216,6 +216,7 @@ def lint_backend_step(edition): 'wire-install', ], 'commands': [ + 'apt-get update && apt-get install make', # Don't use Make since it will re-download the linters 'make lint-go', ],