Skip to content

Commit

Permalink
Add formatter to RestSetAcls (#243)
Browse files Browse the repository at this point in the history
* Refactor build tools into modules

* Add PowerShell formatting test

* Format all RestSetAcls code

* Remove lint.ps1

* Fix github actions job title

* Add recommendation to configure format-on-save
  • Loading branch information
MaximeKjaer authored Dec 13, 2024
1 parent a15a0e8 commit 3be8c38
Show file tree
Hide file tree
Showing 17 changed files with 473 additions and 319 deletions.
23 changes: 19 additions & 4 deletions .github/workflows/RestSetAcls.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,23 @@ jobs:
- name: Run all Pester tests
run: |
.\init.ps1
.\test.ps1
Test
test-format:
name: Test PowerShell formatting
runs-on: windows-latest
defaults:
run:
working-directory: .\RestSetAcls
shell: pwsh
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Test PowerShell formatting
run: |
.\init.ps1
Test-Format
Check-manifest:
name: Check .psd1 manifest file
runs-on: windows-latest
Expand All @@ -37,7 +52,7 @@ jobs:
- name: Check .psd1 file with Test-ModuleManifest
run: |
.\init.ps1
.\check-manifest.ps1
Test-Manifest
lint-with-PSScriptAnalyzer:
name: Install and run PSScriptAnalyzer
Expand All @@ -51,4 +66,4 @@ jobs:
- name: Lint with PSScriptAnalyzer
run: |
.\init.ps1
.\lint.ps1
Lint
52 changes: 47 additions & 5 deletions RestSetAcls/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,69 @@
> These instructions are only meant for contributors to this project.
> If you want to use the script, refer to the README.
## Editor configuration

### VS Code

This module has PR validations that enforce formatting rules, so it's recommended to configure VS Code to format on save, to ensure that your changes are always formatted correctly.

## Installing development dependencies

```powershell
.\init.ps1
```

## Running unit tests
## Testing

### Run unit tests

```powershell
Test
```

### Test formatting

```powershell
Test-Format
```

### Test module manifest

```powershell
Test-Manifest
```

### Test all the above

```powershell
Test-All
```

## Format files

```powershell
.\test.ps1
Format
```

## Lint

```powershell
Lint
```

## Publishing the module locally

This is a useful test before publishing to the PSGallery.

```powershell
.\publish-local.ps1
Import-Module .\publish-tools.psm1
Publish-Local
Install-Module RestSetAcls -Repository LocalRepo
Uninstall-Module RestSetAcls
.\unpublish-local.ps1
Unpublish-Local
```

## Publishing the module to the PSGallery
Expand All @@ -36,7 +76,9 @@ Uninstall-Module RestSetAcls
1. Run the following command:

```powershell
.\publish-psgallery.ps1 -apiKey "<api-key>"
Import-Module .\publish-tools.psm1
Publish-PSGallery -apiKey "<api-key>"
```
## Setting up an E2E test run
Expand Down
23 changes: 14 additions & 9 deletions RestSetAcls/RestSetAcls/PrintUtils.ps1
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
function Ask([Parameter(Mandatory=$false)][string] $question)
{
function Ask([Parameter(Mandatory = $false)][string] $question) {
while ($true) {
$yn = Read-Host "${question} [Y/n]"
$yn = $yn.Trim().ToLower()
if ($yn -eq 'n') {
return $false
} elseif ($yn -eq '' -or $yn -eq 'y') {
}
elseif ($yn -eq '' -or $yn -eq 'y') {
return $true
}
Write-Host "Invalid answer '$yn'. Answer with either 'y' or 'n'" -ForegroundColor Red
Expand Down Expand Up @@ -35,7 +35,8 @@ function Write-DoneHeader {
if (Get-SpecialCharactersPrintable) {
$checkmark = [System.Char]::ConvertFromUtf32([System.Convert]::ToInt32("2713", 16))
Write-Host "($checkmark) Done: " -ForegroundColor Green -NoNewline
} else {
}
else {
Write-Host "Done: " -ForegroundColor Green -NoNewline
}
}
Expand All @@ -44,7 +45,8 @@ function Write-PartialHeader {
if (Get-SpecialCharactersPrintable) {
$cross = [System.Char]::ConvertFromUtf32([System.Convert]::ToInt32("2717", 16))
Write-Host "($cross) Partial: " -ForegroundColor Yellow -NoNewline
} else {
}
else {
Write-Host "Partial: " -ForegroundColor Yellow -NoNewline
}
}
Expand All @@ -53,7 +55,8 @@ function Write-FailedHeader {
if (Get-SpecialCharactersPrintable) {
$cross = [System.Char]::ConvertFromUtf32([System.Convert]::ToInt32("2717", 16))
Write-Host "($cross) Failed: " -ForegroundColor Red -NoNewline
} else {
}
else {
Write-Host "Failed: " -ForegroundColor Red -NoNewline
}
}
Expand All @@ -62,17 +65,18 @@ function Write-WarningHeader {
if (Get-SpecialCharactersPrintable) {
$warning = [System.Char]::ConvertFromUtf32([System.Convert]::ToInt32("26A0", 16))
Write-Host "($warning) Warning: " -ForegroundColor Yellow -NoNewline
} else {
}
else {
Write-Host "Warning: " -ForegroundColor Yellow -NoNewline
}
}

function Write-Failure {
param (
[Parameter(Mandatory=$true, Position=0)]
[Parameter(Mandatory = $true, Position = 0)]
[string]$Overview,

[Parameter(Mandatory=$false)]
[Parameter(Mandatory = $false)]
[string]$Details = $null
)

Expand All @@ -83,3 +87,4 @@ function Write-Failure {
Write-Host $Details -ForegroundColor Red
}
}

Loading

0 comments on commit 3be8c38

Please sign in to comment.