Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mazhelez committed Jan 9, 2024
2 parents d831a3d + ef8b276 commit 0b83925
Show file tree
Hide file tree
Showing 76 changed files with 1,684 additions and 607 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ defaults:

jobs:
AnalyzeTests:
if: github.repository == 'Microsoft/NavContainerHelper'
runs-on: [ windows-latest ]
outputs:
tests: ${{ steps.Analyze.outputs.tests }}
Expand All @@ -37,6 +38,7 @@ jobs:
- name: Analyze
id: Analyze
run: |
$errorActionPreference = "stop"
$tests = @(Get-ChildItem -Path (Join-Path $ENV:GITHUB_WORKSPACE 'Tests\*.Tests.ps1') | ForEach-Object { $_.BaseName }) | ConvertTo-Json -compress
Add-Content -Path $env:GITHUB_OUTPUT -Value "tests=$tests"
Write-Host "tests=$tests"
Expand All @@ -62,7 +64,7 @@ jobs:
try {
$errorActionPreference = "stop"
Set-StrictMode -version 2.0
$pesterContainer = New-PesterContainer -Path (Join-Path $ENV:GITHUB_WORKSPACE 'Tests\${{ matrix.test }}.ps1') -Data @{ "licenseFile" = '${{ secrets.licensefile }}'; "buildLicenseFile" = '${{ secrets.buildLicenseFile }}'; "insiderSasToken" = '${{ secrets.insiderSasToken }}' }
$pesterContainer = New-PesterContainer -Path (Join-Path $ENV:GITHUB_WORKSPACE 'Tests\${{ matrix.test }}.ps1') -Data @{ "licenseFile" = '${{ secrets.licensefile }}'; "buildLicenseFile" = '${{ secrets.buildLicenseFile }}' }
$result = Invoke-Pester -Container $pesterContainer -passthru
if ($result.FailedCount -gt 0) {
Write-Host "::Error::$($result.FailedCount) tests are failing"
Expand Down Expand Up @@ -95,7 +97,7 @@ jobs:
try {
$errorActionPreference = "stop"
Set-StrictMode -version 2.0
$pesterContainer = New-PesterContainer -Path (Join-Path $ENV:GITHUB_WORKSPACE 'Tests\${{ matrix.test }}.ps1') -Data @{ "licenseFile" = '${{ secrets.licensefile }}'; "buildLicenseFile" = '${{ secrets.buildLicenseFile }}'; "insiderSasToken" = '${{ secrets.insiderSasToken }}' }
$pesterContainer = New-PesterContainer -Path (Join-Path $ENV:GITHUB_WORKSPACE 'Tests\${{ matrix.test }}.ps1') -Data @{ "licenseFile" = '${{ secrets.licensefile }}'; "buildLicenseFile" = '${{ secrets.buildLicenseFile }}' }
$result = Invoke-Pester -Container $pesterContainer -passthru
if ($result.FailedCount -gt 0) {
Write-Host "::Error::$($result.FailedCount) tests are failing"
Expand Down Expand Up @@ -128,7 +130,7 @@ jobs:
try {
$errorActionPreference = "stop"
Set-StrictMode -version 2.0
$pesterContainer = New-PesterContainer -Path (Join-Path $ENV:GITHUB_WORKSPACE 'LinuxTests\${{ matrix.test }}.ps1') -Data @{ "licenseFile" = '${{ secrets.licensefile }}'; "buildLicenseFile" = '${{ secrets.buildLicenseFile }}'; "insiderSasToken" = '${{ secrets.insiderSasToken }}' }
$pesterContainer = New-PesterContainer -Path (Join-Path $ENV:GITHUB_WORKSPACE 'LinuxTests\${{ matrix.test }}.ps1') -Data @{ "licenseFile" = '${{ secrets.licensefile }}'; "buildLicenseFile" = '${{ secrets.buildLicenseFile }}' }
$result = Invoke-Pester -Container $pesterContainer -passthru
if ($result.FailedCount -gt 0) {
Write-Host "::Error::$($result.FailedCount) tests are failing"
Expand Down
17 changes: 9 additions & 8 deletions .github/workflows/Release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ defaults:

jobs:
Deploy:
if: github.repository == 'Microsoft/NavContainerHelper'
runs-on: [ windows-latest ]
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Deploy
run: |
$errorActionPreference = "stop"
try {
$path = Join-Path ([System.IO.Path]::GetTempPath()) "BcContainerHelper"
New-Item -path $path -itemType Directory | Out-Null
Expand Down Expand Up @@ -56,7 +58,7 @@ jobs:
Write-Host "Release Notes:"
Write-Host $VersionReleaseNotes
Write-Host "Update Module Manifest"
Update-ModuleManifest -Path (Join-Path $path "BcContainerHelper.psd1") `
-RootModule "BcContainerHelper.psm1" `
Expand All @@ -67,28 +69,27 @@ jobs:
-CompanyName "Microsoft" `
-ReleaseNotes $versionReleaseNotes
$certFileName = Join-Path ([System.IO.Path]::GetTempPath()) "$([GUID]::NewGuid().ToString()).pfx"
Download-File -sourceUrl '${{ secrets.CodeSignCertificateUrl }}' -destinationFile $certFileName
Remove-Module BcContainerHelper
Write-Host $path
Write-Host "Signing scripts"
$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2($certFileName, '${{ secrets.CodeSignCertificatePassword }}')
$filesToSign = @((Get-ChildItem $path -Filter "*.ps1" -Recurse -Depth 99).FullName)+
@((Get-ChildItem $path -Filter "*.psm1" -Recurse -Depth 99).FullName)
Set-AuthenticodeSignature -Certificate $cert -HashAlgorithm SHA256 -TimestampServer "http://timestamp.digicert.com" -FilePath $filesToSign
Write-Host "Upload to storage (preview)"
$storageContext = New-AzureStorageContext -ConnectionString '${{ secrets.BchStorageConnectionString }}'
New-AzureStorageContainer -Name 'public' -Context $storageContext -Permission 'Container' -ErrorAction Ignore | Out-Null
Compress-Archive -path $path -DestinationPath "$($path).zip"
Set-AzureStorageBlobContent -File "$($path).zip" -Context $storageContext -Container 'public' -Blob "$version.zip" -Force | Out-Null
Set-AzureStorageBlobContent -File "$($path).zip" -Context $storageContext -Container 'public' -Blob "latest.zip" -Force | Out-Null
Write-Host "Publishing Module"
Publish-Module -Path $path -NuGetApiKey '${{ secrets.NugetKey }}' -SkipAutomaticTags
}
Expand Down
158 changes: 158 additions & 0 deletions .github/workflows/RunTests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
name: Run Tests

on:
workflow_dispatch:
inputs:
ref:
description: ref on which to run the end-2-end tests (default is head_sha on the current branch)
required: false
default: ''
testPatterns:
description: Commaseparated list of patterns to match against test names (default is * for all tests)
required: false
default: ''

permissions:
contents: read
actions: read
pull-requests: write
checks: write

concurrency:
group: 'runTests-${{ github.ref }}'
cancel-in-progress: true

defaults:
run:
shell: powershell

jobs:
AnalyzeTests:
runs-on: [ windows-latest ]
outputs:
tests: ${{ steps.Analyze.outputs.tests }}
linuxtests: ${{ steps.Analyze.outputs.linuxtests }}
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.inputs.ref }}
lfs: true

- name: Analyze
id: Analyze
env:
testPatterns: ${{ github.event.inputs.testPatterns }}
run: |
$errorActionPreference = "stop"
$testPatterns = $ENV:TESTPATTERNS
if (!$testPatterns) { $testPatterns = '*' }
$testPatternArr = $testPatterns.Split(',')
Write-Host "Running test matching patterns:"
$testPatternArr | ForEach-Object { Write-Host "- $_" }
$tests = ConvertTo-Json -compress -InputObject @(Get-ChildItem -Path (Join-Path $ENV:GITHUB_WORKSPACE 'Tests\*.Tests.ps1') | Where-Object { $name = $_.Basename; $testPatternArr | Where-Object { $name -like "$($_).Tests" } } | ForEach-Object { $_.BaseName })
Add-Content -Path $env:GITHUB_OUTPUT -Value "tests=$tests"
Write-Host "tests=$tests"
$linuxtests = ConvertTo-Json -compress -InputObject @(Get-ChildItem -Path (Join-Path $ENV:GITHUB_WORKSPACE 'LinuxTests\*.Tests.ps1') | Where-Object { $name = $_.Basename; $testPatternArr | Where-Object { $name -like "$($_).Tests" } } | ForEach-Object { $_.BaseName })
Add-Content -Path $env:GITHUB_OUTPUT -Value "linuxtests=$linuxtests"
Write-Host "linuxtests=$linuxtests"
PS5:
runs-on: [ windows-latest ]
needs: [ AnalyzeTests ]
if: needs.AnalyzeTests.outputs.tests != '[]'
strategy:
matrix:
test: ${{fromJson(needs.AnalyzeTests.outputs.tests)}}
fail-fast: false
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.inputs.ref }}
lfs: true

- name: Run Tests
run: |
try {
$errorActionPreference = "stop"
Set-StrictMode -version 2.0
$pesterContainer = New-PesterContainer -Path (Join-Path $ENV:GITHUB_WORKSPACE 'Tests\${{ matrix.test }}.ps1') -Data @{ "licenseFile" = '${{ secrets.licensefile }}'; "buildLicenseFile" = '${{ secrets.buildLicenseFile }}' }
$result = Invoke-Pester -Container $pesterContainer -passthru
if ($result.FailedCount -gt 0) {
Write-Host "::Error::$($result.FailedCount) tests are failing"
$host.SetShouldExit(1)
}
}
catch {
Write-Host "::Error::Exception when running tests. The Error was $($_.Exception.Message)"
$host.SetShouldExit(1)
}
PS7:
runs-on: [ windows-latest ]
needs: [ AnalyzeTests ]
if: needs.AnalyzeTests.outputs.tests != '[]'
strategy:
matrix:
test: ${{fromJson(needs.AnalyzeTests.outputs.tests)}}
fail-fast: false
defaults:
run:
shell: pwsh
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ github.event.inputs.ref }}
lfs: true

- name: Run Tests
run: |
try {
$errorActionPreference = "stop"
Set-StrictMode -version 2.0
$pesterContainer = New-PesterContainer -Path (Join-Path $ENV:GITHUB_WORKSPACE 'Tests\${{ matrix.test }}.ps1') -Data @{ "licenseFile" = '${{ secrets.licensefile }}'; "buildLicenseFile" = '${{ secrets.buildLicenseFile }}' }
$result = Invoke-Pester -Container $pesterContainer -passthru
if ($result.FailedCount -gt 0) {
Write-Host "::Error::$($result.FailedCount) tests are failing"
$host.SetShouldExit(1)
}
}
catch {
Write-Host "::Error::Exception when running tests. The Error was $($_.Exception.Message)"
$host.SetShouldExit(1)
}
Linux:
runs-on: [ ubuntu-latest ]
needs: [ AnalyzeTests ]
if: needs.AnalyzeTests.outputs.linuxtests != '[]'
strategy:
matrix:
test: ${{fromJson(needs.AnalyzeTests.outputs.linuxtests)}}
fail-fast: false
defaults:
run:
shell: pwsh
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ github.event.inputs.ref }}
lfs: true

- name: Run Tests
run: |
try {
$errorActionPreference = "stop"
Set-StrictMode -version 2.0
$pesterContainer = New-PesterContainer -Path (Join-Path $ENV:GITHUB_WORKSPACE 'LinuxTests\${{ matrix.test }}.ps1') -Data @{ "licenseFile" = '${{ secrets.licensefile }}'; "buildLicenseFile" = '${{ secrets.buildLicenseFile }}' }
$result = Invoke-Pester -Container $pesterContainer -passthru
if ($result.FailedCount -gt 0) {
Write-Host "::Error::$($result.FailedCount) tests are failing"
$host.SetShouldExit(1)
}
}
catch {
Write-Host "::Error::Exception when running tests. The Error was $($_.Exception.Message)"
$host.SetShouldExit(1)
}
57 changes: 37 additions & 20 deletions AppHandling/Compile-AppInNavContainer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,8 @@ try {
$dependency = $dependencies[$depidx]
Write-Host "Processing dependency $($dependency.Publisher)_$($dependency.Name)_$($dependency.Version) ($($dependency.AppId))"
$existingApp = $existingApps | Where-Object {
if (($dependency.appId) -and ($platformversion -ge [System.Version]"19.0.0.0")) {
($_.AppId -eq $dependency.appId -and ([System.Version]$_.Version -ge [System.Version]$dependency.version))
if ($platformversion -ge [System.Version]"19.0.0.0") {
((($dependency.appId -ne '' -and $_.AppId -eq $dependency.appId) -or ($dependency.appId -eq '' -and $_.Name -eq $dependency.Name)) -and ([System.Version]$_.Version -ge [System.Version]$dependency.version))
}
else {
(($_.Name -eq $dependency.name) -and ($_.Name -eq "Application" -or (($_.Publisher -eq $dependency.publisher) -and ([System.Version]$_.Version -ge [System.Version]$dependency.version))))
Expand Down Expand Up @@ -502,28 +502,45 @@ try {
try {
# Import types needed to invoke the compiler
$alcPath = 'C:\build\vsix\extension\bin'
Add-Type -Path (Join-Path $alcPath Newtonsoft.Json.dll)
Add-Type -Path (Join-Path $alcPath System.Collections.Immutable.dll)
Add-Type -Path (Join-Path $alcPath System.IO.Packaging.dll)
Add-Type -Path (Join-Path $alcPath Microsoft.Dynamics.Nav.CodeAnalysis.dll)

$packageStream = [System.IO.File]::OpenRead($symbolsFile)
$package = [Microsoft.Dynamics.Nav.CodeAnalysis.Packaging.NavAppPackageReader]::Create($PackageStream, $true)
$manifest = $package.ReadNavAppManifest()

if ($manifest.application) {
@{ "publisher" = "Microsoft"; "name" = "Application"; "appId" = ''; "version" = $manifest.Application }
$alToolExe = Join-Path $alcPath 'win32\altool.exe'
$alToolExists = Test-Path -Path $alToolExe -PathType Leaf
if ($alToolExists) {
$manifest = & "$alToolExe" GetPackageManifest "$symbolsFile" | ConvertFrom-Json
if ($manifest.PSObject.Properties.Name -eq 'application' -and $manifest.application) {
@{ "publisher" = "Microsoft"; "name" = "Application"; "appId" = ''; "version" = $manifest.Application }
}
if ($manifest.PSObject.Properties.Name -eq 'dependencies') {
foreach ($dependency in $manifest.dependencies) {
@{ "publisher" = $dependency.Publisher; "name" = $dependency.name; "appId" = $dependency.id; "Version" = $dependency.Version }
}
}
}
else {
Add-Type -Path (Join-Path $alcPath Newtonsoft.Json.dll)
Add-Type -Path (Join-Path $alcPath System.Collections.Immutable.dll)
if (Test-Path (Join-Path $alcPath System.IO.Packaging.dll)) {
Add-Type -Path (Join-Path $alcPath System.IO.Packaging.dll)
}
Add-Type -Path (Join-Path $alcPath Microsoft.Dynamics.Nav.CodeAnalysis.dll)

$packageStream = [System.IO.File]::OpenRead($symbolsFile)
$package = [Microsoft.Dynamics.Nav.CodeAnalysis.Packaging.NavAppPackageReader]::Create($PackageStream, $true)
$manifest = $package.ReadNavAppManifest()

foreach ($dependency in $manifest.dependencies) {
$appId = ''
if ($dependency.psobject.Properties.name -eq 'appid') {
$appId = $dependency.appid
if ($manifest.application) {
@{ "publisher" = "Microsoft"; "name" = "Application"; "appId" = ''; "version" = $manifest.Application }
}
elseif ($dependency.psobject.Properties.name -eq 'id') {
$appId = $dependency.id

foreach ($dependency in $manifest.dependencies) {
$appId = ''
if ($dependency.psobject.Properties.name -eq 'appid') {
$appId = $dependency.appid
}
elseif ($dependency.psobject.Properties.name -eq 'id') {
$appId = $dependency.id
}
@{ "publisher" = $dependency.Publisher; "name" = $dependency.name; "appId" = $appId; "Version" = $dependency.Version }
}
@{ "publisher" = $dependency.Publisher; "name" = $dependency.name; "appId" = $appId; "Version" = $dependency.Version }
}
}
catch [System.Reflection.ReflectionTypeLoadException] {
Expand Down
20 changes: 20 additions & 0 deletions AppHandling/Copy-AppFilesToFolder.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<#
.Synopsis
Copy App Files to Folder (supporting urls, .zip files and .app files)
.Description
.Parameter appFiles
Can be an array of appfiles, urls or zip files
.Parameter folder
Folder to copy the app files to
.Example
Copy-AppFilesToFolder -appFiles @("c:\temp\apps.zip", "c:\temp\app2.app", "https://github.com/org/repo/releases/download/2.0.200/project-branch-Apps-1.0.0.0.zip") -folder "c:\temp\appfiles"
#>
function Copy-AppFilesToFolder {
Param(
$appFiles,
[string] $folder
)

CopyAppFilesToFolder -appFiles $appFiles -folder $folder
}
Export-ModuleMember -Function Copy-AppFilesToFolder
21 changes: 21 additions & 0 deletions AppHandling/Create-SymbolsFileFromAppFile.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<#
.Synopsis
Create a Symbols only .app file from an .app file
.Description
.Parameter AppFile
Path of the application file which should be converted to symbols
.Parameter symbolsFile
Path of the symbols file which should be created
.Example
Create-SymbolsFileFromAppFile -appFile c:\temp\baseapp.app -symbolsFile c:\temp\baseapp.symbols.app
#>
function Create-SymbolsFileFromAppFile {
Param(
[Parameter(Mandatory=$true)]
[string] $appFile,
[Parameter(Mandatory=$true)]
[string] $symbolsFile
)
RunAlTool -arguments @('CreateSymbolPackage', """$appFile""", """$symbolsFile""")
}
Export-ModuleMember -Function Create-SymbolsFileFromAppFile
Loading

0 comments on commit 0b83925

Please sign in to comment.