зеркало из
1
0
Форкнуть 0

Added github action for arm-ttk tests. Added AzureDevOps pipeline example on building artifacts for ADO pipelines

This commit is contained in:
Harald Solstad Fianbakken 2020-09-09 07:27:51 +02:00
Родитель be1438898b
Коммит 7c582413be
3 изменённых файлов: 233 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,27 @@
FROM mcr.microsoft.com/powershell:latest
LABEL "com.github.actions.name"="arm-ttk"
LABEL "com.github.actions.description"="Checks template with the arm-ttk toolkit"
LABEL version="1.0.0"
LABEL maintainer="Harald S. Fianbakken"
RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y git
RUN git clone https://github.com/Azure/arm-ttk.git
COPY entrypoint.ps1 /entrypoint.ps1
# When used from Github - mounts workspace into :
# /github/workspace
# Build and run locally using
#
# docker image build -t armttk:1.0 .
# Run with mount
# docker run --rm -it armttk:1.0 --mount source=../../,target=/github/workspace -e TemplatesFolder=./src/platform-automation/artifacts/templates
# Start using the Entrypoint file.
ENTRYPOINT [ "pwsh", "/entrypoint.ps1" ]

Просмотреть файл

@ -0,0 +1,64 @@
Import-Module '/arm-ttk/arm-ttk/arm-ttk.psd1'
$params = @{};
if($env:TestsToInclude){
$params.Add("Test", $env:TestsToInclude);
}
if($env:TestsToSkip){
$params.add("Skip", $env:TestsToSkip)
}
if($env:TemplatePath -and -not $env:TemplatesFolder){
$params.Add("TemplatePath", $env:TemplatePath);
}
$testRuns = @();
if($env:TemplatesFolder){
$files = Get-ChildItem -Recurse -filter *.json -path $env:TemplatesFolder -exclude *.parameters.json;
$files | Foreach-object {
$TestResults = Test-AzTemplate @params -TemplatePath $_.FullName;
$testRuns += $TestResults;
}
} else {
$TestResults = Test-AzTemplate @params;
$testRuns += $TestResults;
}
$runs = $testRuns|foreach-object {
@{
"Passed"=$_.Passed;
"Name"=$_.Name;
"Group"=$_.Group;
"FileName"=$_.File.FullPath;
"FileshortName"=$_.File.Name;
"Output" = $_.AllOutput;
}
}
$TestFailures = $runs | Where-Object { -not $_.Passed }
# Write test results to csv file (output path)
if($env:OutputFilePath){
$outputPath = $env:OutputFilePath;
if(!(Test-Path $outputPath)){
[void](New-Item -ItemType File $outputPath -force);
}
$runs|ConvertTo-Csv -Delimiter ';'|Set-Content $outputPath;
}
$runs|Select-Object FileName, Group, Passed, Name, Output;
# Fail github
if ($TestFailures) {
Write-Error "There were $($TestFailures.Count) tests failing - please fix before continuing!"
$TestFailures|Select-Object FileName, Group, Passed, Name, Output;
Write-Error "There were $($TestFailures.Count) tests failing - please fix before continuing!"
exit 1
}
else {
Write-Output "All tests are passing"
exit 0
}

Просмотреть файл

@ -0,0 +1,142 @@
trigger:
- master
stages:
- stage: buildArtifacts
displayName: create artifacts
variables:
artifactsDirectory : "$(Build.ArtifactStagingDirectory)"
bluePrintsFolder : "$(Build.ArtifactStagingDirectory)/Blueprints"
dscFolder : "$(Build.ArtifactStagingDirectory)/Dsc"
pipelinesFolder : "$(Build.ArtifactStagingDirectory)/Pipelines"
scriptsFolder : "$(Build.ArtifactStagingDirectory)/Scripts"
mgTemplatesFolder: "$(Build.ArtifactStagingDirectory)/MgTemplates"
rgTemplatesFolder: "$(Build.ArtifactStagingDirectory)/RgTemplates"
subscriptionTemplatesFolder: "$(Build.ArtifactStagingDirectory)/subscriptionTemplates"
tenantTemplatesFolder: "$(Build.ArtifactStagingDirectory)/tenantTemplates"
templateFolder : "$(Build.ArtifactStagingDirectory)/Templates"
blueprintArtifactName : "Blueprints"
dscArtifactName : "Dsc"
pipelinesArtifactName : "Pipelines"
scriptsArtifactName : "Scripts"
mgTemplatesArtifactName : "ManagementGroup"
rgTemplatesArtifactName : "ResourceGroup"
subscriptionTemplatesArtifactName : "Subscription"
tenantTemplatesArtifactName : "Tenant"
templatesArtifactName : "Templates"
jobs:
- job: buildAndAssembleArtifacts
steps:
- pwsh: |
new-item -itemType Directory $(bluePrintsFolder) -force
new-item -itemType Directory $(dscFolder) -force
new-item -itemType Directory $(pipelinesFolder) -force
new-item -itemType Directory $(scriptsFolder) -force
new-item -itemType Directory $(mgTemplatesFolder) -force
new-item -itemType Directory $(rgTemplatesFolder) -force
new-item -itemType Directory $(subscriptionTemplatesFolder) -force
new-item -itemType Directory $(tenantTemplatesFolder) -force
new-item -itemType Directory $(templateFolder) -force
displayName: Create folders and prep artifacts
enabled: true
- task: CopyFiles@2
displayName: "Copy blueprints"
inputs:
sourceFolder: "$(Build.SourcesDirectory)/src/platform-automation/artifacts/blueprints"
contents: "**"
targetFolder: "$(blueprintsFolder)"
- task: PublishBuildArtifacts@1
inputs:
pathToPublish: $(blueprintsFolder)
artifactName: $(blueprintArtifactName)
- task: CopyFiles@2
displayName: "Copy DSC"
inputs:
sourceFolder: "$(Build.SourcesDirectory)/src/platform-automation/artifacts/dsc"
contents: "**"
targetFolder: "$(dscFolder)"
- task: PublishBuildArtifacts@1
inputs:
pathToPublish: $(dscFolder)
artifactName: $(dscArtifactName)
- task: CopyFiles@2
displayName: "Copy pipelines"
inputs:
sourceFolder: "$(Build.SourcesDirectory)/src/platform-automation/artifacts/pipelines"
contents: "**"
targetFolder: "$(pipelinesFolder)"
- task: PublishBuildArtifacts@1
inputs:
pathToPublish: $(pipelinesFolder)
artifactName: $(pipelinesArtifactName)
- task: CopyFiles@2
displayName: Copy Scripts
inputs:
sourceFolder: "$(Build.SourcesDirectory)/src/platform-automation/artifacts/scripts"
contents: "**"
targetFolder: "$(scriptsFolder)"
- task: PublishBuildArtifacts@1
inputs:
pathToPublish: $(scriptsFolder)
artifactName: $(scriptsArtifactName)
- task: CopyFiles@2
displayName: Copy MG templates
inputs:
sourceFolder: "$(Build.SourcesDirectory)/src/platform-automation/artifacts/templates/managementgroup"
contents: "**"
targetFolder: "$(mgTemplatesFolder)"
- task: PublishBuildArtifacts@1
inputs:
pathToPublish: $(mgTemplatesFolder)
artifactName: $(mgTemplatesArtifactName)
- task: CopyFiles@2
displayName: Copy RG templates
inputs:
sourceFolder: "$(Build.SourcesDirectory)/src/platform-automation/artifacts/templates/resourcegroup"
contents: "**"
targetFolder: "$(rgTemplatesFolder)"
- task: PublishBuildArtifacts@1
inputs:
pathToPublish: $(rgTemplatesFolder)
artifactName: $(rgTemplatesArtifactName)
- task: CopyFiles@2
displayName: Copy subscription templates
inputs:
sourceFolder: "$(Build.SourcesDirectory)/src/platform-automation/artifacts/templates/subscription"
contents: "**"
targetFolder: "$(subscriptionTemplatesFolder)"
- task: PublishBuildArtifacts@1
inputs:
pathToPublish: $(subscriptionTemplatesFolder)
artifactName: $(subscriptionTemplatesArtifactName)
- task: CopyFiles@2
displayName: Copy tenant templates
inputs:
sourceFolder: "$(Build.SourcesDirectory)/src/platform-automation/artifacts/templates/tenant"
contents: "**"
targetFolder: "$(tenantTemplatesFolder)"
- task: PublishBuildArtifacts@1
inputs:
pathToPublish: $(tenantTemplatesFolder)
artifactName: $(tenantTemplatesArtifactName)
- task: CopyFiles@2
displayName: Copy all templates
inputs:
sourceFolder: "$(Build.SourcesDirectory)/src/platform-automation/artifacts/templates/tenant"
contents: "**"
targetFolder: "$(templatesFolder)"
- task: PublishBuildArtifacts@1
inputs:
pathToPublish: $(templatesFolder)
artifactName: $(templatesArtifactName)