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
This commit is contained in:
Dimitris Sotirakis 2022-09-21 14:05:19 +03:00 committed by GitHub
parent b25ea75bac
commit c18432971b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 172 additions and 43 deletions

View File

@ -152,12 +152,6 @@ steps:
- echo $DRONE_RUNNER_NAME - echo $DRONE_RUNNER_NAME
image: alpine:3.15.6 image: alpine:3.15.6
name: identify-runner 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: - commands:
- go build -o ./bin/build -ldflags '-extldflags -static' ./pkg/build/cmd - go build -o ./bin/build -ldflags '-extldflags -static' ./pkg/build/cmd
depends_on: [] depends_on: []
@ -180,14 +174,6 @@ steps:
- verify-gen-cue - verify-gen-cue
image: grafana/build-container:1.6.2 image: grafana/build-container:1.6.2
name: wire-install 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: - commands:
- go test -short -covermode=atomic -timeout=30m ./pkg/... - go test -short -covermode=atomic -timeout=30m ./pkg/...
depends_on: depends_on:
@ -228,6 +214,66 @@ depends_on: []
image_pull_secrets: image_pull_secrets:
- dockerconfigjson - dockerconfigjson
kind: pipeline 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 name: pr-build-e2e
node: node:
type: no-parallel type: no-parallel
@ -908,12 +954,6 @@ steps:
- echo $DRONE_RUNNER_NAME - echo $DRONE_RUNNER_NAME
image: alpine:3.15.6 image: alpine:3.15.6
name: identify-runner 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: - commands:
- go build -o ./bin/build -ldflags '-extldflags -static' ./pkg/build/cmd - go build -o ./bin/build -ldflags '-extldflags -static' ./pkg/build/cmd
depends_on: [] depends_on: []
@ -936,14 +976,6 @@ steps:
- verify-gen-cue - verify-gen-cue
image: grafana/build-container:1.6.2 image: grafana/build-container:1.6.2
name: wire-install 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: - commands:
- go test -short -covermode=atomic -timeout=30m ./pkg/... - go test -short -covermode=atomic -timeout=30m ./pkg/...
depends_on: depends_on:
@ -956,6 +988,60 @@ steps:
- wire-install - wire-install
image: grafana/build-container:1.6.2 image: grafana/build-container:1.6.2
name: test-backend-integration 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: - commands:
- ./bin/build verify-drone - ./bin/build verify-drone
depends_on: depends_on:
@ -2115,12 +2201,13 @@ steps:
image: golang:1.19.1 image: golang:1.19.1
name: compile-build-cmd name: compile-build-cmd
- commands: - commands:
- apt-get update && apt-get install make
- make lint-go - make lint-go
depends_on: depends_on:
- wire-install - wire-install
environment: environment:
CGO_ENABLED: "1" CGO_ENABLED: "1"
image: grafana/build-container:1.6.2 image: golang:1.19.1
name: lint-backend name: lint-backend
- commands: - commands:
- yarn run prettier:check - yarn run prettier:check
@ -2772,12 +2859,13 @@ steps:
image: grafana/build-container:1.6.2 image: grafana/build-container:1.6.2
name: verify-gen-cue name: verify-gen-cue
- commands: - commands:
- apt-get update && apt-get install make
- make lint-go - make lint-go
depends_on: depends_on:
- wire-install - wire-install
environment: environment:
CGO_ENABLED: "1" CGO_ENABLED: "1"
image: grafana/build-container:1.6.2 image: golang:1.19.1
name: lint-backend name: lint-backend
- commands: - commands:
- yarn run prettier:check - yarn run prettier:check
@ -2811,12 +2899,13 @@ steps:
image: grafana/build-container:1.6.2 image: grafana/build-container:1.6.2
name: test-frontend name: test-frontend
- commands: - commands:
- apt-get update && apt-get install make
- make lint-go - make lint-go
depends_on: depends_on:
- wire-install - wire-install
environment: environment:
CGO_ENABLED: "1" CGO_ENABLED: "1"
image: grafana/build-container:1.6.2 image: golang:1.19.1
name: lint-backend-enterprise2 name: lint-backend-enterprise2
- commands: - commands:
- go test -tags=pro -covermode=atomic -timeout=30m ./pkg/... - go test -tags=pro -covermode=atomic -timeout=30m ./pkg/...
@ -4080,12 +4169,13 @@ steps:
image: golang:1.19.1 image: golang:1.19.1
name: compile-build-cmd name: compile-build-cmd
- commands: - commands:
- apt-get update && apt-get install make
- make lint-go - make lint-go
depends_on: depends_on:
- wire-install - wire-install
environment: environment:
CGO_ENABLED: "1" CGO_ENABLED: "1"
image: grafana/build-container:1.6.2 image: golang:1.19.1
name: lint-backend name: lint-backend
- commands: - commands:
- yarn run prettier:check - yarn run prettier:check
@ -4701,12 +4791,13 @@ steps:
image: grafana/build-container:1.6.2 image: grafana/build-container:1.6.2
name: verify-gen-cue name: verify-gen-cue
- commands: - commands:
- apt-get update && apt-get install make
- make lint-go - make lint-go
depends_on: depends_on:
- wire-install - wire-install
environment: environment:
CGO_ENABLED: "1" CGO_ENABLED: "1"
image: grafana/build-container:1.6.2 image: golang:1.19.1
name: lint-backend name: lint-backend
- commands: - commands:
- yarn run prettier:check - yarn run prettier:check
@ -4740,12 +4831,13 @@ steps:
image: grafana/build-container:1.6.2 image: grafana/build-container:1.6.2
name: test-frontend name: test-frontend
- commands: - commands:
- apt-get update && apt-get install make
- make lint-go - make lint-go
depends_on: depends_on:
- wire-install - wire-install
environment: environment:
CGO_ENABLED: "1" CGO_ENABLED: "1"
image: grafana/build-container:1.6.2 image: golang:1.19.1
name: lint-backend-enterprise2 name: lint-backend-enterprise2
- commands: - commands:
- go test -tags=pro -covermode=atomic -timeout=30m ./pkg/... - go test -tags=pro -covermode=atomic -timeout=30m ./pkg/...
@ -5178,6 +5270,6 @@ kind: secret
name: packages_secret_access_key name: packages_secret_access_key
--- ---
kind: signature kind: signature
hmac: b08cb03f133c943a789bf6abf7f2645536598e4d8a5a86b34b9231db8afc8ff4 hmac: a17adc518f8ba4ea5c123bf440adf9aceec5e7ba5d9fdae9e467dbd1ec91fd46
... ...

View File

@ -47,6 +47,11 @@ load(
'enterprise_downstream_pipeline', 'enterprise_downstream_pipeline',
) )
load(
'scripts/drone/pipelines/lint_backend.star',
'lint_backend_pipeline',
)
load('scripts/drone/vault.star', 'from_secret') load('scripts/drone/vault.star', 'from_secret')
@ -84,6 +89,7 @@ def main_pipelines(edition):
docs_pipelines(edition, ver_mode, trigger_docs_main()), docs_pipelines(edition, ver_mode, trigger_docs_main()),
test_frontend(trigger, ver_mode), test_frontend(trigger, ver_mode),
test_backend(trigger, ver_mode), test_backend(trigger, ver_mode),
lint_backend_pipeline(trigger, ver_mode),
build_e2e(trigger, ver_mode, edition), build_e2e(trigger, ver_mode, edition),
integration_tests(trigger, ver_mode, edition), integration_tests(trigger, ver_mode, edition),
windows(trigger, edition, ver_mode), windows(trigger, edition, ver_mode),

View File

@ -39,6 +39,11 @@ load(
'shellcheck_pipeline', 'shellcheck_pipeline',
) )
load(
'scripts/drone/pipelines/lint_backend.star',
'lint_backend_pipeline',
)
ver_mode = 'pr' ver_mode = 'pr'
trigger = { trigger = {
'event': [ 'event': [
@ -59,6 +64,7 @@ def pr_pipelines(edition):
verify_drone(get_pr_trigger(include_paths=['scripts/drone/**', '.drone.yml', '.drone.star']), ver_mode), 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_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), 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), 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), 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()), docs_pipelines(edition, ver_mode, trigger_docs_pr()),

View File

@ -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,
)

View File

@ -1,10 +1,7 @@
load( load(
'scripts/drone/steps/lib.star', 'scripts/drone/steps/lib.star',
'identify_runner_step', 'identify_runner_step',
'download_grabpl_step',
'wire_install_step', 'wire_install_step',
'lint_backend_step',
'lint_drone_step',
'test_backend_step', 'test_backend_step',
'test_backend_integration_step', 'test_backend_integration_step',
'verify_gen_cue_step', 'verify_gen_cue_step',
@ -19,18 +16,14 @@ load(
def test_backend(trigger, ver_mode): def test_backend(trigger, ver_mode):
init_steps = [ init_steps = [
identify_runner_step(), identify_runner_step(),
download_grabpl_step(),
compile_build_cmd(), compile_build_cmd(),
verify_gen_cue_step(edition="oss"), verify_gen_cue_step(edition="oss"),
wire_install_step(), wire_install_step(),
] ]
test_steps = [ test_steps = [
lint_backend_step(edition="oss"),
test_backend_step(edition="oss"), test_backend_step(edition="oss"),
test_backend_integration_step(edition="oss"), test_backend_integration_step(edition="oss"),
] ]
if ver_mode == 'main':
test_steps.extend([lint_drone_step()])
return pipeline( return pipeline(
name='{}-test-backend'.format(ver_mode), edition="oss", trigger=trigger, services=[], steps=init_steps + test_steps, name='{}-test-backend'.format(ver_mode), edition="oss", trigger=trigger, services=[], steps=init_steps + test_steps,

View File

@ -207,7 +207,7 @@ def enterprise_downstream_step(edition, ver_mode):
def lint_backend_step(edition): def lint_backend_step(edition):
return { return {
'name': 'lint-backend' + enterprise2_suffix(edition), 'name': 'lint-backend' + enterprise2_suffix(edition),
'image': build_image, 'image': go_image,
'environment': { 'environment': {
# We need CGO because of go-sqlite3 # We need CGO because of go-sqlite3
'CGO_ENABLED': '1', 'CGO_ENABLED': '1',
@ -216,6 +216,7 @@ def lint_backend_step(edition):
'wire-install', 'wire-install',
], ],
'commands': [ 'commands': [
'apt-get update && apt-get install make',
# Don't use Make since it will re-download the linters # Don't use Make since it will re-download the linters
'make lint-go', 'make lint-go',
], ],