Skip to content

Commit 4664eb7

Browse files
tsteenbakkersTobi Steenbakkers
andauthored
First Master version (#2)
* initialize code * cleansing comments * psdupdates * changed path * added actual details to build / release defition when lisitng * also added .value property to release definitions * adding checks to prevent unneeded calls * adding functionality to include previews in deciding highestversion * enabled searching for a specific version for TG ID Search * taking into account nested tg version drafts and preview * gitignore * adding refName to excluded * readability * adding empty placeholder for build * adding BuildNumber format from BD * adding a first iteration of readme * updated docs * added more documentation * adding schedules for Build Definition conversion (#1) * adding priv function get-cronfromschedule * add caller, cleanup comments, DST corrections & debugging dayshift * adding prot from empty properties and added schedules * updated documentation * cleansing * empty placegolder to identify folder in git * added schedules assumption * modding verbose msg for secrets * small additions to readme * Adding Set-AzDOAPIToolsConfig function and changes to existing files to make it work * returning profile after creating one * PSScriptanalyzer errors * adding possibility to overwrite existing profile * single out-file command * splitting configfilepath and filename for custom out-file function * Revert "splitting configfilepath and filename for custom out-file function" This reverts commit 2c49401. * fixed bug jobcount = 1 & custom pool no output * adding separate function to output as YAML * renaming functions and adding outputting as file optional * moving functions to private * renaming functions * rename Get-AzDOAPIToolsDefinitionsTaskGroupsByID * fixing caps * rename convert function * casing * renaming * renaming * renaming * renaming var function * proper renaming internal function Convert-TaskIDToYAMLTaskIdentifier * renaming internalfunction Convert-TaskStepsToYAMLSteps * forgot to rename function itself * renaming internal function Convert-TGInputsToYamlTemplateInputs * renaming internal function Get-DefinitionInputIncludeExclude * renaming internal functions Get-AzdoAPIURL * renaming internal functions Get-Confirmation * renaming internal functions Use-AzDoAPI * fixing MD Markup problems * adding badges * names * docs update * adding skeletons for unit tests and markdown files * added summarized explanation for each public function * ignoring local VSCode settings * updating main readme * expanding on main functionality * moar info * tags * adding documentation on build definitions * updating local PSD files with new function names to export * updating project names * documentation on seperate functions * Finishing documentation on conversion * pester part * updated title * started adding example conversions * finishing examples * fixing images * fixing the rest of the image links * image captions * captions * test * formatting * formatting * updating task group examples * generated help Markdown files with PlatyPS * Added first PlatyPS file with content * updated specific function documentation * update re-added aliasses * typo in functionname * missed a function * adding new experimental build & deploy files * finishing Build Scripts * adding doc generation to build script * build scripts overhaul * pipeline * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * updating module dependancies * pester v5 * renamed test files, update pipeline for using win2016 and adding testroot * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * Update azure-pipelines.yml for Azure Pipelines * test publish to psgallery * updating paths * status badge * nugetapikey * mapping apikey and reverting apikeyname * changes to docs * updating triggers * fixing path * paths Co-authored-by: Tobi Steenbakkers <tobi.steenbakkers@rabobank.com>
1 parent e18a6c2 commit 4664eb7

94 files changed

Lines changed: 4132 additions & 1 deletion

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
BuildOutput/
3+
4+
Config/config.json
5+
6+
Manual_test_script.ps1
7+
8+
Test-results.xml
9+
10+
testscriptdefinitions.ps1
11+
12+
snippets.ps1
13+
14+
.vscode/settings.json

AzDoAPITools.PSDeploy.ps1

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Deploy Module {
2+
By PSGalleryModule {
3+
FromSource AzDoAPITools
4+
To PSGallery
5+
WithOptions @{
6+
7+
ApiKey = $ENV:PSGalleryKey
8+
}
9+
}
10+
}

AzdoAPITools.build.ps1

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
#requires -Modules InvokeBuild, Buildhelpers, PSScriptAnalyzer, Pester, PSDeploy, PlatyPS
2+
3+
$script:ModuleName = 'AzdoAPITools'
4+
$Script:Author = 'Tobi Steenbakkers'
5+
$Script:CompanyName = 'Continuous Data'
6+
$script:Source = Join-Path $BuildRoot Source
7+
$script:Output = Join-Path $BuildRoot BuildOutput
8+
$script:DocPath = Join-Path $BuildRoot "docs\functions"
9+
$script:TestRoot = Join-Path $BuildRoot 'Tests\Unit'
10+
$script:Destination = Join-Path $Output $ModuleName
11+
$script:ModulePath = "$Destination\$ModuleName.psm1"
12+
$script:ManifestPath = "$Destination\$ModuleName.psd1"
13+
$script:Imports = ( 'Private','Public' )
14+
15+
task Default Clean, Build, AnalyzeErrors, Pester
16+
task Build ModuleBuild, DocBuild
17+
task Pester {ImportModule}, Test, {uninstall}
18+
Task UpdateDocs {ImportModule}, CreateUpdateDocs, {uninstall}
19+
20+
task Local Default, UpdateSource, UpdateDocs
21+
task CICD Default, UpdateVersion, {Uninstall}
22+
23+
Task Clean {
24+
If(Get-Module $moduleName){
25+
Remove-Module $moduleName
26+
}
27+
If(Test-Path $Output){
28+
$null = Remove-Item $Output -Recurse -ErrorAction Ignore
29+
}
30+
}
31+
32+
task AnalyzeErrors {
33+
$scriptAnalyzerParams = @{
34+
Path = $Destination
35+
Severity = @('Error')
36+
Recurse = $true
37+
Verbose = $false
38+
#ExcludeRule = 'PSUseDeclaredVarsMoreThanAssignments'
39+
}
40+
41+
$saResults = Invoke-ScriptAnalyzer @scriptAnalyzerParams
42+
43+
if ($saResults) {
44+
$saResults | Format-Table
45+
throw "One or more PSScriptAnalyzer errors/warnings where found."
46+
}
47+
}
48+
49+
task Analyze {
50+
$scriptAnalyzerParams = @{
51+
Path = $Destination
52+
Severity = @('Warning','Error')
53+
Recurse = $true
54+
Verbose = $false
55+
#ExcludeRule = 'PSUseDeclaredVarsMoreThanAssignments'
56+
}
57+
58+
$saResults = Invoke-ScriptAnalyzer @scriptAnalyzerParams
59+
60+
if ($saResults) {
61+
$saResults | Format-Table
62+
throw "One or more PSScriptAnalyzer errors/warnings where found."
63+
}
64+
}
65+
66+
task Test {
67+
68+
$invokePesterParams = @{
69+
Passthru = $true
70+
Verbose = $false
71+
EnableExit = $true
72+
OutputFile = 'Test-results.xml'
73+
OutputFormat = 'NunitXML'
74+
Path = $script:TestRoot
75+
}
76+
77+
$testResults = Invoke-Pester @invokePesterParams
78+
79+
$numberFails = $testResults.FailedCount
80+
assert($numberFails -eq 0) ('Failed "{0}" unit tests.' -f $numberFails)
81+
}
82+
83+
task UpdateVersion {
84+
try
85+
{
86+
#$moduleManifestFile = ((($ManifestPath -split '\\')[-1] -split '\.')[0]+'.psd1')
87+
$manifestContent = Get-Content $ManifestPath -Raw
88+
[version]$version = [regex]::matches($manifestContent,"ModuleVersion\s=\s\'(?<version>(\d+\.)?(\d+\.)?(\*|\d+))") | ForEach-Object {$_.groups['version'].value}
89+
$newVersion = "{0}.{1}.{2}" -f $version.Major, $version.Minor, $ENV:Build_BuildID
90+
91+
$replacements = @{
92+
"ModuleVersion = '.*'" = "ModuleVersion = '$newVersion'"
93+
}
94+
95+
$replacements.GetEnumerator() | ForEach-Object {
96+
$manifestContent = $manifestContent -replace $_.Key,$_.Value
97+
}
98+
99+
$manifestContent | Set-Content -Path "$ManifestPath"
100+
}
101+
catch
102+
{
103+
Write-Error -Message $_.Exception.Message
104+
$host.SetShouldExit($LastExitCode)
105+
}
106+
}
107+
108+
Task UpdateSource {
109+
Copy-Item $ManifestPath -Destination "$source\$ModuleName.psd1"
110+
}
111+
112+
Function ImportModule {
113+
if ( -Not ( Test-Path $ManifestPath ) )
114+
{
115+
" Modue [$ModuleName] is not built, cannot find [$ManifestPath]"
116+
Write-Error "Could not find module manifest [$ManifestPath]. You may need to build the module first"
117+
}
118+
else
119+
{
120+
if (Get-Module $ModuleName)
121+
{
122+
" Unloading Module [$ModuleName] from previous import"
123+
Remove-Module $ModuleName
124+
}
125+
" Importing Module [$ModuleName] from [$ManifestPath]"
126+
Import-Module $ManifestPath -Force
127+
}
128+
}
129+
130+
function Uninstall {
131+
'Unloading Modules...'
132+
Get-Module -Name $ModuleName -ErrorAction 'Ignore' | Remove-Module
133+
134+
'Uninstalling Module packages...'
135+
$modules = Get-Module $ModuleName -ErrorAction 'Ignore' -ListAvailable
136+
foreach ($module in $modules)
137+
{
138+
Uninstall-Module -Name $module.Name -RequiredVersion $module.Version -ErrorAction 'Ignore'
139+
}
140+
141+
'Cleaning up manually installed Modules...'
142+
$path = $env:PSModulePath.Split(';').Where( {
143+
$_ -like 'C:\Users\*'
144+
}, 'First', 1)
145+
146+
$path = Join-Path -Path $path -ChildPath $ModuleName
147+
if ($path -and (Test-Path -Path $path))
148+
{
149+
'Removing files... (This may fail if any DLLs are in use.)'
150+
Get-ChildItem -Path $path -File -Recurse |
151+
Remove-Item -Force | ForEach-Object 'FullName'
152+
153+
'Removing folders... (This may fail if any DLLs are in use.)'
154+
Remove-Item $path -Recurse -Force
155+
}
156+
}
157+
158+
task Publish {
159+
Invoke-PSDeploy -Path $PSScriptRoot -Force
160+
}
161+
162+
Task DocBuild {
163+
New-ExternalHelp $DocPath -OutputPath "$destination\EN-US"
164+
}
165+
166+
Task CreateUpdateDocs {
167+
168+
If(-not (Test-Path $DocPath)){
169+
"Creating Documents path: $DocPath"
170+
$null = New-Item -Type Directory -Path $DocPath -ErrorAction Ignore
171+
}
172+
173+
"Creating new markdown files if any"
174+
New-MarkdownHelp -Module $modulename -OutputFolder $docpath -ErrorAction SilentlyContinue
175+
"Updating existing markdown files"
176+
Update-MarkdownHelp $docpath
177+
178+
}
179+
180+
task ModuleBuild {
181+
$pubFiles = Get-ChildItem "$Source\public" -Filter *.ps1 -File
182+
$privFiles = Get-ChildItem "$Source\private" -Filter *.ps1 -File
183+
If(-not(Test-Path $Destination)){
184+
New-Item $destination -ItemType Directory
185+
}
186+
ForEach($file in ($pubFiles + $privFiles)) {
187+
Get-Content $file.FullName | Out-File "$destination\$moduleName.psm1" -Append -Encoding utf8
188+
}
189+
Copy-Item "$Source\$moduleName.psd1" -Destination $destination
190+
191+
$moduleManifestData = @{
192+
Author = $author
193+
Copyright = "(c) $((get-date).Year) $companyname. All rights reserved."
194+
Path = "$destination\$moduleName.psd1"
195+
FunctionsToExport = $pubFiles.BaseName
196+
RootModule = "$moduleName.psm1"
197+
ProjectUri = "https://github.com/Continuous-Data/$modulename"
198+
}
199+
Update-ModuleManifest @moduleManifestData
200+
}

Config/config-example.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"profiles":[
3+
{
4+
"profilename": "",
5+
"Organization": "",
6+
"pat": ""
7+
}
8+
]
9+
}

README.md

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,64 @@
1-
AzDoAPITools
1+
# AzDoAPITools
2+
3+
[![Build Status](https://dev.azure.com/ContinuousData/cdtestproject/_apis/build/status/tsteenbakkers.AzDoAPITools?branchName=master)](https://dev.azure.com/ContinuousData/cdtestproject/_build/latest?definitionId=4&branchName=master)
4+
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/Continuous-Data/AzDoAPITools/blob/master/LICENSE)
5+
[![Documentation - AzDoAPITools](https://img.shields.io/badge/Documentation-AzDoAPITools-blue.svg)](https://github.com/Continuous-Data/AzDoAPITools/blob/master/docs/readme.md)
6+
[![PowerShell Gallery - AzDoAPITools](https://img.shields.io/badge/PowerShell%20Gallery-AzDoAPITools-blue.svg)](https://www.powershellgallery.com/packages/AzDoAPITools)
7+
[![Minimum Supported PowerShell Version](https://img.shields.io/badge/PowerShell-5.1-blue.svg)](https://github.com/PowerShell/PowerShell)
8+
9+
## Introduction
10+
11+
AzDoAPITools is a project which was born when doing a migration from classical pipelines to YAML pipelines for a customer. Which is the current function of the published module. The module will convert Task Groups and classical build pipelines to usable all in one YAML pipelines / step templates.
12+
13+
In the future you can expect other automations which i have done for customers such as automatic branching / mass policy application etc. to be bundled in this module.
14+
15+
## Requirements
16+
17+
- Powershell 5.1
18+
19+
## Module Dependancies
20+
21+
[Powershell-YAML](https://www.powershellgallery.com/packages/powershell-yaml) is required if you want to create \*.yml files with this Module. The module is capable of delivering a PSObject with all YAML components inside found in your Task Group / Definition if you wish to use a different convert to YAML tool.
22+
23+
## installation
24+
25+
Install this module from the [Powershell Gallery](https://www.powershellgallery.com/packages/AzdoAPITools) or by performing `Install-Module -Name AzdoAPITools`
26+
27+
## First Time use
28+
29+
Run Set-AzDOAPIToolsConfig to create a config.json file which is stored inside the %APPData%\AzDoAPITools folder. Don't sweat if you forget this step. The module will prompt you if it does not find a configfile.
30+
31+
## Documentation
32+
33+
You can find generic documentation [here](/docs/README.md) or check specific functionality documentation below.
34+
35+
## Functionality
36+
37+
- [Convert Classical (GUI) Pipelines to YAML Pipelines](/docs/classic-to-yaml-conversion.md)
38+
- [Convert Task Groups to YAML Templates](/docs/classic-to-yaml-conversion.md)
39+
- Retrieve a list of names of Build / Release Definitions & Task Groups
40+
- Retrieve details of Build / Release Definitions & Task Groups based of (a list of) names
41+
- Filter Task Groups API to return highest / draft / preview of a Task Group
42+
43+
## How to Build local
44+
45+
- Download Source code / Clone repo
46+
- Run Invoke-Build from the modules root directory
47+
- You will need the following modules in order to use Invoke-Build:
48+
- InvokeBuild
49+
- Buildhelpers
50+
- PSScriptAnalyzer
51+
- Pester
52+
- PSDeploy
53+
- PlatyPS
54+
- Load the module from the BuildOutput folder
55+
56+
## Pester Tests
57+
58+
Currently only placeholders have been made for each function. Tests were done on my personal Azure DevOps Instance and verified by using the actual converted pipelines to see how they work.
59+
60+
I need to gain more knowledge on Pester Tests and especially on how to mock the REST API calls. Tests will be added when I have this knowledged and time to create tests.
61+
62+
## License
63+
64+
This project is licensed under the [MIT License](https://github.com/tsteenbakkers/AzDoAPITools/blob/master/LICENSE.md)

0 commit comments

Comments
 (0)