CI #26
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| on: | |
| push: | |
| tags: | |
| - "v*" | |
| workflow_dispatch: | |
| env: | |
| DOTNET_CLI_TELEMETRY_OPTOUT: true | |
| DOTNET_GENERATE_ASPNET_CERTIFICATE: false | |
| DOTNET_NOLOGO: true | |
| DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true | |
| jobs: | |
| build: | |
| runs-on: windows-latest | |
| steps: | |
| - uses: actions/checkout@v5 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup dotnet | |
| id: setup-dotnet | |
| uses: actions/setup-dotnet@v5 | |
| with: | |
| global-json-file: src/global.json | |
| - name: Setup wix | |
| run: | | |
| dotnet.exe tool install --global wix --version 6.0.2 --verbosity diag | |
| wix.exe extension add WixToolset.UI.wixext/6.0.2 --global | |
| wix.exe extension list --global | |
| - name: Generate version property | |
| id: version | |
| run: | | |
| $pattern = '^v(((\d+\.\d+\.\d+\.\d+)(?:-[a-z]+\.\d+)?)-(\d+-g.+))' | |
| $tag = git.exe describe --tags --long | |
| $version = [System.Text.RegularExpressions.Regex]::Match($tag, $pattern).Groups[3].Value | |
| $fullVersion = [System.Text.RegularExpressions.Regex]::Match($tag, $pattern).Groups[2].Value | |
| $gitCommitInfo = [System.Text.RegularExpressions.Regex]::Match($tag, $pattern).Groups[4].Value | |
| $informationalVersion = '{0}+{1}' -f $fullVersion,$gitCommitInfo | |
| echo "version=$version" >> $env:GITHUB_OUTPUT | |
| echo "fullVersion=$fullVersion" >> $env:GITHUB_OUTPUT | |
| echo "informationalVersion=$informationalVersion" >> $env:GITHUB_OUTPUT | |
| - name: Run tests | |
| run: | | |
| cd .\src | |
| dotnet.exe test --project .\Tests\Tests.csproj --configuration Debug --output Detailed | |
| - name: Clean solution | |
| run: dotnet.exe clean .\src\PSDataProtection.sln --configuration Release | |
| - name: Build project | |
| run: dotnet.exe publish .\src\PSDataProtection\PSDataProtection.csproj --configuration Release --output .\publish | |
| - name: Prepare release | |
| run: Remove-Item ./publish/* -Include *.pdb,*.xml -ErrorAction Stop | |
| - name: Generate PowerShell help | |
| run: | | |
| Install-Module -Name platyPS -Force -Confirm:$false -ErrorAction Stop | |
| Import-Module ./publish/PSDataProtection.psd1 -ErrorAction Stop | |
| Update-MarkdownHelp ./docs -UpdateInputOutput -Force -ErrorAction Stop | |
| New-ExternalHelp ./docs -OutputPath ./publish -ErrorAction Stop | |
| - name: Build installer | |
| run: | | |
| wix.exe ` | |
| build ` | |
| -arch x64 ` | |
| -src src\Product.wxs ` | |
| -d ProductSource="$(Resolve-Path ./publish)" ` | |
| -d ProductVersion="${{ steps.version.outputs.version }}" ` | |
| -ext WixToolset.UI.wixext ` | |
| -out ps-data-protection.msi | |
| - name: Validate installer | |
| run: wix.exe msi validate ps-data-protection.msi | |
| - name: Upload artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ps-data-protection | |
| path: | | |
| ./docs/ | |
| ./ps-data-protection.msi | |
| if-no-files-found: error | |
| - name: Install msi | |
| run: | | |
| $process = Start-Process msiexec.exe -ArgumentList '/i','ps-data-protection.msi','/qn' -Wait -NoNewWindow -PassThru -ErrorAction Stop | |
| if ($process.ExitCode -ne 0) | |
| { | |
| throw 'Non zero exit code: "{0}".' -f $process.ExitCode | |
| } | |
| - name: Test module | |
| shell: powershell | |
| run: | | |
| $PSVersionTable | |
| $secret = 'Hello World!' | |
| $secureString = ConvertTo-SecureString $secret -AsPlainText -Force -ErrorAction Stop | |
| $protected = New-DataProtectionSecret -SecureString $secureString -Scope CurrentUser -ErrorAction Stop | |
| $unprotected = Read-DataProtectionSecret -Protected $protected -Scope CurrentUser -ErrorAction Stop | |
| $unprotected | |
| if ($secret -ne $unprotected) { throw } | |
| - name: Publish release | |
| if: github.ref_type == 'tag' | |
| run: gh.exe release create v${{ steps.version.outputs.fullVersion }} --title v${{ steps.version.outputs.fullVersion }} --notes 'PowerShell data protection module.' ps-data-protection.msi | |
| env: | |
| # Requires a personal access token with a fine-grained permission of contents:read/write. | |
| GH_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }} |