Files
grafana/scripts/drone/events/pr.star
Kat Yang bbcc81405b Chore: Add CI Pipeline to generate Grafana's OpenAPI specification (#75393)
* chore: move over initial changes from sofia's pr #58029

* chore: remove go_image

* chore: begin removing edition, remove unused imports

* chore: remove edition from swagger_gen.star and generate .drone.yml

* chore: regen drone.yml

* fix: fix order of load statements

* fix: try #2 fix order of load statements

* linter fixes

* chore: add doc comment explaining purpose of new clone_pr_branch step

* fix: add placeholder documentation for ver_mode arg

* attempt #1 to import and use clone_enterprise_step_pr

* Update scripts/drone/pipelines/swagger_gen.star

Co-authored-by: Sofia Papagiannaki <1632407+papagian@users.noreply.github.com>

* attempt #2 to import and use clone_enterprise_step_pr

* fix: fix drone lint err invalid or unknown step dependency

* fix: regen hmac to make drone run

* fix: fix drone lint err

* fix: update swagger-clean cmd in step

* attempt to return non zero exit code

* test to see if pipeline fails

* fix: add git to clone pr branch step

* fix: add git and make to swagger-gen step

* try to rerun drone

* debug: figure out why cannot find make swagger-clean

* debug: see if cd grafana/grafana fixes things

* debug: undo cd grafana/grafana

* debug: add more logging statements

* debug: try and remove cd grafana in swagger-gen

* debug: removed grafana after clone statement; add debug before cloning

* fix: remove disable clone

* regen specs to see if swagger-gen step passes now

* add descriptive error message to swagger-gen step

* remove api-spec.json from .gitignore

* revert backend change, regen spec

* add back backend change, regen specs

* Update scripts/drone/pipelines/swagger_gen.star

Co-authored-by: Sofia Papagiannaki <1632407+papagian@users.noreply.github.com>

* Update scripts/drone/pipelines/swagger_gen.star

Co-authored-by: Sofia Papagiannaki <1632407+papagian@users.noreply.github.com>

* revert gitignore change, set enterprise source to drone source branch

* chore: remove unused variable, change committish var name to source

* testing functionality: make a new BE change without gen spec, pipeline should fail

* test functionality: does removing err msg cause step to fail properly

* test functionality: add back err msg and && after

* chore: remove debug statements from swagger gen step

* chore: remove debug lines from clone_pr_branch step

* test functionality: regen specs, swagger_gen step should pass

* test funcionality: regen specs again ????

* chore: update swagger-gen step err msg

* test functionality: make BE change dont regen spec, swagger gen should fail

* test functionality: regen the specs, swagger-gen should pass

* chore: revert test BE change, regen spec

* chore: remove unused clone step

* chore: regen drone.yml

---------

Co-authored-by: Timur Olzhabayev <timur.olzhabayev@grafana.com>
Co-authored-by: Sofia Papagiannaki <1632407+papagian@users.noreply.github.com>
2023-10-24 13:01:04 -04:00

185 lines
4.7 KiB
Plaintext

"""
This module returns all pipelines used in the event of a pull request.
It also includes a function generating a PR trigger from a list of included and excluded paths.
"""
load(
"scripts/drone/pipelines/benchmarks.star",
"integration_benchmarks",
)
load(
"scripts/drone/pipelines/build.star",
"build_e2e",
)
load(
"scripts/drone/pipelines/docs.star",
"docs_pipelines",
"trigger_docs_pr",
)
load(
"scripts/drone/pipelines/integration_tests.star",
"integration_tests",
)
load(
"scripts/drone/pipelines/lint_backend.star",
"lint_backend_pipeline",
)
load(
"scripts/drone/pipelines/lint_frontend.star",
"lint_frontend_pipeline",
)
load(
"scripts/drone/pipelines/shellcheck.star",
"shellcheck_pipeline",
)
load(
"scripts/drone/pipelines/swagger_gen.star",
"swagger_gen",
)
load(
"scripts/drone/pipelines/test_backend.star",
"test_backend",
)
load(
"scripts/drone/pipelines/test_frontend.star",
"test_frontend",
)
load(
"scripts/drone/pipelines/verify_drone.star",
"verify_drone",
)
load(
"scripts/drone/pipelines/verify_starlark.star",
"verify_starlark",
)
ver_mode = "pr"
trigger = {
"event": [
"pull_request",
],
"paths": {
"exclude": [
"*.md",
"docs/**",
"latest.json",
],
},
}
def pr_pipelines():
return [
verify_drone(
get_pr_trigger(
include_paths = ["scripts/drone/**", ".drone.yml", ".drone.star"],
),
ver_mode,
),
verify_starlark(
get_pr_trigger(
include_paths = ["scripts/drone/**", ".drone.star"],
),
ver_mode,
),
test_frontend(
get_pr_trigger(
exclude_paths = ["pkg/**", "packaging/**", "go.sum", "go.mod"],
),
ver_mode,
),
lint_frontend_pipeline(
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/**",
".drone.yml",
"conf/**",
"go.sum",
"go.mod",
"public/app/plugins/**/plugin.json",
"devenv/**",
".bingo/**",
],
),
ver_mode,
),
build_e2e(trigger, ver_mode),
integration_tests(
get_pr_trigger(
include_paths = [
"pkg/**",
"packaging/**",
".drone.yml",
"conf/**",
"go.sum",
"go.mod",
"public/app/plugins/**/plugin.json",
],
),
prefix = ver_mode,
),
docs_pipelines(ver_mode, trigger_docs_pr()),
shellcheck_pipeline(),
swagger_gen(
get_pr_trigger(include_paths = ["pkg/**"]),
ver_mode,
),
integration_benchmarks(
prefix = ver_mode,
),
]
def get_pr_trigger(include_paths = None, exclude_paths = None):
"""Generates a trigger filter from the lists of included and excluded path patterns.
This function is primarily intended to generate a trigger for code changes
as the patterns 'docs/**' and '*.md' are always excluded.
Args:
include_paths: a list of path patterns using the same syntax as gitignore.
Changes affecting files matching these path patterns trigger the pipeline.
exclude_paths: a list of path patterns using the same syntax as gitignore.
Changes affecting files matching these path patterns do not trigger the pipeline.
Returns:
Drone trigger.
"""
paths_ex = ["docs/**", "*.md"]
paths_in = []
if include_paths:
for path in include_paths:
paths_in.extend([path])
if exclude_paths:
for path in exclude_paths:
paths_ex.extend([path])
return {
"event": [
"pull_request",
],
"paths": {
"exclude": paths_ex,
"include": paths_in,
},
}