Skip to content

Instantly share code, notes, and snippets.

@kui
Last active June 21, 2021 10:36
Show Gist options
  • Save kui/2f0c0316551824f6f6d274c6ecb4a56b to your computer and use it in GitHub Desktop.
Save kui/2f0c0316551824f6f6d274c6ecb4a56b to your computer and use it in GitHub Desktop.
Generate graph of drone steps using "depends_on"

Visualizing script for steps dependencies.

Requirements

  • graphviz
  • node

Usage

In your terminal:

mkdir vis_drone_steps
cd vis_drone_steps
wget https://gist.githubusercontent.com/kui/2f0c0316551824f6f6d274c6ecb4a56b/raw/index.js
wget https://gist.githubusercontent.com/kui/2f0c0316551824f6f6d274c6ecb4a56b/raw/package.json
npm install
node index.js < .drone.yml > drone.dot
dot -odrone.png -Tpng drone.dot
open drone.png

Sample

Small sample from https://discourse.drone.io/t/how-to-setup-parallel-pipeline-steps-1-0/3251

const yaml = require("js-yaml");
const process = require('process');
async function main() {
const docs = yaml.loadAll(await readStdin());
//console.log(docs);
console.log('digraph G {');
docs.forEach((doc) => {
const docName = escape(doc.name);
console.log(`subgraph cluster_${docName} {`);
console.log(`label = ${docName}`);
doc.steps.forEach((step) => {
const stepName = escape(step.name);
const dependsOn = step["depends_on"];
console.log(`${docName}_${stepName} [ label = ${stepName} ]`);
if (dependsOn && dependsOn.length > 0) {
dependsOn.forEach((s) => {
console.log(`${docName}_${escape(s)} -> ${docName}_${stepName}`);
});
}
});
console.log('}');
});
console.log('}');
}
function escape(str) {
return str.replace(/-/g, '_');
}
function readStdin() {
return new Promise((resolve, reject) => {
const c = [];
process.stdin.on('data', (chunk) => {
c.push(chunk);
});
process.stdin.on('end', () => {
resolve(Buffer.concat(c).toString('UTF-8'));
});
});
}
main();
{
"private": true,
"name": "drone-dep-graph",
"version": "1.0.0",
"description": "Generate grap of steps from drone \"depends_on\"",
"main": "index.js",
"author": "",
"license": "ISC",
"dependencies": {
"js-yaml": "^3.13.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment