Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
workflow "Build and Publish" {
on = "push"
resolves = "Docker Publish"
action "Shell Lint" {
uses = "actions/bin/shellcheck@master"
args = ""
action "Test" {
uses = "actions/bin/bats@master"
args = "test/*.bats"
action "Docker Lint" {
uses = "docker://replicated/dockerfilelint"
args = ["Dockerfile"]
action "Build" {
needs = ["Shell Lint", "Test", "Docker Lint"]
uses = "actions/docker/cli@master"
args = "build -t azure ."
action "Docker Tag" {
needs = ["Build"]
uses = "actions/docker/tag@master"
args = "azure github/azure --no-latest"
action "Publish Filter" {
needs = ["Build"]
uses = "actions/bin/filter@master"
args = "branch master"
action "Docker Login" {
needs = ["Publish Filter"]
uses = "actions/docker/login@master"
action "Docker Publish" {
needs = ["Docker Tag", "Docker Login"]
uses = "actions/docker/cli@master"
args = "push github/azure"
function Get-GitHubActionType {
function Get-GitHubActionTypeName {
$null = $scanner.Scan($QUOTE)
function Get-GitHubActionKVP {
foreach ($line in $block.split("`r`n").where({$_.length -gt 0})) {
$innerScanner = New-PSStringScanner $line
do {
$key = $innerScanner.Scan("\w+")
if($innerScanner.Check('='+$WHITESPACE+$QUOTE)) {
$null = $innerScanner.Scan('=')
$null = $innerScanner.Scan($QUOTE)
$value = $innerScanner.ScanUntil("(?=$QUOTE)")
$null = $innerScanner.Scan($QUOTE)
} else {
$null = $innerScanner.Scan('=')
$null = $innerScanner.Scan($LEFTBRACKET)
$value = Invoke-Expression $innerScanner.ScanUntil("(?=$RIGHTBRACKET)")
$null = $innerScanner.Scan($RIGHTBRACKET)
if ($key) {
[PSCustomObject][Ordered]@{key = $key; value = $value}
} until ($innerScanner.EoS())
function Get-GitHubActionBlock {
$null = $scanner.Scan("\{")
Get-GitHubActionKVP $scanner.ScanUntil("(?=\})")
$null = $scanner.Scan("\}")
function Import-GitHubAction {
$target = Get-Content -Path $Path -Raw
$QUOTE = '"'
$scanner = New-PSStringScanner $target
do {
Type = Get-GitHubActionType
Name = Get-GitHubActionTypeName
Block = Get-GitHubActionBlock
} until ($scanner.EoS())
Copy link

dfinke commented Apr 1, 2019

PS C:\> Import-GitHubAction .\github.action

Type     Name              Block                                                                                                      
----     ----              -----                                                                                                      
workflow Build and Publish {@{key=on; value=push}, @{key=resolves; value=Docker Publish}}                                             
action   Shell Lint        {@{key=uses; value=actions/bin/shellcheck@master}, @{key=args;}}                       
action   Test              {@{key=uses; value=actions/bin/bats@master}, @{key=args; value=test/*.bats}}                               
action   Docker Lint       {@{key=uses; value=docker://replicated/dockerfilelint}, @{key=args; value=Dockerfile}}                     
action   Build             {@{key=needs; value=System.Object[]}, @{key=uses; value=actions/docker/cli@master}, @{key=args; value=bu...
action   Docker Tag        {@{key=needs; value=Build}, @{key=uses; value=actions/docker/tag@master}, @{key=args; value=azure github...
action   Publish Filter    {@{key=needs; value=Build}, @{key=uses; value=actions/bin/filter@master}, @{key=args; value=branch master}}
action   Docker Login      {@{key=needs; value=Publish Filter}, @{key=uses; value=actions/docker/login@master}, @{key=secrets; valu...
action   Docker Publish    {@{key=needs; value=System.Object[]}, @{key=uses; value=actions/docker/cli@master}, @{key=args; value=pu...

Copy link

dfinke commented Apr 1, 2019


foreach($record in Import-GitHubAction .\github.action) {
    foreach ($item in $record.Block) {        
Type     Name              Key      Value                             
----     ----              ---      -----                             
workflow Build and Publish on       push                              
workflow Build and Publish resolves Docker Publish                    
action   Shell Lint        uses     actions/bin/shellcheck@master     
action   Shell Lint        args                     
action   Test              uses     actions/bin/bats@master           
action   Test              args     test/*.bats                       
action   Docker Lint       uses     docker://replicated/dockerfilelint
action   Docker Lint       args     Dockerfile                        
action   Build             needs    {Shell Lint, Test, Docker Lint}   
action   Build             uses     actions/docker/cli@master         
action   Build             args     build -t azure .                  
action   Docker Tag        needs    Build                             
action   Docker Tag        uses     actions/docker/tag@master         
action   Docker Tag        args     azure github/azure --no-latest    
action   Publish Filter    needs    Build                             
action   Publish Filter    uses     actions/bin/filter@master         
action   Publish Filter    args     branch master                     
action   Docker Login      needs    Publish Filter                    
action   Docker Login      uses     actions/docker/login@master       
action   Docker Login      secrets  {DOCKER_USERNAME, DOCKER_PASSWORD}
action   Docker Publish    needs    {Docker Tag, Docker Login}        
action   Docker Publish    uses     actions/docker/cli@master         
action   Docker Publish    args     push github/azure                 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment