Skip to content

Commit

Permalink
CI: Introduce lint-backend pipeline (#55476)
Browse files Browse the repository at this point in the history
* Introduce lint-backend pipeline

* Use go image and install make

* Don't run lint pipeline on .drone.yml changes
  • Loading branch information
dsotirakis committed Sep 21, 2022
1 parent b25ea75 commit c184329
Show file tree
Hide file tree
Showing 6 changed files with 172 additions and 43 deletions.
162 changes: 127 additions & 35 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: []
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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: []
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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/...
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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/...
Expand Down Expand Up @@ -5178,6 +5270,6 @@ kind: secret
name: packages_secret_access_key
---
kind: signature
hmac: b08cb03f133c943a789bf6abf7f2645536598e4d8a5a86b34b9231db8afc8ff4
hmac: a17adc518f8ba4ea5c123bf440adf9aceec5e7ba5d9fdae9e467dbd1ec91fd46

...
6 changes: 6 additions & 0 deletions scripts/drone/events/main.star
Original file line number Diff line number Diff line change
Expand Up @@ -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')


Expand Down Expand Up @@ -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),
Expand Down
6 changes: 6 additions & 0 deletions scripts/drone/events/pr.star
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ load(
'shellcheck_pipeline',
)

load(
'scripts/drone/pipelines/lint_backend.star',
'lint_backend_pipeline',
)

ver_mode = 'pr'
trigger = {
'event': [
Expand All @@ -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()),
Expand Down
31 changes: 31 additions & 0 deletions scripts/drone/pipelines/lint_backend.star
Original file line number Diff line number Diff line change
@@ -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,
)
7 changes: 0 additions & 7 deletions scripts/drone/pipelines/test_backend.star
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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,
Expand Down

0 comments on commit c184329

Please sign in to comment.