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

Added Github actions workflows as examples

This commit is contained in:
Harald Solstad Fianbakken 2020-09-09 07:29:12 +02:00
Родитель 0f475849b0
Коммит 7847e9a2e0
14 изменённых файлов: 589 добавлений и 0 удалений

31
.github/workflows/ARM-Custom-Tests.yml поставляемый Normal file
Просмотреть файл

@ -0,0 +1,31 @@
name: ARM - Custom Tests Nunit
on:
push:
paths:
- src/platform-automation/artifacts/**
env:
testRunner: ./src/platform-automation/tests/Templates.tests.ps1
testResultsFile: TestResults.Pester.xml
tempFolder: ../_temp
defaults:
run:
shell: pwsh
jobs:
test_arm_templates:
runs-on: ubuntu-latest
name: Run Custom tests with Nunit
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Run ARM Tests
run: |
$results = ./src/platform-automation/platform-scripts/Run-Tests.ps1 -testName 'ValidateTemplates' -testScriptToRun '${{env.testRunner}}' -testResultsFile '${{env.testResultsFile}}' -verbose
if($results.FailedCount -gt 0){
Write-Output 'There are failed tests - breaking build now'
$failedResults = $results.TestResult|? Result -eq Failed
$failedResults;
exit 1;
}

27
.github/workflows/ARM-TTK-Tests.yml поставляемый Normal file
Просмотреть файл

@ -0,0 +1,27 @@
name: ARM Tests (arm-ttk)
on:
pull_request:
types: [assigned, opened, synchronize, reopened]
branches:
- master
push:
branches:
- master
paths:
- src/platform-automation/artifacts/**
jobs:
test_arm_templates:
runs-on: ubuntu-latest
name: Run ARM TTK tests
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Run ARM Tests
uses: ./Actions/Arm-ttk
id: action
env:
TestsToInclude: ''
TestsToSkip: ''
TemplatesFolder: './src/platform-automation/artifacts/templates/'
OutputFilePath: testRuns/results.csv

34
.github/workflows/Deploy-All-Customer.yml поставляемый Normal file
Просмотреть файл

@ -0,0 +1,34 @@
name: Deploy all customers
on:
pull_request:
types: [closed]
branches:
- master
paths:
- src/platform-automation/customers/**
defaults:
run:
shell: pwsh
env:
storageAccountName: ${{ secrets.AZURE_STORAGE_ACCOUNT_PROD }}
storageAccountKey: ${{ secrets. AZURE_DEPLOYMENT_STORAGE_SAS_PROD }}
lighthouseDeploymentCredential: ${{ secrets.AZURE_SUBSCRIPTION_CREDENTIAL }}
jobs:
deploy-customer:
name: Deploy all customers in one job - To be implemented
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true
steps:
- name: Run script for each customer
run: |
Write-host 'Running script..'
# - name: Run deployment
# run: |
# Get each customer subfolder
# Foreach customer folder -
# run: ./src/platform-automation/platform-scripts/Deploy-Customer.ps1 -

32
.github/workflows/Deploy-Contoso.yml поставляемый Normal file
Просмотреть файл

@ -0,0 +1,32 @@
name: Customer deployment Contoso
on:
pull_request:
types: [closed]
branches:
- master
paths:
- src/platform-automation/cmdb/customers/contoso/*
env:
storageAccountName: ${{ secrets.AZURE_STORAGE_ACCOUNT_PROD }}
storageAccountKey: ${{ secrets. AZURE_DEPLOYMENT_STORAGE_SAS_PROD }}
customerDeploymentCredential: ${{ secrets.AZURE_CONTOSO_CREDENTIAL }}
defaults:
run:
shell: pwsh
jobs:
deploy-customer:
name: Deploy Contoso with all it's glory
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Login to Azure with Powershell
run: ./src/platform-automation/platform-scripts/Login-WithSecretString.ps1 -secretJson '${{ env.customerDeploymentCredential }}' -verbose
- name: Run deployment with verbose output
run: ./src/platform-automation/platform-scripts/Deploy-Customer.ps1 -customer "contoso" -storageAccountName '${{ env.storageAccountName }}' -storageAccountKey '${{ env.storageAccountKey }}' -verbose

32
.github/workflows/Depoly-Fabrikam.yml поставляемый Normal file
Просмотреть файл

@ -0,0 +1,32 @@
name: Customer deployment Fabrikam
on:
pull_request:
types: [closed]
branches:
- master
paths:
- src/platform-automation/cmdb/customers/fabrikam/*
env:
storageAccountName: ${{ secrets.AZURE_STORAGE_ACCOUNT_PROD }}
storageAccountKey: ${{ secrets. AZURE_DEPLOYMENT_STORAGE_SAS_PROD }}
customerDeploymentCredential: ${{ secrets.AZURE_FABRIKAM_CREDENTIAL }}
defaults:
run:
shell: pwsh
jobs:
deploy-customer:
name: Deploy Fabrikam with all it's glory
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Login to Azure with Powershell
run: ./src/platform-automation/platform-scripts/Login-WithSecretString.ps1 -secretJson '${{ env.customerDeploymentCredential }}' -verbose
- name: Run deployment with verbose output
run: ./src/platform-automation/platform-scripts/Deploy-Customer.ps1 -customer "fabrikam" -storageAccountName '${{ env.storageAccountName }}' -storageAccountKey '${{ env.storageAccountKey }}' -verbose

71
.github/workflows/Governance-Contoso.yml поставляемый Normal file
Просмотреть файл

@ -0,0 +1,71 @@
name: Governance visualizer for contoso
on:
pull_request:
types: [closed]
branches:
- master
paths:
- src/platform-automation/cmdb/customers/contoso/*
env:
ManagementGroupId: Contoso.com-Management
OutputPath: wiki/customers/contoso/governance-scan/
MermaidFile: wiki/customers/contoso/governance-scan/AzGovViz_Contoso.com-Management.md
CsvDelimiter: ;
Repository: wikiRepo
customerDeploymentCredential: ${{ secrets.AZURE_CONTOSO_CREDENTIAL }}
defaults:
run:
shell: pwsh
jobs:
build-customer:
name: Scan contoso for Governance changes
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true
steps:
- name: Checkout
uses: actions/checkout@v2
with:
path: main
- uses: actions/checkout@v2
with:
repository: ${{github.repository}}.wiki # specify the wiki repo name here.
path: wiki
- name: Login to Azure with Powershell
run: ./main/src/platform-automation/platform-scripts/Login-WithSecretString.ps1 -secretJson '${{ env.customerDeploymentCredential }}' -verbose
- name: Install Azure resource graph
run: |
Install-Module -Name Az.ResourceGraph -Force
if(!(Test-Path '${{ env.OutputPath }}')){
new-item -itemtype directory '${{ env.OutputPath }}' -Force
}
- name: Run AZGovViz with parameters for this customer
run: ./main/src/platform-automation/platform-scripts/AzGovViz.ps1 -ManagementGroupId ${{ env.ManagementGroupId }} -OutputPath '${{ env.OutputPath }}' -CsvDelimiter "${{ env.CsvDelimiter }}" -AzureDevOpsWikiAsCode -ErrorAction SilentlyContinue -Verbose
- name: Compile mermaid
uses: neenjaw/compile-mermaid-markdown-action@master
with:
files: ${{ env.MermaidFile }}
output: ${{ env.OutputPath }}
env:
HIDE_CODEBLOCKS: 1
ABSOLUTE_IMAGE_LINKS: 0
- name: show changes
run: |
cd wiki
git status
cd ..
- name: Commit files
run: |
cd wiki
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add .
git commit -m "Updated governance wiki"
- name: Push changes to wiki repo
uses: ad-m/github-push-action@master
with:
directory: wiki
repository: ${{github.repository}}.wiki # specify the wiki repo and push the update.
github_token: ${{ secrets.GITHUB_TOKEN }}

71
.github/workflows/Governance-Fabrikam.yml поставляемый Normal file
Просмотреть файл

@ -0,0 +1,71 @@
name: Governance visualizer for fabrikam
on:
pull_request:
types: [closed]
branches:
- master
paths:
- src/platform-automation/cmdb/customers/fabrikam/*
env:
ManagementGroupId: IT
OutputPath: wiki/customers/fabrikam/governance-scan/
MermaidFile: wiki/customers/fabrikam/governance-scan/AzGovViz_IT.md
CsvDelimiter: ;
Repository: wikiRepo
customerDeploymentCredential: ${{ secrets.AZURE_FABRIKAM_CREDENTIAL }}
defaults:
run:
shell: pwsh
jobs:
build-customer:
name: Scan Fabrikam for Governance changes
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true
steps:
- name: Checkout
uses: actions/checkout@v2
with:
path: main
- uses: actions/checkout@v2
with:
repository: ${{github.repository}}.wiki # specify the wiki repo name here.
path: wiki
- name: Login to Azure with Powershell
run: ./main/src/platform-automation/platform-scripts/Login-WithSecretString.ps1 -secretJson '${{ env.customerDeploymentCredential }}' -verbose
- name: Install Azure resource graph
run: |
Install-Module -Name Az.ResourceGraph -Force
if(!(Test-Path '${{ env.OutputPath }}')){
new-item -itemtype directory '${{ env.OutputPath }}' -Force
}
# - name: Run AZGovViz with parameters for this customer
# run: ./main/src/platform-automation/platform-scripts/AzGovViz.ps1 -ManagementGroupId ${{ env.ManagementGroupId }} -OutputPath '${{ env.OutputPath }}' -CsvDelimiter "${{ env.CsvDelimiter }}" -AzureDevOpsWikiAsCode -ErrorAction SilentlyContinue -Verbose
- name: Compile mermaid
uses: neenjaw/compile-mermaid-markdown-action@master
with:
files: ${{ env.MermaidFile }}
output: ${{ env.OutputPath }}
env:
HIDE_CODEBLOCKS: 1
ABSOLUTE_IMAGE_LINKS: 0
- name: show changes
run: |
cd wiki
git status
cd ..
- name: Commit files
run: |
cd wiki
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add .
git commit -m "Updated governance wiki"
- name: Push changes to wiki repo
uses: ad-m/github-push-action@master
with:
directory: wiki
repository: ${{github.repository}}.wiki # specify the wiki repo and push the update.
github_token: ${{ secrets.GITHUB_TOKEN }}

53
.github/workflows/Manage-CustomerSubscriptions.yml поставляемый Normal file
Просмотреть файл

@ -0,0 +1,53 @@
name: Manage CSP Customer subscriptions
on:
push:
branches:
- master
paths:
- src/platform-automation/cmdb/customers/**/new_subscription
- src/platform-automation/cmdb/customers/**/delete_subscription
env:
partnerCenterCredential: ${{ secrets.AZURE_CONTOSO_CREDENTIAL }}
defaults:
run:
shell: pwsh
jobs:
manage-subscriptions:
name: Manage subscriptions for customers
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Login to Azure with Powershell
run: ./src/platform-automation/platform-scripts/Login-WithSecretString.ps1 -secretJson '${{ env.partnerCenterCredential }}' -verbose
- name: Install Azure resource graph and partner center SDK
run: |
Install-Module -Name Az.ResourceGraph -Force
Install-Module -Name PartnerCenter -Force;
- name: get changed files
id: getfile
run: |
echo "::set-output name=files::$(git diff-tree --no-commit-id --name-only -r ${{ github.sha }} | grep -e '.*new_subscription$' -e '.*delete_subscription$' | xargs)"
- name: Run the correct management scripts for the change
run: |
# $files = ${{ steps.getfile.outputs.files }}
$new_files = Get-ChildItem -Path ./src/platform-automation/cmdb/customers -recurse -filter new_subscription
$deleted_files = Get-ChildItem -Path ./src/platform-automation/cmdb/customers -recurse -filter deleted_subscription;
$new_files|Foreach-object {
./src/platform-automation/platform-scripts/New-CustomerSubscription.ps1 -subscriptionFile $_.Fullname -Verbose
}
# Could output subscriptions to customer file and auto-commit that
- name: Commit changes
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add .
git commit -m "Updated subscription files"
- name: Push changes to wiki repo
uses: ad-m/github-push-action@master
with:
repository: ${{github.repository}}
github_token: ${{ secrets.GITHUB_TOKEN }}

41
.github/workflows/Publish-Artifacts-To-AzureStorage.yml поставляемый Normal file
Просмотреть файл

@ -0,0 +1,41 @@
name: Production - Verify and publish artifacts to Azure Storage
on:
pull_request:
types: [closed]
branches:
- master
paths:
- src/platform-automation/artifacts/**
defaults:
run:
shell: pwsh
env:
storageAccountName: ${{ secrets.AZURE_STORAGE_ACCOUNT_PROD }}
storageAccountKey: ${{ secrets. AZURE_DEPLOYMENT_STORAGE_SAS_PROD }}
artifactsVersion: "1.0"
artifactsSrcFolder: ./src/platform-automation/artifacts
deploymentAutomationCredential: ${{ secrets.AZURE_SUBSCRIPTION_CREDENTIAL }}
jobs:
build-and-deploy:
runs-on: ubuntu-latest
# strategy:
# matrix:
# artifacts: ['blueprints','dsc','scripts','workbooks','templates']
# fail-fast: true
if: github.event.pull_request.merged == true
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Login to Azure with Powershell
run: ./src/platform-automation/platform-scripts/Login-WithSecretString.ps1 -secretJson '${{ env.deploymentAutomationCredential }}' -verbose
- name: Prepare for artifact upload
run: |
Write-Output 'StorageAccount : ${{ env.storageAccountName }} Preparing artifacts and uploading artifacts from ${{ env.artifactsSrcPath }}'
- name: Run upload artifacts script
run: ./src/platform-automation/platform-scripts/Upload-Artifacts.ps1 -storageAccountName '${{ env.storageAccountName }}' -storageAccountKey '${{ env.storageAccountKey }}' -version '${{ env.artifactsVersion }}' -artifactsPath '${{ env.artifactsSrcFolder }}' -verbose

40
.github/workflows/Publish-Artifacts.yml поставляемый Normal file
Просмотреть файл

@ -0,0 +1,40 @@
name: Publish artifacts to workflow
on:
push:
paths:
- src/platform-automation/artifacts
# paths-ignore:
# - 'docs/**'
jobs:
create-artifacts:
name: Create artifacts for re-use
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Create blueprints artifacts
uses: actions/upload-artifact@v1
with:
name: Blueprints
path: ./src/platform-automation/artifacts/blueprints
- name: Create Desired state configuration artifacts
uses: actions/upload-artifact@v1
with:
name: dsc
path: ./src/platform-automation/artifacts/dsc
- name: Create pipelines artifact
uses: actions/upload-artifact@v1
with:
name: pipelines
path: ./src/platform-automation/artifacts/pipelines
- name: Create scripts
uses: actions/upload-artifact@v1
with:
name: scripts
path: ./src/platform-automation/artifacts/scripts
- name: Create all templates in one artifact
uses: actions/upload-artifact@v1
with:
name: templates
path: ./src/platform-automation/artifacts/templates

17
.github/workflows/Readme.md поставляемый Normal file
Просмотреть файл

@ -0,0 +1,17 @@
# Workflows needs to be on (ROOT)\.github\workflows
# Getting started
The workflows needs some secrets to be set under github and some 'prework'.
Create a storage account that are to be used for sharing artifacts (or configure the name in the pipelines)
See:
- [Publish-Artifacts-To-AzureStorage.yml](./Publish-Artifacts-To-AzureStorage.yml).
- [Deploy-Contoso.yml](./Deploy-Contoso.yml).
Create minimum two secrets in github to allow the 'operations/platform' pipelines to work:
- AZURE_DEPLOYMENT_STORAGE_SAS => SAS from the previous storage account
- AZURE_SUBSCRIPTION_CREDENTIAL => Credential for deployment automation
In addition - per pipeline (customer)
- AZURE_CUSTOMER_SUBSCRIPTION_CREDENTIAL => Diff

51
.github/workflows/Test-And-Upload-Dev-Artifacts.yml поставляемый Normal file
Просмотреть файл

@ -0,0 +1,51 @@
name: Dev - Verify and publish artifacts to Azure Storage
on:
push:
branches-ignore:
- master
paths:
- src/platform-automation/artifacts/**
defaults:
run:
shell: pwsh
env:
storageAccountName: ${{ secrets.AZURE_STORAGE_ACCOUNT_DEV }}
storageAccountKey: ${{ secrets. AZURE_DEPLOYMENT_STORAGE_SAS_DEV }}
artifactsVersion: "1.0"
artifactsSrcFolder: ./src/platform-automation/artifacts
deploymentAutomationCredential: ${{ secrets.AZURE_SUBSCRIPTION_CREDENTIAL }}
jobs:
test_arm_templates:
runs-on: ubuntu-latest
name: Run artifacts tests for all customers
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Run artifacts test
run: |
Find-Module Pester|Install-Module -Scope CurrentUser -Force
Import-module Pester
./src/platform-automation/tests/Artifacts.tests.ps1
build-and-deploy:
needs: test_arm_templates
runs-on: ubuntu-latest
# strategy:
# matrix:
# artifacts: ['blueprints','dsc','scripts','workbooks','templates']
# fail-fast: true
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Login to Azure with Powershell
run: ./src/platform-automation/platform-scripts/Login-WithSecretString.ps1 -secretJson '${{ env.deploymentAutomationCredential }}' -verbose
- name: Prepare for artifact upload
run: |
Write-Output 'StorageAccount : ${{ env.storageAccountName }} Preparing artifacts and uploading artifacts from ${{ env.artifactsSrcPath }}'
- name: Run upload artifacts script
run: ./src/platform-automation/platform-scripts/Upload-Artifacts.ps1 -storageAccountName '${{ env.storageAccountName }}' -storageAccountKey '${{ env.storageAccountKey }}' -version '${{ env.artifactsVersion }}' -artifactsPath '${{ env.artifactsSrcFolder }}' -verbose

66
.github/workflows/Update-Wiki.yml поставляемый Normal file
Просмотреть файл

@ -0,0 +1,66 @@
name: Update wiki
on:
push:
branches:
- master
paths:
- src/platform-automation/cmdb/customers/**
defaults:
run:
shell: pwsh
env:
artifactsSrcFolder: ./src/platform-automation/artifacts
lighthouseDeploymentCredential: ${{ secrets.AZURE_LIGHTHOUSE_CREDENTIAL }}
jobs:
test_arm_templates:
runs-on: ubuntu-latest
name: Generate wiki pages for all customers managed by code
steps:
- uses: actions/checkout@v2
with:
path: main
- uses: actions/checkout@v2
with:
repository: ${{github.repository}}.wiki # specify the wiki repo name here.
path: wiki
- name: Login to Azure with Powershell
run: ./main/src/platform-automation/platform-scripts/Login-WithSecretString.ps1 -secretJson '${{ env.lighthouseDeploymentCredential }}' -verbose
- name: check wiki repo content
run: |
cd wiki
ls -al
- name: Update customers wiki
run: ./main/src/platform-automation/platform-scripts/Build-Wiki.ps1 -customersPath 'main/src/platform-automation/cmdb/customers' -wikiPath 'wiki/'
- name: Commit changes files
run: |
cd wiki
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add .
git commit -m "Updated wiki"
- name: Push changes to wiki repo
uses: ad-m/github-push-action@master
with:
directory: wiki
repository: ${{github.repository}}.wiki # specify the wiki repo and push the update.
github_token: ${{ secrets.GITHUB_TOKEN }}
# - name: Updated Governance documentation for customers
# id: cpr
# uses: peter-evans/create-pull-request@v2
# with:
# path: wiki
# token: ${{ secrets.GITHUB_TOKEN }}
# commit-message: Updated customer list
# title: '[Customers] Updated list of customers'
# body: |
# - Auto-generated by [create-pull-request][1]
# labels: report, automated pr
# assignees: haraldfianbakken
# reviewers: haraldfianbakken
# branch-suffix: timestamp
# - name: Check outputs
# run: |
# echo "Pull Request Number - ${{ env.PULL_REQUEST_NUMBER }}"
# echo "Pull Request Number - ${{ steps.cpr.outputs.pr_number }}"

23
.github/workflows/Validate-Customers-Tests.yml поставляемый Normal file
Просмотреть файл

@ -0,0 +1,23 @@
name: Customer Platform Validation Tests
on:
push:
branches:
- master
paths:
- src/platform-automation/cmdb/customers/*/manifest.json
defaults:
run:
shell: pwsh
jobs:
test_arm_templates:
runs-on: ubuntu-latest
name: Run artifacts tests for all customers
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Run artifacts test
run: |
Find-Module Pester|Install-Module -Scope CurrentUser -Force
Import-module Pester
./src/platform-automation/tests/Artifacts.tests.ps1