-
-
Notifications
You must be signed in to change notification settings - Fork 21
124 lines (108 loc) · 4.26 KB
/
Copy pathvalidate-scripts.yml
File metadata and controls
124 lines (108 loc) · 4.26 KB
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
name: "Validate project"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
on:
push:
branches:
- main
paths:
- 'src/**'
- 'tests/*.ps1'
- '!src/VERSION.txt'
workflow_dispatch:
permissions:
contents: write # Required for committing version changes and pushing to repository
security-events: write # Required for uploading SARIF results to GitHub Security
checks: write # Required for publishing test results
pull-requests: write # Required for commenting on PRs with test results (if applicable)
jobs:
validate:
name: "Validate project code"
runs-on: windows-latest
steps:
- uses: actions/checkout@v7
with:
ref: main
- name: Run PSScriptAnalyzer
uses: microsoft/psscriptanalyzer-action@6b2948b1944407914a58661c49941824d149734f
with:
path: ./src
recurse: true
# output: results.sarif
# # Upload the SARIF file generated in the previous step
# - name: Upload SARIF results file
# uses: github/codeql-action/upload-sarif@v4
# with:
# sarif_file: results.sarif
- name: Install Pester
shell: powershell
working-directory: "${{ github.workspace }}"
run: |
Install-Module -Name "Pester" -SkipPublisherCheck -Force
# Run Pester tests
- name: Test with Pester
shell: powershell
working-directory: "${{ github.workspace }}"
run: |
Import-Module -Name "Pester" -Force -ErrorAction "Stop"
$Config = New-PesterConfiguration
$Config.Run.Path = "$env:GITHUB_WORKSPACE\tests"
$Config.Run.PassThru = $true
$Config.CodeCoverage.Enabled = $true
$Config.CodeCoverage.CoveragePercentTarget = 50
$Files = Get-ChildItem -Path "$env:GITHUB_WORKSPACE\src" -Recurse -File -Include *.ps1 -Exclude "Start-DefaultsViewer.ps1"
$Config.CodeCoverage.Path = $Files.FullName
$Config.CodeCoverage.OutputFormat = "JaCoCo"
$Config.CodeCoverage.OutputPath = "$env:GITHUB_WORKSPACE\CodeCoverage.xml"
$Config.TestResult.Enabled = $true
$Config.Output.Verbosity = "Detailed"
$Config.TestResult.OutputFormat = "NUnitXml"
$Config.TestResult.OutputPath = "$env:GITHUB_WORKSPACE\tests\TestResults.xml"
Invoke-Pester -Configuration $Config
# Upload test results
- name: Upload test results
uses: actions/upload-artifact@v7
if: always()
with:
name: test-results
path: "${{ github.workspace }}\\tests\\TestResults.xml"
# Publish test results
- name: Publish test results
uses: EnricoMi/publish-unit-test-result-action/windows@v2
if: always()
with:
files: "${{ github.workspace }}\\tests\\TestResults.xml"
- name: Get version
id: get-version
shell: powershell
working-directory: "${{ github.workspace }}"
run: |
echo "version=$(Get-Date -Format "yyMM.dd.$($env:GITHUB_RUN_NUMBER)")" | Out-File -FilePath $Env:GITHUB_OUTPUT -Encoding utf8 -Append
# Update version number in VERSION.txt
- name: Update version number
shell: powershell
working-directory: "${{ github.workspace }}"
run: |
"${{ steps.get-version.outputs.version }}" | `
Out-File -FilePath "${{ github.workspace }}\src\VERSION.txt" -Encoding "ascii" -Force -NoNewline
# Import GPG key
- name: Import GPG key
id: import_gpg
uses: crazy-max/ghaction-import-gpg@v7
with:
gpg_private_key: ${{ secrets.GPGKEY }}
passphrase: ${{ secrets.GPGPASSPHRASE }}
git_user_signingkey: true
git_commit_gpgsign: true
git_config_global: true
git_tag_gpgsign: true
git_push_gpgsign: false
git_committer_name: ${{ secrets.COMMIT_NAME }}
git_committer_email: ${{ secrets.COMMIT_EMAIL }}
- name: Commit changes
id: commit
uses: stefanzweifel/git-auto-commit-action@v7
with:
commit_message: "${{ steps.get-version.outputs.version }}"
commit_user_name: ${{ secrets.COMMIT_NAME }}
commit_user_email: ${{ secrets.COMMIT_EMAIL }}