forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chore: Add CI Pipeline to generate Grafana's OpenAPI specification (g…
…rafana#75393) * chore: move over initial changes from sofia's pr grafana#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 <[email protected]> * 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 <[email protected]> * Update scripts/drone/pipelines/swagger_gen.star Co-authored-by: Sofia Papagiannaki <[email protected]> * 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 <[email protected]> Co-authored-by: Sofia Papagiannaki <[email protected]>
- Loading branch information
1 parent
be6b407
commit bbcc814
Showing
5 changed files
with
219 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1132,6 +1132,66 @@ volumes: | |
clone: | ||
retries: 3 | ||
depends_on: [] | ||
image_pull_secrets: | ||
- dockerconfigjson | ||
kind: pipeline | ||
name: pr-swagger-gen | ||
node: | ||
type: no-parallel | ||
platform: | ||
arch: amd64 | ||
os: linux | ||
services: [] | ||
steps: | ||
- commands: | ||
- apk add --update curl jq bash | ||
- is_fork=$(curl "https://[email protected]/repos/grafana/grafana/pulls/$DRONE_PULL_REQUEST" | ||
| jq .head.repo.fork) | ||
- if [ "$is_fork" != false ]; then return 1; fi | ||
- git clone "https://$${GITHUB_TOKEN}@github.com/grafana/grafana-enterprise.git" | ||
grafana-enterprise | ||
- cd grafana-enterprise | ||
- if git checkout ${DRONE_SOURCE_BRANCH}; then echo "checked out ${DRONE_SOURCE_BRANCH}"; | ||
elif git checkout main; then echo "git checkout main"; else git checkout main; | ||
fi | ||
environment: | ||
GITHUB_TOKEN: | ||
from_secret: github_token | ||
image: alpine/git:2.40.1 | ||
name: clone-enterprise | ||
- commands: | ||
- apk add --update git make | ||
- make swagger-clean && make openapi3-gen | ||
- for f in public/api-merged.json public/openapi3.json; do git add $f; done | ||
- if [ -z "$(git diff --name-only --cached)" ]; then echo "Everything seems up to | ||
date!"; else echo "Please ensure the branch is up-to-date, then regenerate the | ||
specification by running make swagger-clean && make openapi3-gen" && return 1; | ||
fi | ||
depends_on: | ||
- clone-enterprise | ||
environment: | ||
GITHUB_TOKEN: | ||
from_secret: github_token | ||
image: golang:1.20.10-alpine | ||
name: swagger-gen | ||
trigger: | ||
event: | ||
- pull_request | ||
paths: | ||
exclude: | ||
- docs/** | ||
- '*.md' | ||
include: | ||
- pkg/** | ||
type: docker | ||
volumes: | ||
- host: | ||
path: /var/run/docker.sock | ||
name: docker | ||
--- | ||
clone: | ||
retries: 3 | ||
depends_on: [] | ||
environment: | ||
EDITION: oss | ||
image_pull_secrets: | ||
|
@@ -4607,6 +4667,6 @@ kind: secret | |
name: gcr_credentials | ||
--- | ||
kind: signature | ||
hmac: 93de8a710e23d3f1d31860f9eed34cd841b0a0eb48637971de4e8ce60a7c3df1 | ||
hmac: 29a933affceb9cc39b285d936de9e6327deedbb80f1285fa645d596f89ede442 | ||
|
||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
""" | ||
This module returns all pipelines used in OpenAPI specification generation of Grafana HTTP APIs | ||
""" | ||
|
||
load( | ||
"scripts/drone/steps/lib.star", | ||
"clone_enterprise_step_pr", | ||
) | ||
load( | ||
"scripts/drone/utils/images.star", | ||
"images", | ||
) | ||
load( | ||
"scripts/drone/utils/utils.star", | ||
"pipeline", | ||
) | ||
load( | ||
"scripts/drone/vault.star", | ||
"from_secret", | ||
) | ||
|
||
def swagger_gen_step(ver_mode): | ||
if ver_mode != "pr": | ||
return None | ||
|
||
return { | ||
"name": "swagger-gen", | ||
"image": images["go"], | ||
"environment": { | ||
"GITHUB_TOKEN": from_secret("github_token"), | ||
}, | ||
"commands": [ | ||
"apk add --update git make", | ||
"make swagger-clean && make openapi3-gen", | ||
"for f in public/api-merged.json public/openapi3.json; do git add $f; done", | ||
'if [ -z "$(git diff --name-only --cached)" ]; then echo "Everything seems up to date!"; else echo "Please ensure the branch is up-to-date, then regenerate the specification by running make swagger-clean && make openapi3-gen" && return 1; fi', | ||
], | ||
"depends_on": [ | ||
"clone-enterprise", | ||
], | ||
} | ||
|
||
def swagger_gen(trigger, ver_mode, source = "${DRONE_SOURCE_BRANCH}"): | ||
test_steps = [ | ||
clone_enterprise_step_pr(source = source), | ||
swagger_gen_step(ver_mode = ver_mode), | ||
] | ||
|
||
p = pipeline( | ||
name = "{}-swagger-gen".format(ver_mode), | ||
trigger = trigger, | ||
services = [], | ||
steps = test_steps, | ||
) | ||
|
||
return p |