Highlight

Need to build WIKI flows in automated way for Azure Data Factory? Here’s how!

Check this out :)

The basics

Add below to pipelines in ADO and enjoy!

The Code

trigger:
  branches:
    include:
    - master
  paths:
    include:
    - pipeline
    exclude:
    - docs

pool:
  vmImage: ubuntu-latest

steps:
- checkout: self
  persistCredentials: true

- task: PowerShell@2
  inputs:
    filePath: './scripts/generate-md-ado.ps1'
    workingDirectory: $(System.DefaultWorkingDirectory)

- script: |
   git config user.email [email protected]
   git config user.name "your name"
   git diff
   git  add .
   git commit -m "version update [skip ci]"
   git push origin HEAD:master   

MermaidJS script

and powershell

$files = Get-ChildItem ./pipeline

if (Test-Path -LiteralPath ./docs) {
    Remove-Item ./docs -Recurse
}
New-Item ./docs/ -ItemType Directory

foreach ($file in $files) {
    $content = Get-Content -Path $file.FullName | ConvertFrom-Json
    $fileName = $content.Name.Replace(" ", "-")
    $fileName = "./docs/$($fileName).md"
    "# $($content.Name)" > $fileName 
    "::: mermaid" >> $fileName 
    "graph LR;" >> $fileName 
    $linkId = 0

    foreach ($activity in $content.properties.activities) {
        $activityName = $activity.Name.Replace(" ","")
        "$activityName[$($activity.Name)]" >> $fileName 

        foreach ($dependency in $activity.dependsOn) {
            if ($dependency.dependencyConditions -eq "Succeeded") {
                $color = "linkStyle $linkId stroke:green;"
            } elseif ($dependency.dependencyConditions -eq "Failed") {
                $color = "linkStyle $linkId stroke:red;"
            } 
            $linkId += 1
            $dependencyActivityName = $dependency.activity.Replace(" ", "")
            "$dependencyActivityName --> $activityName" >> $fileName 
            "$color" >> $fileName 
        }
    }

    ":::" >> $fileName 
}

PlantUML script

$files = Get-ChildItem ./main/pipeline
foreach ($file in $files) {
    $content = Get-Content -Path $file.FullName | ConvertFrom-Json
    $fileName = "./main/docs/$($content.Name).puml"
    "@startuml $($content.Name)" > $fileName 
    "left to right direction" >> $fileName 

    foreach ($activity in $content.properties.activities) {
        $activityName = $activity.Name.Replace(" ","")
        "rectangle $activityName" >> $fileName 

        foreach ($dependency in $activity.dependsOn) {
            if ($dependency.dependencyConditions -eq "Succeeded") {
                $color = "#green"
            } elseif ($dependency.dependencyConditions -eq "Failed") {
                $color = "#red"
            }
            $dependencyActivityName = $dependency.activity.Replace(" ", "")
            "$dependencyActivityName --> $activityName $color" >> $fileName 
        }
    }

    "@enduml" >> $fileName 
}

And that’s it!

Adam Marczak

Programmer, architect, trainer, blogger, evangelist are just a few of my titles. What I really am, is a passionate technology enthusiast. I take great pleasure in learning new technologies and finding ways in which this can aid people every day. My latest passion is running an Azure 4 Everyone YouTube channel, where I show that Azure really is for everyone!

Did you enjoy the article?

Share it!

More tagged posts