Skip to content

Commit afbe552

Browse files
authored
Merge pull request #1 from wild-devops/develop
Develop
2 parents 2566fc7 + 9f085c0 commit afbe552

18 files changed

+108
-324
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ The result looks like the followed output including information about:
6969
* `PWSHAKE config:` - loaded config file content (may be rearranged due to overriding, interpolation, and merging metadata)
7070
* `Arranged tasks:` - tasks to be executed in actual order
7171
* `Invoke task:` - invoked tasks name
72-
* `Execute <step|powershell|cmd|msbuild>:` - invoked steps caption
72+
* `Execute <step|powershell|cmd>:` - invoked steps caption
7373
* Everything else - invoked scripts output
7474

7575
```

doc/step.md

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@ The internal representation of a single **step** looks like a following **Powers
66
```
77
@{
88
name = $null;
9+
when = "`$true";
10+
work_dir = $null;
11+
on_error = "throw";
912
script = $null;
1013
powershell = $null;
1114
cmd = $null;
12-
msbuild = @{
13-
project = $null;
14-
targets = $null;
15-
properties = $null;
16-
};
17-
when = "`$true";
1815
invoke_tasks = $null;
16+
template = $null;
17+
parameters = @{};
1918
}
2019
```
2120

@@ -47,19 +46,16 @@ So, the full allowed form of the `- [step]:` element could be the following:
4746
script: script_name
4847
powershell: "some inline powershell code"
4948
cmd: "other inline cmd.exe commands"
50-
msbuild:
51-
project: some_project_file_name
52-
targets: "List,Of,Targets"
53-
properties: "MyProperty=Assigned"
49+
template: my_template
5450
when: $true
5551
...
5652
```
57-
But **PWSHAKE** engine take pecedence over the given structure items and executes only the first non empty item, in this case `script:` item with '`script_name`' value, all others (`powershell:`, `cmd:`, `msbuild:`) are ignored.
53+
But **PWSHAKE** engine take pecedence over the given structure items and executes only the first non empty item, in this case `script:` item with '`script_name`' value, all others (`powershell:`, `cmd:`, `template:`) are ignored.
5854

5955
* ### - `[step]:` element implicit shortenings
6056
Since the actual payload in the executed structure have only the two elements:
6157
* `name:`
62-
* first non empty of `[script: | powershell: | cmd: | msbuild:]`
58+
* first non empty of `[script: | powershell: | cmd:]`
6359

6460
There are allowed some implicit shortenings in the `[step]:` element `yaml` syntax.
6561

@@ -99,24 +95,6 @@ But **PWSHAKE** engine take pecedence over the given structure items and execute
9995
- name: Deploy package
10096
cmd: npm publish
10197
```
102-
103-
* ### - `[msbuild]:` element implicit shortenings
104-
All things described above are eligible for the `msbuild:` element.
105-
106-
107-
Since the actual payload of this element is the **MSBuild** project file name, so the shortening syntax use this value as a `project:` element value.
108-
109-
Example:
110-
```
111-
- name: Build
112-
msbuild: some_project_file_name
113-
```
114-
This is actually the same as:
115-
```
116-
- name: Build
117-
msbuild:
118-
project: some_project_file_name
119-
```
12098

12199
* ### - `[powershell|cmd]:` element implicit shortenings
122100
Since the `[powershell|cmd]:` elements contain inline code that can be too long and\or complex to use it as the meaningful name, so the `name:` property for these shortenings is generated from the `.GetHashCode()` method of the supplied inline string to distinct each other inline step in the **PWSHAKE** engine log.

doc/tasks.md

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -120,19 +120,6 @@ Every named element of the `tasks:` can contain some definitions to provide more
120120
-multiline -code -with -long ^
121121
-list -of -fake -parameters
122122
```
123-
* `- msbuild:` - element to run **MSBuild** with particular settings
124-
125-
Example:
126-
```
127-
tasks:
128-
build:
129-
- msbuild: .\MySolution.sln
130-
- msbuild:
131-
project: .\MyProject.csproj
132-
targets: TransformConfigs
133-
properties: Configuration=Debug
134-
```
135-
The above are 2 calls to **MSBuild**: the first is in shortened form and just uses default target (`Build`) and default options, the second uses given parameters `targets:` and `properties:` passed from `pwshake.yaml` config.
136123
137124
* `- [step]:` - an implicit element to fulfill the particular step settings in explicit way
138125
@@ -147,7 +134,8 @@ Every named element of the `tasks:` can contain some definitions to provide more
147134
cmd: echo 'step2'
148135
- step3:
149136
name: Do msbuild task
150-
msbuild:
137+
template: msbuild
138+
parameters:
151139
project: .\MyProject.csproj
152140
targets: TransformConfigs
153141
properties: Configuration=Debug

examples/example.msbuild.proj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
3-
ToolsVersion="4.0"
3+
ToolsVersion="4.0"
44
DefaultTargets="Hello">
55

6-
<PropertyGroup>
7-
<Configuration Condition="'$(Configuration)' == ''">Debug</Configuration>
8-
</PropertyGroup>
6+
<PropertyGroup>
7+
<Configuration Condition="'$(Configuration)' == ''">Debug</Configuration>
8+
</PropertyGroup>
99

1010
<Target Name="Hello">
11-
<Message Text="Hello from MSBuild with $(Configuration) mode." />
11+
<Message Text="Hello from MSBuild with $(Configuration) mode." Importance="High" />
1212
</Target>
1313

1414
<Target Name="Build">
15-
<Message Text="Building in $(Configuration) mode." />
15+
<Message Text="Building in $(Configuration) mode." Importance="High" />
1616
<Error Text="Something went wrong." />
1717
</Target>
1818

examples/msbuild_pwshake.yaml

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,40 @@
11
attributes:
22
configuration: Release
33

4-
# List of directories relative to this file location where executable scripts are looking for (can be omitted)
5-
scripts_directories:
6-
- .
4+
templates:
5+
doitall:
6+
parameters:
7+
payload:
8+
cmd: >
9+
[[payload]]
10+
dotnet:
11+
template: doitall
12+
parameters:
13+
payload: dotnet [[command]] [[options]]
14+
command:
15+
options: --version
16+
msbuild:
17+
template: dotnet
18+
parameters:
19+
command: msbuild
20+
options: >
21+
[[project]]
22+
/t:[[targets]]
23+
/p:[[properties]]
24+
project: '{{pwshake_path}}/example.msbuild.proj'
25+
targets: Hello
26+
properties: Configuration=Debug
727

8-
# Declaration of run lists that compose and determine order of executing for scripts
928
tasks:
1029
msbuild:
11-
- msbuild: '{{pwshake_path}}\example.msbuild.proj'
12-
- msbuild:
13-
project: '{{pwshake_path}}\example.msbuild.proj'
30+
- template: msbuild
31+
- template: msbuild
32+
on_error: continue
33+
parameters:
1434
targets: Build
1535
properties: Configuration={{configuration}}
36+
- pwsh: Write-Host '<<something>>'
37+
- template: dotnet
1638

17-
# Run lists to current execute
1839
invoke_tasks:
1940
- msbuild

examples/pwshake_config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ tasks:
6868
scripts:
6969
- create_linux
7070
- update_linux
71-
- name: Check msbuild step parsing relative to pwshake_path
72-
msbuild: build.properties
71+
- name: Check the step parsing relative to pwshake_path
72+
cmd: build.properties
7373
when: $false
74-
- name: Check msbuild step parsing relative to work_dir
75-
msbuild: build.properties
74+
- name: Check the step parsing relative to work_dir
75+
cmd: build.properties
7676
when: $false
7777

7878
# Run lists to execute

pwshake.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ param(
2222
[switch]$DryRun,
2323

2424
[Parameter(Mandatory = $false)]
25-
[string]$Version = "1.0.0"
25+
[string]$Version = "1.1.0"
2626
)
2727

2828
$ErrorActionPreference = "Stop"

pwshake/pwshake.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
RootModule = 'pwshake.psm1'
1313

1414
# Version number of this module.
15-
ModuleVersion = '1.0.0'
15+
ModuleVersion = '1.1.0'
1616

1717
# Supported PSEditions
1818
# CompatiblePSEditions = @()

pwshake/scripts/Execute-Step.ps1

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ function Execute-Step {
1515
return;
1616
}
1717

18-
if ($step.script) {
18+
if ($step.template) {
19+
Execute-Step $config (Normalize-Template $step $config)
20+
} elseif ($step.script) {
1921
$paths = $config.scripts_directories | ForEach-Object { Join-Path $config.attributes.pwshake_path -ChildPath $_ }
2022
$script_path = Get-ChildItem $paths -File `
2123
| Where-Object BaseName -eq $step.script `
@@ -32,13 +34,6 @@ function Execute-Step {
3234
$cmd += $item
3335
}
3436
Cmd-Shell $cmd -errorMessage "$($step.name) failed."
35-
} elseif ($step.msbuild) {
36-
$msbuild = "msbuild"
37-
if (${is-Linux}) { $msbuild = "dotnet msbuild" }
38-
$msbuild += " $($step.msbuild.project)"
39-
if ($step.msbuild.targets) { $msbuild += " /t:$($step.msbuild.targets)" }
40-
if ($step.msbuild.properties) { $msbuild += " /p:$($step.msbuild.properties)" }
41-
Cmd-Shell $msbuild -errorMessage "$($step.name) failed."
4237
} elseif ($step.invoke_tasks) {
4338
$tasks = Arrange-Tasks $config $step.invoke_tasks
4439
foreach ($task in $tasks) {

pwshake/scripts/Invoke-Step.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function Invoke-Step {
2626
}
2727
Push-Location (Normalize-Path "$($step.work_dir)" $config)
2828

29-
Log-Output "Execute step: $($step.name)" $config 6>&1
29+
Log-Output "Execute step: $($step.name)" $config
3030
$logOut = @()
3131
$global:LASTEXITCODE = 0
3232
Execute-Step $config $step *>&1 | Tee-Object -Variable logOut | Log-Output -config $config

pwshake/scripts/Invoke-Task.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function global:Invoke-Task {
1111
[bool]$dryRun = $false
1212
)
1313
process {
14-
Log-Output "Invoke task: $($task.name)" $config 6>&1
14+
Log-Output "Invoke task: $($task.name)" $config
1515

1616
if (-not (Invoke-Expression $task.when)) {
1717
Log-Output "`t`tBypassed because of when: [$($task.when)] = $(Invoke-Expression $task.when)" $config

pwshake/scripts/Invoke-pwshake.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ function Invoke-pwshake {
2121
| Override-Attributes `
2222
| Interpolate-Attributes
2323

24-
Log-Output "PWSHAKE config:" $config 6>&1
25-
Log-Output "$(ConvertTo-Yaml $config)" $config 6>&1
24+
Log-Output "PWSHAKE config:" $config
25+
Log-Output "$(ConvertTo-Yaml $config)" $config
2626

2727
$arranged_tasks = Arrange-Tasks $config
28-
Log-Output "Arranged tasks:" $config 6>&1
29-
Log-Output "$(ConvertTo-Yaml $arranged_tasks)" $config 6>&1
28+
Log-Output "Arranged tasks:" $config
29+
Log-Output "$(ConvertTo-Yaml $arranged_tasks)" $config
3030

3131
try {
3232
Push-Location $config.attributes.work_dir

pwshake/scripts/Normalize-Config.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ function Normalize-Config {
1111
attributes_overrides = @() + (Coalesce $config.attributes_overrides, @());
1212
scripts_directories = @() + (Coalesce $config.scripts_directories, @());
1313
tasks = Coalesce $config.tasks, $config.tasks, $config.roles, @{};
14+
templates = Coalesce $config.templates, @{};
1415
invoke_tasks = @() + (Coalesce $config.invoke_tasks, $config.invoke_run_lists, $config.apply_roles, @());
1516
}
1617
}

pwshake/scripts/Normalize-MsBuild.ps1

Lines changed: 0 additions & 30 deletions
This file was deleted.

pwshake/scripts/Normalize-Step.ps1

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function Normalize-Step {
1717
} elseif ($item -is [Hashtable]) {
1818
if ($item.Keys.Length) {
1919
$key = $item.Keys | Select-Object -First 1
20-
$reserved_keys = @('name','script','powershell','cmd','msbuild','when','invoke_tasks','work_dir','on_error')
20+
$reserved_keys = @('name','script','powershell','cmd','template', 'parameters','when','invoke_tasks','work_dir','on_error')
2121
if ((-not ($key -in $reserved_keys)) -and ($item[$key] -is [hashtable])) {
2222
$item = $item[$key]
2323
$item.name = Coalesce $item.name, $key
@@ -29,14 +29,15 @@ function Normalize-Step {
2929

3030
return @{
3131
name = Coalesce $item.name, "step_$([Math]::Abs($item.GetHashCode()))";
32-
script = $item.script;
33-
powershell = Coalesce $item.powershell, $item.pwsh, '';
34-
cmd = Coalesce $item.cmd, $item.shell, '';
35-
msbuild = (Normalize-MsBuild $item.msbuild $config);
3632
when = (Normalize-When $item);
37-
invoke_tasks = Coalesce $item.invoke_tasks, $item.apply_roles, $item.invoke_run_lists, @();
38-
work_dir = Coalesce $item.work_dir, $item.in, '';
33+
work_dir = Coalesce $item.work_dir, $item.in;
3934
on_error = Coalesce $item.on_error, 'throw';
35+
script = $item.script;
36+
powershell = Coalesce $item.powershell, $item.pwsh;
37+
cmd = Coalesce $item.cmd, $item.shell;
38+
invoke_tasks = Coalesce $item.invoke_tasks, $item.apply_roles, $item.invoke_run_lists, @();
39+
template = $item.template;
40+
parameters = Coalesce $item.parameters, @{};
4041
}
4142
}
4243
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
function Normalize-Template {
2+
[CmdletBinding()]
3+
param (
4+
[Parameter(Position = 0, Mandatory = $false)]
5+
[hashtable]$item,
6+
7+
[Parameter(Position = 1, Mandatory = $false)]
8+
[hashtable]$config = @{},
9+
10+
[Parameter(Position = 2, Mandatory = $false)]
11+
[int]$depth = 0
12+
)
13+
process {
14+
$ErrorActionPreference = "Stop"
15+
16+
if ($depth -gt 100) {
17+
throw "Circular reference detected for templates in:`n$(ConvertFrom-Yaml $item)"
18+
}
19+
20+
if (-not $item) { return $null }
21+
22+
$step = Normalize-Step $config.templates[$item.template] $config
23+
$step.parameters = Merge-Hashtables $step.parameters $item.parameters
24+
$parameters = $step.parameters.Clone()
25+
foreach ($param in $parameters.Keys) {
26+
$step = ($step | ConvertTo-Yaml).Replace("[[$param]]", $parameters[$param]) | ConvertFrom-Yaml
27+
}
28+
29+
if ($step.template) {
30+
$step = Normalize-Template $step $config ($depth + 1)
31+
}
32+
33+
return $step
34+
}
35+
}

0 commit comments

Comments
 (0)