Skip to content

Commit

Permalink
Added build pipeline (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
BernieWhite authored Dec 1, 2020
1 parent 93a0898 commit 6004255
Show file tree
Hide file tree
Showing 12 changed files with 698 additions and 7 deletions.
193 changes: 193 additions & 0 deletions .azure-pipelines/azure-pipelines.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
# Azure DevOps
# CI pipeline for PSDocs.Azure

variables:
version: '0.1.0'
buildConfiguration: 'Release'
disable.coverage.autogenerate: 'true'
imageName: 'ubuntu-18.04'

# Use build number format, i.e. 0.18.0-B2008001
name: $(version)-B$(date:yyMM)$(rev:rrr)

trigger:
branches:
include:
- 'main'
tags:
include:
- 'v0.*'

pr:
branches:
include:
- 'main'

stages:

# Build pipeline
- stage: Build
displayName: Build
dependsOn: []
jobs:
- job:
pool:
vmImage: $(imageName)
displayName: 'Module'
steps:

# Install pipeline dependencies
- powershell: ./.azure-pipelines/pipeline-deps.ps1
displayName: 'Install dependencies'

# Build module
- powershell: Invoke-Build -Configuration $(buildConfiguration) -Build $(Build.BuildNumber)
displayName: 'Build module'

# DotNet test results
- task: PublishTestResults@2
displayName: 'Publish unit test results'
inputs:
testRunTitle: 'DotNet on $(imageName)'
testRunner: VSTest
testResultsFiles: 'reports/*.trx'
mergeTestResults: true
platform: $(imageName)
configuration: $(buildConfiguration)
publishRunAttachments: true
condition: succeededOrFailed()

# PSRule results
- task: PublishTestResults@2
displayName: 'Publish PSRule results'
inputs:
testRunTitle: 'PSRule on $(imageName)'
testRunner: NUnit
testResultsFiles: 'reports/ps-rule*.xml'
mergeTestResults: true
platform: $(imageName)
configuration: $(buildConfiguration)
publishRunAttachments: true
condition: succeededOrFailed()

# Generate artifacts
- publish: out/modules/PSDocs.Azure
displayName: 'Publish module'
artifact: PSDocs.Azure

# Analysis pipeline
- stage: Analysis
displayName: Analysis
dependsOn: []
variables:
skipComponentGovernanceDetection: true
jobs:

- job: Secret_Scan
pool: 'Hosted VS2017'
displayName: Secret scan
steps:
- task: securedevelopmentteam.vss-secure-development-tools.build-task-credscan.CredScan@2
displayName: 'Scan for secrets'
inputs:
debugMode: false
toolMajorVersion: V2

- task: securedevelopmentteam.vss-secure-development-tools.build-task-publishsecurityanalysislogs.PublishSecurityAnalysisLogs@2
displayName: 'Publish scan logs'
continueOnError: true

- task: securedevelopmentteam.vss-secure-development-tools.build-task-postanalysis.PostAnalysis@1
displayName: 'Check for failures'
inputs:
CredScan: true
ToolLogsNotFoundAction: Error

# Test pipeline
- stage: Test
dependsOn: Build
jobs:

- template: jobs/test.yaml
parameters:
name: ubuntu_18_04_coverage
imageName: 'ubuntu-18.04'
displayName: 'PowerShell coverage'
coverage: 'true'
publishResults: 'false'

- template: jobs/test.yaml
parameters:
name: macOS_10_15
displayName: 'PowerShell 7.0 - macOS-10.15'
imageName: 'macOS-10.15'

- template: jobs/test.yaml
parameters:
name: windows
displayName: 'PowerShell 5.1 - win2016'
imageName: 'vs2017-win2016'

- template: jobs/testContainer.yaml
parameters:
name: ps_7_ubuntu_18_04
displayName: 'PowerShell 7.0 - ubuntu-18.04'
imageName: mcr.microsoft.com/powershell
imageTag: 7.0.3-ubuntu-18.04

- template: jobs/testContainer.yaml
parameters:
name: ps_7_1_ubuntu_18_04
displayName: 'PowerShell 7.1 - ubuntu-18.04'
imageName: mcr.microsoft.com/powershell
imageTag: 7.1.0-ubuntu-18.04

- template: jobs/testContainer.yaml
parameters:
name: ps_6_ubuntu_18_04
displayName: 'PowerShell 6.2 - ubuntu-18.04'
imageName: mcr.microsoft.com/powershell
imageTag: 6.2.4-ubuntu-18.04

# Release pipeline
- stage: Release
displayName: Release
dependsOn: [ 'Test', 'Analysis' ]
condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags/v0.'))
jobs:
- job:
displayName: Live
pool:
vmImage: $(imageName)
variables:
isPreRelease: $[contains(variables['Build.SourceBranchName'], '-B')]
steps:

# Download module from build
- task: DownloadPipelineArtifact@2
displayName: 'Download module'
inputs:
artifact: PSDocs.Azure
path: $(Build.SourcesDirectory)/out/modules/PSDocs.Azure

# Install pipeline dependencies
- powershell: ./.azure-pipelines/pipeline-deps.ps1
displayName: 'Install dependencies'

# Install pipeline dependencies and build module
- powershell: Invoke-Build Release -ApiKey $(apiKey)
displayName: 'Publish module'

# Update GitHub release
- task: GitHubRelease@1
displayName: 'GitHub release'
inputs:
gitHubConnection: 'AzureDevOps-PSDocs.Azure'
repositoryName: '$(Build.Repository.Name)'
action: edit
tag: '$(Build.SourceBranchName)'
releaseNotesSource: inline
releaseNotesInline: 'See [change log](https://github.com/Azure/PSDocs.Azure/blob/main/CHANGELOG.md)'
assetUploadMode: replace
addChangeLog: false
isPreRelease: $(isPreRelease)
71 changes: 71 additions & 0 deletions .azure-pipelines/jobs/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Azure DevOps
# CI job for running VM pipelines

parameters:
name: ''
displayName: ''
buildConfiguration: 'Release'
imageName: ''
coverage: 'false'
publishResults: 'true'

jobs:
- job: ${{ parameters.name }}
displayName: ${{ parameters.displayName }}
pool:
vmImage: ${{ parameters.imageName }}
variables:
COVERAGE: ${{ parameters.coverage }}
PUBLISHRESULTS: ${{ parameters.publishResults }}
skipComponentGovernanceDetection: true
steps:

# Install pipeline dependencies
- powershell: ./.azure-pipelines/pipeline-deps.ps1
displayName: 'Install dependencies'

# Download module
- task: DownloadPipelineArtifact@2
displayName: 'Download module'
inputs:
artifact: PSDocs.Azure
path: $(Build.SourcesDirectory)/out/modules/PSDocs.Azure

# Build module
- powershell: Invoke-Build TestModule -Configuration ${{ parameters.buildConfiguration }} -Build $(Build.BuildNumber)
env:
COVERAGE: ${{ parameters.coverage }}
displayName: 'Test module'

# Pester test results
- task: PublishTestResults@2
displayName: 'Publish Pester results'
inputs:
testRunTitle: 'Pester on ${{ parameters.imageName }}'
testRunner: NUnit
testResultsFiles: 'reports/pester-unit.xml'
mergeTestResults: true
platform: ${{ parameters.name }}
configuration: ${{ parameters.buildConfiguration }}
publishRunAttachments: true
condition: and(succeededOrFailed(), eq(variables['PUBLISHRESULTS'], 'true'))

# Generate Code Coverage report
- task: Palmmedia.reportgenerator.reportgenerator-build-release-task.reportgenerator@4
displayName: 'Code coverage report generator'
inputs:
reports: 'reports/pester-coverage.xml'
targetdir: 'reports/coverage'
sourcedirs: 'src/PSDocs.Azure'
reporttypes: 'HtmlInline_AzurePipelines;Cobertura;SonarQube;Badges'
tag: $(Build.BuildNumber)
condition: eq(variables['COVERAGE'], 'true')

# Publish Code Coverage report
- task: PublishCodeCoverageResults@1
displayName: 'Publish Pester code coverage'
inputs:
codeCoverageTool: 'Cobertura'
summaryFileLocation: 'reports/coverage/Cobertura.xml'
reportDirectory: 'reports/coverage'
condition: eq(variables['COVERAGE'], 'true')
76 changes: 76 additions & 0 deletions .azure-pipelines/jobs/testContainer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Azure DevOps
# CI job for running container pipelines

parameters:
name: ''
displayName: ''
buildConfiguration: 'Release'
vmImage: 'ubuntu-16.04'
imageName: ''
imageTag: ''
coverage: 'false'
publishResults: 'true'

jobs:
- job: ${{ parameters.name }}
displayName: ${{ parameters.displayName }}
pool:
vmImage: ${{ parameters.vmImage }}
container:
image: '${{ parameters.imageName }}:${{ parameters.imageTag }}'
env:
COVERAGE: ${{ parameters.coverage }}
PUBLISHRESULTS: ${{ parameters.publishResults }}
variables:
COVERAGE: ${{ parameters.coverage }}
PUBLISHRESULTS: ${{ parameters.publishResults }}
skipComponentGovernanceDetection: true
steps:

# Install pipeline dependencies
- powershell: ./.azure-pipelines/pipeline-deps.ps1
displayName: 'Install dependencies'

# Download module
- task: DownloadPipelineArtifact@2
displayName: 'Download module'
inputs:
artifact: PSDocs.Azure
path: $(Build.SourcesDirectory)/out/modules/PSDocs.Azure

# Build module
- powershell: Invoke-Build TestModule -Configuration ${{ parameters.buildConfiguration }} -Build $(Build.BuildNumber)
displayName: 'Test module'

# Pester test results
- task: PublishTestResults@2
displayName: 'Publish Pester results'
inputs:
testRunTitle: 'Pester on ${{ parameters.imageTag }}'
testRunner: NUnit
testResultsFiles: 'reports/pester-unit.xml'
mergeTestResults: true
platform: ${{ parameters.imageTag }}
configuration: ${{ parameters.buildConfiguration }}
publishRunAttachments: true
condition: and(succeededOrFailed(), eq(variables['PUBLISHRESULTS'], 'true'))

# Generate Code Coverage report
- task: Palmmedia.reportgenerator.reportgenerator-build-release-task.reportgenerator@4
displayName: 'Code coverage report generator'
inputs:
reports: 'reports\pester-coverage.xml'
targetdir: 'reports\coverage'
sourcedirs: 'src\PSDocs.Azure'
reporttypes: 'HtmlInline_AzurePipelines;Cobertura;SonarQube;Badges'
tag: $(Build.BuildNumber)
condition: eq(variables['COVERAGE'], 'true')

# Publish Code Coverage report
- task: PublishCodeCoverageResults@1
displayName: 'Publish Pester code coverage'
inputs:
codeCoverageTool: 'Cobertura'
summaryFileLocation: 'reports/coverage/Cobertura.xml'
reportDirectory: 'reports/coverage'
condition: eq(variables['COVERAGE'], 'true')
22 changes: 22 additions & 0 deletions .azure-pipelines/pipeline-deps.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

#
# Install dependencies for integration with Azure DevOps
#

if ($Env:SYSTEM_DEBUG -eq 'true') {
$VerbosePreference = 'Continue';
}

if ($Null -eq (Get-PackageProvider -Name NuGet -ErrorAction Ignore)) {
Install-PackageProvider -Name NuGet -Force -Scope CurrentUser;
}

if ($Null -eq (Get-InstalledModule -Name PowerShellGet -MinimumVersion 2.2.1 -ErrorAction Ignore)) {
Install-Module PowerShellGet -MinimumVersion 2.2.1 -Scope CurrentUser -Force -AllowClobber;
}

if ($Null -eq (Get-InstalledModule -Name InvokeBuild -MinimumVersion 5.4.0 -ErrorAction Ignore)) {
Install-Module InvokeBuild -MinimumVersion 5.4.0 -Scope CurrentUser -Force;
}
5 changes: 0 additions & 5 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,3 @@
- [ ] Summarized changes
- [ ] Change is not breaking
- [ ] This PR is ready to merge and is not **Work in Progress**
- **Rule changes**
- [ ] Unit tests created/ updated
- [ ] Rule documentation created/ updated
- [ ] Link to a filed issue
- [ ] [Change log](https://github.com/Azure/PSDocs.Azure/blob/main/CHANGELOG.md) has been updated with change under unreleased section
Loading

0 comments on commit 6004255

Please sign in to comment.