Skip to content

Commit

Permalink
First Master version (#2)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
tsteenbakkers and Tobi Steenbakkers authored Sep 17, 2020
1 parent e18a6c2 commit 4664eb7
Show file tree
Hide file tree
Showing 94 changed files with 4,132 additions and 1 deletion.
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

BuildOutput/

Config/config.json

Manual_test_script.ps1

Test-results.xml

testscriptdefinitions.ps1

snippets.ps1

.vscode/settings.json
10 changes: 10 additions & 0 deletions AzDoAPITools.PSDeploy.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Deploy Module {
By PSGalleryModule {
FromSource AzDoAPITools
To PSGallery
WithOptions @{

ApiKey = $ENV:PSGalleryKey
}
}
}
200 changes: 200 additions & 0 deletions AzdoAPITools.build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
#requires -Modules InvokeBuild, Buildhelpers, PSScriptAnalyzer, Pester, PSDeploy, PlatyPS

$script:ModuleName = 'AzdoAPITools'
$Script:Author = 'Tobi Steenbakkers'
$Script:CompanyName = 'Continuous Data'
$script:Source = Join-Path $BuildRoot Source
$script:Output = Join-Path $BuildRoot BuildOutput
$script:DocPath = Join-Path $BuildRoot "docs\functions"
$script:TestRoot = Join-Path $BuildRoot 'Tests\Unit'
$script:Destination = Join-Path $Output $ModuleName
$script:ModulePath = "$Destination\$ModuleName.psm1"
$script:ManifestPath = "$Destination\$ModuleName.psd1"
$script:Imports = ( 'Private','Public' )

task Default Clean, Build, AnalyzeErrors, Pester
task Build ModuleBuild, DocBuild
task Pester {ImportModule}, Test, {uninstall}
Task UpdateDocs {ImportModule}, CreateUpdateDocs, {uninstall}

task Local Default, UpdateSource, UpdateDocs
task CICD Default, UpdateVersion, {Uninstall}

Task Clean {
If(Get-Module $moduleName){
Remove-Module $moduleName
}
If(Test-Path $Output){
$null = Remove-Item $Output -Recurse -ErrorAction Ignore
}
}

task AnalyzeErrors {
$scriptAnalyzerParams = @{
Path = $Destination
Severity = @('Error')
Recurse = $true
Verbose = $false
#ExcludeRule = 'PSUseDeclaredVarsMoreThanAssignments'
}

$saResults = Invoke-ScriptAnalyzer @scriptAnalyzerParams

if ($saResults) {
$saResults | Format-Table
throw "One or more PSScriptAnalyzer errors/warnings where found."
}
}

task Analyze {
$scriptAnalyzerParams = @{
Path = $Destination
Severity = @('Warning','Error')
Recurse = $true
Verbose = $false
#ExcludeRule = 'PSUseDeclaredVarsMoreThanAssignments'
}

$saResults = Invoke-ScriptAnalyzer @scriptAnalyzerParams

if ($saResults) {
$saResults | Format-Table
throw "One or more PSScriptAnalyzer errors/warnings where found."
}
}

task Test {

$invokePesterParams = @{
Passthru = $true
Verbose = $false
EnableExit = $true
OutputFile = 'Test-results.xml'
OutputFormat = 'NunitXML'
Path = $script:TestRoot
}

$testResults = Invoke-Pester @invokePesterParams

$numberFails = $testResults.FailedCount
assert($numberFails -eq 0) ('Failed "{0}" unit tests.' -f $numberFails)
}

task UpdateVersion {
try
{
#$moduleManifestFile = ((($ManifestPath -split '\\')[-1] -split '\.')[0]+'.psd1')
$manifestContent = Get-Content $ManifestPath -Raw
[version]$version = [regex]::matches($manifestContent,"ModuleVersion\s=\s\'(?<version>(\d+\.)?(\d+\.)?(\*|\d+))") | ForEach-Object {$_.groups['version'].value}
$newVersion = "{0}.{1}.{2}" -f $version.Major, $version.Minor, $ENV:Build_BuildID

$replacements = @{
"ModuleVersion = '.*'" = "ModuleVersion = '$newVersion'"
}

$replacements.GetEnumerator() | ForEach-Object {
$manifestContent = $manifestContent -replace $_.Key,$_.Value
}

$manifestContent | Set-Content -Path "$ManifestPath"
}
catch
{
Write-Error -Message $_.Exception.Message
$host.SetShouldExit($LastExitCode)
}
}

Task UpdateSource {
Copy-Item $ManifestPath -Destination "$source\$ModuleName.psd1"
}

Function ImportModule {
if ( -Not ( Test-Path $ManifestPath ) )
{
" Modue [$ModuleName] is not built, cannot find [$ManifestPath]"
Write-Error "Could not find module manifest [$ManifestPath]. You may need to build the module first"
}
else
{
if (Get-Module $ModuleName)
{
" Unloading Module [$ModuleName] from previous import"
Remove-Module $ModuleName
}
" Importing Module [$ModuleName] from [$ManifestPath]"
Import-Module $ManifestPath -Force
}
}

function Uninstall {
'Unloading Modules...'
Get-Module -Name $ModuleName -ErrorAction 'Ignore' | Remove-Module

'Uninstalling Module packages...'
$modules = Get-Module $ModuleName -ErrorAction 'Ignore' -ListAvailable
foreach ($module in $modules)
{
Uninstall-Module -Name $module.Name -RequiredVersion $module.Version -ErrorAction 'Ignore'
}

'Cleaning up manually installed Modules...'
$path = $env:PSModulePath.Split(';').Where( {
$_ -like 'C:\Users\*'
}, 'First', 1)

$path = Join-Path -Path $path -ChildPath $ModuleName
if ($path -and (Test-Path -Path $path))
{
'Removing files... (This may fail if any DLLs are in use.)'
Get-ChildItem -Path $path -File -Recurse |
Remove-Item -Force | ForEach-Object 'FullName'

'Removing folders... (This may fail if any DLLs are in use.)'
Remove-Item $path -Recurse -Force
}
}

task Publish {
Invoke-PSDeploy -Path $PSScriptRoot -Force
}

Task DocBuild {
New-ExternalHelp $DocPath -OutputPath "$destination\EN-US"
}

Task CreateUpdateDocs {

If(-not (Test-Path $DocPath)){
"Creating Documents path: $DocPath"
$null = New-Item -Type Directory -Path $DocPath -ErrorAction Ignore
}

"Creating new markdown files if any"
New-MarkdownHelp -Module $modulename -OutputFolder $docpath -ErrorAction SilentlyContinue
"Updating existing markdown files"
Update-MarkdownHelp $docpath

}

task ModuleBuild {
$pubFiles = Get-ChildItem "$Source\public" -Filter *.ps1 -File
$privFiles = Get-ChildItem "$Source\private" -Filter *.ps1 -File
If(-not(Test-Path $Destination)){
New-Item $destination -ItemType Directory
}
ForEach($file in ($pubFiles + $privFiles)) {
Get-Content $file.FullName | Out-File "$destination\$moduleName.psm1" -Append -Encoding utf8
}
Copy-Item "$Source\$moduleName.psd1" -Destination $destination

$moduleManifestData = @{
Author = $author
Copyright = "(c) $((get-date).Year) $companyname. All rights reserved."
Path = "$destination\$moduleName.psd1"
FunctionsToExport = $pubFiles.BaseName
RootModule = "$moduleName.psm1"
ProjectUri = "https://github.com/Continuous-Data/$modulename"
}
Update-ModuleManifest @moduleManifestData
}
9 changes: 9 additions & 0 deletions Config/config-example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"profiles":[
{
"profilename": "",
"Organization": "",
"pat": ""
}
]
}
65 changes: 64 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,64 @@
AzDoAPITools
# AzDoAPITools

[![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)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/Continuous-Data/AzDoAPITools/blob/master/LICENSE)
[![Documentation - AzDoAPITools](https://img.shields.io/badge/Documentation-AzDoAPITools-blue.svg)](https://github.com/Continuous-Data/AzDoAPITools/blob/master/docs/readme.md)
[![PowerShell Gallery - AzDoAPITools](https://img.shields.io/badge/PowerShell%20Gallery-AzDoAPITools-blue.svg)](https://www.powershellgallery.com/packages/AzDoAPITools)
[![Minimum Supported PowerShell Version](https://img.shields.io/badge/PowerShell-5.1-blue.svg)](https://github.com/PowerShell/PowerShell)

## Introduction

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.

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.

## Requirements

- Powershell 5.1

## Module Dependancies

[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.

## installation

Install this module from the [Powershell Gallery](https://www.powershellgallery.com/packages/AzdoAPITools) or by performing `Install-Module -Name AzdoAPITools`

## First Time use

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.

## Documentation

You can find generic documentation [here](/docs/README.md) or check specific functionality documentation below.

## Functionality

- [Convert Classical (GUI) Pipelines to YAML Pipelines](/docs/classic-to-yaml-conversion.md)
- [Convert Task Groups to YAML Templates](/docs/classic-to-yaml-conversion.md)
- Retrieve a list of names of Build / Release Definitions & Task Groups
- Retrieve details of Build / Release Definitions & Task Groups based of (a list of) names
- Filter Task Groups API to return highest / draft / preview of a Task Group

## How to Build local

- Download Source code / Clone repo
- Run Invoke-Build from the modules root directory
- You will need the following modules in order to use Invoke-Build:
- InvokeBuild
- Buildhelpers
- PSScriptAnalyzer
- Pester
- PSDeploy
- PlatyPS
- Load the module from the BuildOutput folder

## Pester Tests

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.

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.

## License

This project is licensed under the [MIT License](https://github.com/tsteenbakkers/AzDoAPITools/blob/master/LICENSE.md)
Loading

0 comments on commit 4664eb7

Please sign in to comment.