Last active
April 28, 2019 16:38
-
-
Save dfinke/8c56cbe95a0e531c24a935fa05633356 to your computer and use it in GitHub Desktop.
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
workflow "Build and Publish" { | |
on = "push" | |
resolves = "Docker Publish" | |
} | |
action "Shell Lint" { | |
uses = "actions/bin/shellcheck@master" | |
args = "entrypoint.sh" | |
} | |
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" | |
secrets = ["DOCKER_USERNAME", "DOCKER_PASSWORD"] | |
} | |
action "Docker Publish" { | |
needs = ["Docker Tag", "Docker Login"] | |
uses = "actions/docker/cli@master" | |
args = "push github/azure" | |
} |
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
function Get-GitHubActionType { | |
$scanner.Scan("\w+") | |
} | |
function Get-GitHubActionTypeName { | |
$scanner.Skip($WHITESPACE) | |
$null = $scanner.Scan($QUOTE) | |
$scanner.ScanUntil("(?=$QUOTE)") | |
} | |
function Get-GitHubActionKVP { | |
param($block) | |
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('=') | |
$innerScanner.Skip($WHITESPACE) | |
$null = $innerScanner.Scan($QUOTE) | |
$value = $innerScanner.ScanUntil("(?=$QUOTE)") | |
$null = $innerScanner.Scan($QUOTE) | |
} else { | |
$null = $innerScanner.Scan('=') | |
$innerScanner.Skip($WHITESPACE) | |
$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 { | |
param( | |
[Parameter(Mandatory)] | |
$Path | |
) | |
$target = Get-Content -Path $Path -Raw | |
$QUOTE = '"' | |
$WHITESPACE = '\s+' | |
$LEFTBRACKET = '\[' | |
$RIGHTBRACKET = '\]' | |
$scanner = New-PSStringScanner $target | |
do { | |
[PSCustomObject][Ordered]@{ | |
Type = Get-GitHubActionType | |
Name = Get-GitHubActionTypeName | |
Block = Get-GitHubActionBlock | |
} | |
} until ($scanner.EoS()) | |
} |
Author
dfinke
commented
Apr 1, 2019
Unrolled
foreach($record in Import-GitHubAction .\github.action) {
foreach ($item in $record.Block) {
[PSCustomObject][Ordered]@{
Type=$record.Type
Name=$record.Name
Key=$item.key
Value=$item.value
}
}
}
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 entrypoint.sh
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