-
Notifications
You must be signed in to change notification settings - Fork 28
155 lines (142 loc) · 5.3 KB
/
universalnrp-test.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
150
151
152
153
154
155
name: Universal NRP Test
on:
workflow_dispatch:
pull_request:
schedule:
- cron: '0 20 * * *' # Every day at 12pm PST (UTC-8)
jobs:
package:
name: Package
uses: ./.github/workflows/package-build.yml
strategy:
matrix:
target:
[
{ os: ubuntu, version: 14.04, arch: amd64, dist: trusty, package-type: DEB },
]
with:
target: ${{ matrix.target.os }}-${{ matrix.target.version }}
arch: ${{ matrix.target.arch }}
artifact: nrp-test-package
package-type: ${{ matrix.target.package-type }}
machine-config: true
release: ${{ github.event_name == 'pull_request' && false || true }}
test:
name: Test
needs: package
runs-on: [self-hosted, 1ES.Pool=ci-pool, '1ES.ImageOverride=${{ matrix.target.os }}-${{ matrix.target.version }}']
strategy:
fail-fast: false
matrix:
target:
[
{ os: centos, version: 8, package-type: RPM, tag: ''},
{ os: debian, version: 10, package-type: DEB, tag: ''},
{ os: debian, version: 11, package-type: DEB, tag: ''},
{ os: mariner, version: 2, package-type: RPM, tag: ''},
{ os: oraclelinux, version: 8, package-type: RPM, tag: ''},
{ os: rhel, version: 8, package-type: RPM, tag: ''},
{ os: rhel, version: 9, package-type: RPM, tag: ''},
{ os: rockylinux, version: 9, package-type: RPM, tag: ''},
{ os: sles, version: 15, package-type: RPM, tag: ''},
{ os: ubuntu, version: 20.04, package-type: DEB, tag: ''},
{ os: ubuntu, version: 22.04, package-type: DEB, tag: ''},
]
policy-package:
[
{ name: LinuxSshServerSecurityBaseline, short-name: SSH, resource-count: 20 },
{ name: AzureLinuxBaseline, short-name: ASB, resource-count: 168 },
]
arch: [amd64]
mode: [Audit, Remediate]
steps:
- uses: actions/checkout@v4
- name: Normalize variables
id: normalize
run: |
output=${{ matrix.target.os }}-${{ matrix.target.version }}_${{ matrix.policy-package.short-name }}-${{ matrix.mode }}
echo name=${output} >> $GITHUB_OUTPUT
- uses: actions/download-artifact@v4
id: download
with:
name: nrp-test-package
- name: Run Guest Configuration Test
working-directory: ${{ steps.download.outputs.download-path }}
run: |
script="./universalNRPTest.ps1"
cat >$script <<EOL
Install-Module -Name GuestConfiguration -Force
Install-Module Pester -Force -SkipPublisherCheck
Import-Module Pester -Passthru
\$params = @{
PolicyPackage = './${{ matrix.policy-package.name }}.zip'
SkipRemediation = if ('${{ matrix.mode }}' -eq 'Audit') { \$true } else { \$false }
ResourceCount = ${{ matrix.policy-package.resource-count }}
}
\$container = New-PesterContainer -Path ./src/tests/universal-nrp-e2e/UniversalNRP.Tests.ps1 -Data \$params
\$pesterConfig = [PesterConfiguration]@{
Run = @{
Exit = \$true
Container = \$container
}
Output = @{
Verbosity = 'Detailed'
}
TestResult = @{
Enabled = \$true
OutputFormat = 'JUnitXml'
OutputPath = '${{ steps.normalize.outputs.name }}-testResults.xml'
}
Should = @{
ErrorAction = 'Continue'
}
Filter = @{
Tag = '${{ matrix.tag }}'
}
};
Invoke-Pester -Configuration \$pesterConfig
EOL
sudo LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/omi/lib/ pwsh -Command $script
ls -l
# if command -v lsb_release &>/dev/null; then
# [[ $(lsb_release -is) == "Ubuntu" ]] && sudo chmod 644 *testResults.xml
# else
# echo "lsb_release not found"
# fi
stat *testResults.xml
- name: Stage OSConfig Logs
if: success() || failure()
run: |
mkdir osconfig-logs
stat /var/log/osconfig_nrp.log
cp -r /var/log/osconfig* osconfig-logs/
- uses: actions/upload-artifact@v4
if: success() || failure()
with:
name: ${{ steps.normalize.outputs.name }}_report
path: '${{ steps.download.outputs.download-path }}/*testResults.xml'
- uses: actions/upload-artifact@v4
if: success() || failure()
with:
name: ${{ steps.normalize.outputs.name }}_logs
path: osconfig-logs/osconfig*
# See for more details: https://github.com/marketplace/actions/publish-test-results
report:
name: Report
needs: test
runs-on: ubuntu-latest
permissions:
checks: write
pull-requests: write
if: always()
steps:
- name: Download Test Report Artifacts
uses: actions/download-artifact@v4
with:
path: universal-nrp-test
pattern: '*_report'
merge-multiple: true
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
with:
files: 'universal-nrp-test/*testResults.xml'