-
Notifications
You must be signed in to change notification settings - Fork 89
/
action.yml
149 lines (134 loc) · 5.8 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
name: "Maester Action"
description: "Monitor your Microsoft 365 tenant's security configuration using Maester THE PowerShell-based test automation framework"
branding:
icon: "check-circle"
color: "red"
inputs:
tenant_id:
description: "Entra ID Tenant ID"
required: true
client_id:
description: "App Registration Client ID"
required: true
include_public_tests:
description: "Include public test repository 'maester365/maester-tests' as well as private tests in the test run"
required: false
default: "true"
mail_recipients:
description: "A list of email addresses to send the test results to. Please separate multiple email addresses with a comma."
required: false
default: ""
mail_userid:
description: "The user id of the sender of the mail. This is required since the action is using application permissions."
required: false
default: ""
mail_testresultsuri:
description: "Uri to the detailed test results page."
required: false
default: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
include_tags:
description: "A list of tags to include in the test run. Please separate multiple tags with a comma."
required: false
default: ""
exclude_tags:
description: "A list of tags to exclude from the test run. Please separate multiple tags with a comma."
required: false
default: ""
pester_verbosity:
description: "Pester verbosity level. Options: 'None', 'Normal', 'Detailed', 'Diagnostic'"
required: false
default: "None"
step_summary:
type: boolean
description: "Define whether a summary is outputted to GitHub Actions."
required: false
default: true
artifact_upload:
type: boolean
description: "Define whether the results are uploaded as Artifacts."
required: false
default: true
runs:
using: "composite"
steps:
- name: Sign in to Entra ID
uses: azure/login@v2
with:
client-id: ${{ inputs.client_id }}
tenant-id: ${{ inputs.tenant_id }}
allow-no-subscriptions: true
- name: Set current date as env variable
shell: bash
run: echo "NOW=$(date +'%Y-%m-%d-T%H%M%S')" >> $GITHUB_ENV
- name: Checkout latest public tests
if: ${{ inputs.include_public_tests == 'true' }}
uses: actions/checkout@v4
with:
repository: maester365/maester-tests
path: public-tests
- name: Checkout latest private tests
uses: actions/checkout@v4
with:
path: private-tests
- name: Run Maester
uses: azure/powershell@v2
with:
inlineScript: |
# Get Token
$token = az account get-access-token --resource-type ms-graph
# Connect to Microsoft Graph
$accessToken = ($token | ConvertFrom-Json).accessToken | ConvertTo-SecureString -AsPlainText -Force
Connect-MgGraph -AccessToken $accessToken -NoWelcome
# Install Maester
Install-Module Maester -Force
# Configure test results
$PesterConfiguration = New-PesterConfiguration
$PesterConfiguration.Output.Verbosity = '${{ inputs.pester_verbosity }}'
Write-Host "Pester verbosity level set to: $($PesterConfiguration.Output.Verbosity.Value)"
$MaesterParameters = @{
Path = '${{ github.workspace }}'
PesterConfiguration = $PesterConfiguration
OutputFolder = 'test-results'
OutputFolderFileName = 'test-results'
PassThru = $true
}
# Check if test tags are provided
if ( [string]::IsNullOrWhiteSpace( '${{ inputs.include_tags }}' ) -eq $false ) {
$TestTags = '${{ inputs.include_tags }}' -split ','
$MaesterParameters.Add( 'Tag', $TestTags )
Write-Host "Running tests with tags: $TestTags"
}
# Check if exclude test tags are provided
if ( [string]::IsNullOrWhiteSpace( '${{ inputs.exclude_tags }}' ) -eq $false ) {
$ExcludeTestTags = '${{ inputs.exclude_tags }}' -split ','
$MaesterParameters.Add( 'ExcludeTag', $ExcludeTestTags )
Write-Host "Excluding tests with tags: $ExcludeTestTags"
}
# Check if mail recipients and mail userid are provided
if ( [string]::IsNullOrWhiteSpace( '${{ inputs.mail_userid }}' ) -eq $false ) {
if ( [string]::IsNullOrWhiteSpace( '${{ inputs.mail_recipients }}' ) -eq $false ) {
# Add mail parameters
$MaesterParameters.Add( 'MailUserId', '${{ inputs.mail_userid }}' )
$Recipients = '${{ inputs.mail_recipients }}' -split ','
$MaesterParameters.Add( 'MailRecipient', $Recipients )
$MaesterParameters.Add( 'MailTestResultsUri', '${{ inputs.mail_testresultsuri }}' )
Write-Host "Mail notification will be sent to: $Recipients"
} else {
Write-Warning "Mail recipients are not provided. Skipping mail notification."
}
}
# Run Maester tests
$results = Invoke-Maester @MaesterParameters
if('${{ inputs.step_summary }}' -ne $false) {
# Add step summary
$summary = Get-Content test-results/test-results.md
Add-Content -Path $env:GITHUB_STEP_SUMMARY -Value $summary
}
azPSVersion: "latest"
- name: Archive Maester Html Report
uses: actions/upload-artifact@v4
if: ${{ inputs.artifact_upload == 'true' }}
with:
name: maester-test-results-${{ env.NOW }}
path: test-results
include-hidden-files: true