Skip to content

Commit

Permalink
support Drone CI
Browse files Browse the repository at this point in the history
  • Loading branch information
mschuett committed Sep 4, 2021
1 parent 8b9c6ac commit e3ce7e9
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Currently supported formats are
[Bitbucket Pipelines](https://support.atlassian.com/bitbucket-cloud/docs/configure-bitbucket-pipelinesyml/),
[GitLab CI](https://docs.gitlab.com/ee/ci/yaml/gitlab_ci_yaml.html),
[GitHub Actions](https://docs.github.com/en/actions),
[Drone CI](https://docs.drone.io/pipeline/overview/),
and (very limited) [Ansible](https://docs.ansible.com/ansible/2.9/modules/shell_module.html)

## Usage
Expand Down Expand Up @@ -78,6 +79,12 @@ is considered a shell script.
this is a todo, it should be simple enough to only check `sh` and `bash` scripts with right shebang line
* [expressions](https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions) get replaced with a simple variable before running shellcheck

### Drone CI

Drone CI has a very simple file structure. As far as I can tell it only has
conditions, but no deep nesting or includes. All command lists are concatenated
and checked as a shell script.

### GitLab CI Pipelines

GitLab CI files have more structure, and we try to support more of it.
Expand Down
18 changes: 18 additions & 0 deletions test-input/.drone.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
# Drone CI example, from https://docs.drone.io/pipeline/overview/
kind: pipeline
type: docker
name: default

steps:
- name: backend
image: golang
commands:
- go build
- go test

- name: frontend
image: node
commands:
- npm install
- npm run test
22 changes: 22 additions & 0 deletions yaml_shellcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,23 @@ def get_runs(data, path):
return result


def get_drone_scripts(data):
"""Drone CI has a simple file format, with all scripts in
`lists in steps[].commands[]`, see https://docs.drone.io/yaml/exec/
"""
result = {}
if "steps" not in data:
return result
jobkey = data.get("name", "unknown")
for item in data["steps"]:
section = item.get("name")
result[f"{jobkey}/{section}"] = "\n".join(item.get("commands", []))
logging.debug("got scripts: %s", result)
for key in result:
logging.debug("%s: %s", key, result[key])
return result


def get_gitlab_scripts(data):
"""GitLab is nice, as far as I can tell its files have a
flat hierarchy with many small job entities"""
Expand Down Expand Up @@ -245,6 +262,11 @@ def select_yaml_schema(data, filename):
elif isinstance(data, dict) and "on" in data and "jobs" in data:
logging.info(f"read {filename} as GitHub Actions config...")
return get_github_scripts
elif (
isinstance(data, dict) and "steps" in data and "kind" in data and "type" in data
):
logging.info(f"read {filename} as Drone CI config...")
return get_drone_scripts
elif isinstance(data, list):
logging.info(f"read {filename} as Ansible file...")
return get_ansible_scripts
Expand Down

0 comments on commit e3ce7e9

Please sign in to comment.