From 9b1830032f7de721574c0836c4b89eea869fcb56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olav=20R=C3=B8nnestad=20Birkeland?= <6450056+o-l-a-v@users.noreply.github.com> Date: Fri, 8 Nov 2024 14:53:31 +0100 Subject: [PATCH 1/9] Fixed JSON --- snippets/PowerShell.json | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/snippets/PowerShell.json b/snippets/PowerShell.json index bd478f1ff3..5e25f10286 100644 --- a/snippets/PowerShell.json +++ b/snippets/PowerShell.json @@ -162,24 +162,23 @@ ] }, "Foreach with Progress": { - "prefix": "foreach-progress", + "prefix": "foreach-progress", "description": "Insert a foreach loop with Write-Progress initialized", - "body": [ -\\$progPercent = \"{0:n2}\" -f ([math]::round(\\$i/\\$array.count,4) * 100)", - -Write-Progress -Activity \"${3:activityName}\" -Status \"\\$i of \\$array.count - \\$progPercent% Complete:\" -PercentComplete \\$progPercent", - "\\$i = 1", - "foreach ($${2:item} in $${1:array}) {", - " \\$progPercent = \"{0:n2}\" -f ([math]::round(\\$i/\\$total,4) * 100)", - " Write-Progress -Activity \"${3:activityName}\" -Status \"\\$i of \\$total - \\$progPercent% Complete:\" -PercentComplete \\$progPercent", - " # Insert Code Here", - " ${0}", - " ", - " \\$i++", - "}", - "" - ] - }, + "body": [ + "\\$progPercent = \"{0:n2}\" -f ([math]::round(\\$i/\\$array.count,4) * 100)", + "Write-Progress -Activity \"${3:activityName}\" -Status \"\\$i of \\$array.count - \\$progPercent% Complete:\" -PercentComplete \\$progPercent", + "\\$i = 1", + "foreach ($${2:item} in $${1:array}) {", + " \\$progPercent = \"{0:n2}\" -f ([math]::round(\\$i/\\$total,4) * 100)", + " Write-Progress -Activity \"${3:activityName}\" -Status \"\\$i of \\$total - \\$progPercent% Complete:\" -PercentComplete \\$progPercent", + " # Insert Code Here", + " ${0}", + " ", + " \\$i++", + "}", + "" + ] + }, "ForEach-Object -Parallel": { "prefix": "foreach-parallel", "description": "[PS 7+] Process multiple objects in parallel using runspaces. This has some limitations compared to a regular ForEach-Object. More: Get-Help ForEach-Object", From 338b9d05f8d79fff326cc2400fce8fc91d53e81b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olav=20R=C3=B8nnestad=20Birkeland?= <6450056+o-l-a-v@users.noreply.github.com> Date: Fri, 8 Nov 2024 14:53:46 +0100 Subject: [PATCH 2/9] Added test for making sure all JSON files are valid JSON --- .github/workflows/ci-test.yml | 12 ++++++--- tools/testValidJson.ps1 | 46 +++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 tools/testValidJson.ps1 diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml index 1b448c7eb4..96692b601b 100644 --- a/.github/workflows/ci-test.yml +++ b/.github/workflows/ci-test.yml @@ -2,19 +2,19 @@ name: CI Tests on: push: - branches: [ main ] + branches: [main] pull_request: # The branches below must be a subset of the branches above - branches: [ main ] + branches: [main] merge_group: - types: [ checks_requested ] + types: [checks_requested] jobs: ci: name: node strategy: matrix: - os: [ windows-latest, macos-latest, ubuntu-latest ] + os: [windows-latest, macos-latest, ubuntu-latest] runs-on: ${{ matrix.os }} env: DOTNET_NOLOGO: true @@ -33,6 +33,10 @@ jobs: with: path: vscode-powershell + - name: Make sure JSON files are valid + shell: pwsh + run: ./vscode-powershell/tools/testValidJson.ps1 + - name: Install dotnet uses: actions/setup-dotnet@v4 with: diff --git a/tools/testValidJson.ps1 b/tools/testValidJson.ps1 new file mode 100644 index 0000000000..4151476aba --- /dev/null +++ b/tools/testValidJson.ps1 @@ -0,0 +1,46 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. +<# + .SYNOPSIS + Get all JSON files recursively and test if they are valid by trying to import them. + + .EXAMPLE + & $psEditor.GetEditorContext().CurrentFile.Path -WorkingDir '.\' +#> + +# Input and expected output +[OutputType([System.Void])] +Param( + [Parameter()] + [ValidateScript({[System.IO.Directory]::Exists($_)})] + [string] $WorkingDir = '.\' +) + +# PowerShell preferences +$ErrorActionPreference = 'Stop' + +# Try to import all JSON files in the repo +$TestValidJson = [PSCustomObject[]]( + [System.IO.Directory]::GetFiles($WorkingDir,'*.json',[System.IO.SearchOption]::AllDirectories).ForEach{ + [PSCustomObject]@{ + 'Path' = [string] $_ + 'IsValidJson' = [bool]$( + Try { + $null = ConvertFrom-Json -InputObject (Get-Content -Raw -Path $_) -AsHashtable + $? + } + Catch { + $false + } + ) + } + } +) + +# Output results +$TestValidJson | Format-Table + +# Throw if errors were found +if ($TestValidJson.Where{-not $_.'IsValidJson'}.'Count' -gt 0) { + Throw ('Found {0} non-valid JSON file(s).' -f $TestValidJson.Where{-not $_.'IsValidJson'}.'Count') +} From bac4de0ccb5f36f3bd4eb0ed04e3515d6d10e02e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olav=20R=C3=B8nnestad=20Birkeland?= <6450056+o-l-a-v@users.noreply.github.com> Date: Fri, 8 Nov 2024 14:55:12 +0100 Subject: [PATCH 3/9] Run in correct dir --- .github/workflows/ci-test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml index 96692b601b..7f5e52e0eb 100644 --- a/.github/workflows/ci-test.yml +++ b/.github/workflows/ci-test.yml @@ -33,9 +33,10 @@ jobs: with: path: vscode-powershell - - name: Make sure JSON files are valid + - name: Make sure JSON files in ./vscode-powershell/ are valid shell: pwsh run: ./vscode-powershell/tools/testValidJson.ps1 + working-directory: vscode-powershell - name: Install dotnet uses: actions/setup-dotnet@v4 From f54c79ccab9f0e69e3656500dceee195b15a4b86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olav=20R=C3=B8nnestad=20Birkeland?= <6450056+o-l-a-v@users.noreply.github.com> Date: Wed, 13 Nov 2024 19:16:06 +0100 Subject: [PATCH 4/9] Simplify title of the new step Co-authored-by: Andy Jordan <2226434+andyleejordan@users.noreply.github.com> --- .github/workflows/ci-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml index 7f5e52e0eb..406296e5ed 100644 --- a/.github/workflows/ci-test.yml +++ b/.github/workflows/ci-test.yml @@ -33,7 +33,7 @@ jobs: with: path: vscode-powershell - - name: Make sure JSON files in ./vscode-powershell/ are valid + - name: Validate JSON files shell: pwsh run: ./vscode-powershell/tools/testValidJson.ps1 working-directory: vscode-powershell From 608bbca52c1b57e2592fcd0e7ba89b2b761ae433 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olav=20R=C3=B8nnestad=20Birkeland?= <6450056+o-l-a-v@users.noreply.github.com> Date: Wed, 13 Nov 2024 19:16:57 +0100 Subject: [PATCH 5/9] Fix path double nesting Co-authored-by: Andy Jordan <2226434+andyleejordan@users.noreply.github.com> --- .github/workflows/ci-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml index 406296e5ed..5eecfeee8d 100644 --- a/.github/workflows/ci-test.yml +++ b/.github/workflows/ci-test.yml @@ -35,7 +35,7 @@ jobs: - name: Validate JSON files shell: pwsh - run: ./vscode-powershell/tools/testValidJson.ps1 + run: ./tools/testValidJson.ps1 working-directory: vscode-powershell - name: Install dotnet From 9290471f5d5f8f3f2f3edbde7f55f5372a288f7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olav=20R=C3=B8nnestad=20Birkeland?= <6450056+o-l-a-v@users.noreply.github.com> Date: Wed, 13 Nov 2024 19:17:13 +0100 Subject: [PATCH 6/9] Add spaces after commas Co-authored-by: Andy Jordan <2226434+andyleejordan@users.noreply.github.com> --- tools/testValidJson.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testValidJson.ps1 b/tools/testValidJson.ps1 index 4151476aba..4b02e9e629 100644 --- a/tools/testValidJson.ps1 +++ b/tools/testValidJson.ps1 @@ -21,7 +21,7 @@ $ErrorActionPreference = 'Stop' # Try to import all JSON files in the repo $TestValidJson = [PSCustomObject[]]( - [System.IO.Directory]::GetFiles($WorkingDir,'*.json',[System.IO.SearchOption]::AllDirectories).ForEach{ + [System.IO.Directory]::GetFiles($WorkingDir, '*.json', [System.IO.SearchOption]::AllDirectories).ForEach{ [PSCustomObject]@{ 'Path' = [string] $_ 'IsValidJson' = [bool]$( From 5c1997f524df6e7268168089af1bbb98523e7632 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olav=20R=C3=B8nnestad=20Birkeland?= <6450056+o-l-a-v@users.noreply.github.com> Date: Wed, 13 Nov 2024 19:43:29 +0100 Subject: [PATCH 7/9] =?UTF-8?q?Use=20$PWD=20instead=20of=20'.\'=20for=20cu?= =?UTF-8?q?rrent=20dir=20=F0=9F=90=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/testValidJson.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testValidJson.ps1 b/tools/testValidJson.ps1 index 4b02e9e629..494f03f027 100644 --- a/tools/testValidJson.ps1 +++ b/tools/testValidJson.ps1 @@ -5,7 +5,7 @@ Get all JSON files recursively and test if they are valid by trying to import them. .EXAMPLE - & $psEditor.GetEditorContext().CurrentFile.Path -WorkingDir '.\' + & $psEditor.GetEditorContext().CurrentFile.Path -WorkingDir $PWD #> # Input and expected output @@ -13,7 +13,7 @@ Param( [Parameter()] [ValidateScript({[System.IO.Directory]::Exists($_)})] - [string] $WorkingDir = '.\' + [string] $WorkingDir = $PWD ) # PowerShell preferences From 5e9b7f1f856cc59b16eb94e0c631b3bd2b17aa10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olav=20R=C3=B8nnestad=20Birkeland?= <6450056+o-l-a-v@users.noreply.github.com> Date: Wed, 13 Nov 2024 20:16:03 +0100 Subject: [PATCH 8/9] Only test the snippets JSON file --- .github/workflows/ci-test.yml | 4 +-- tools/testValidJson.ps1 | 46 ----------------------------------- 2 files changed, 2 insertions(+), 48 deletions(-) delete mode 100644 tools/testValidJson.ps1 diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml index 5eecfeee8d..c4b5df746b 100644 --- a/.github/workflows/ci-test.yml +++ b/.github/workflows/ci-test.yml @@ -33,9 +33,9 @@ jobs: with: path: vscode-powershell - - name: Validate JSON files + - name: Validate snippets JSON files shell: pwsh - run: ./tools/testValidJson.ps1 + run: $null = ConvertFrom-Json -InputObject (Get-Content -Raw -Path './snippets/PowerShell.json') working-directory: vscode-powershell - name: Install dotnet diff --git a/tools/testValidJson.ps1 b/tools/testValidJson.ps1 deleted file mode 100644 index 494f03f027..0000000000 --- a/tools/testValidJson.ps1 +++ /dev/null @@ -1,46 +0,0 @@ -# Copyright (c) Microsoft Corporation. -# Licensed under the MIT License. -<# - .SYNOPSIS - Get all JSON files recursively and test if they are valid by trying to import them. - - .EXAMPLE - & $psEditor.GetEditorContext().CurrentFile.Path -WorkingDir $PWD -#> - -# Input and expected output -[OutputType([System.Void])] -Param( - [Parameter()] - [ValidateScript({[System.IO.Directory]::Exists($_)})] - [string] $WorkingDir = $PWD -) - -# PowerShell preferences -$ErrorActionPreference = 'Stop' - -# Try to import all JSON files in the repo -$TestValidJson = [PSCustomObject[]]( - [System.IO.Directory]::GetFiles($WorkingDir, '*.json', [System.IO.SearchOption]::AllDirectories).ForEach{ - [PSCustomObject]@{ - 'Path' = [string] $_ - 'IsValidJson' = [bool]$( - Try { - $null = ConvertFrom-Json -InputObject (Get-Content -Raw -Path $_) -AsHashtable - $? - } - Catch { - $false - } - ) - } - } -) - -# Output results -$TestValidJson | Format-Table - -# Throw if errors were found -if ($TestValidJson.Where{-not $_.'IsValidJson'}.'Count' -gt 0) { - Throw ('Found {0} non-valid JSON file(s).' -f $TestValidJson.Where{-not $_.'IsValidJson'}.'Count') -} From ac2608ab6006951f51dc2781680316817175b67c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olav=20R=C3=B8nnestad=20Birkeland?= <6450056+o-l-a-v@users.noreply.github.com> Date: Wed, 13 Nov 2024 20:16:47 +0100 Subject: [PATCH 9/9] Oops, typo --- .github/workflows/ci-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml index c4b5df746b..8d416d460a 100644 --- a/.github/workflows/ci-test.yml +++ b/.github/workflows/ci-test.yml @@ -33,7 +33,7 @@ jobs: with: path: vscode-powershell - - name: Validate snippets JSON files + - name: Validate snippets JSON file shell: pwsh run: $null = ConvertFrom-Json -InputObject (Get-Content -Raw -Path './snippets/PowerShell.json') working-directory: vscode-powershell