mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2024-11-24 03:45:30 +00:00
Fix Unit Tests and Official Releases (#1854)
* Update Unit Tests * Update pester from 4 to 5 * Update compile and releases * Working on making release tags * Update release.yaml * Compile Winutil --------- Co-authored-by: ChrisTitusTech <ChrisTitusTech@users.noreply.github.com>
This commit is contained in:
parent
88a622c368
commit
9eceae6751
36
.github/workflows/release.yaml
vendored
36
.github/workflows/release.yaml
vendored
@ -10,12 +10,42 @@ jobs:
|
|||||||
build-runspace:
|
build-runspace:
|
||||||
runs-on: windows-latest
|
runs-on: windows-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
ref: ${{ github.head_ref }}
|
ref: ${{ github.head_ref }}
|
||||||
- name: Create local changes
|
- name: Create local changes
|
||||||
|
shell: pwsh
|
||||||
run: |
|
run: |
|
||||||
powershell.exe -f Compile.ps1
|
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process
|
||||||
- uses: stefanzweifel/git-auto-commit-action@v4.16.0
|
./Compile.ps1
|
||||||
|
continue-on-error: true
|
||||||
|
- name: Check for failure in the previous step
|
||||||
|
if: failure()
|
||||||
|
run: |
|
||||||
|
echo "Compile.ps1 failed to execute properly."
|
||||||
|
exit 1
|
||||||
|
- uses: stefanzweifel/git-auto-commit-action@v5
|
||||||
with:
|
with:
|
||||||
commit_message: Compile Winutil
|
commit_message: Compile Winutil
|
||||||
|
if: success()
|
||||||
|
|
||||||
|
create-release:
|
||||||
|
needs: build-runspace
|
||||||
|
runs-on: windows-latest
|
||||||
|
if: github.ref == 'refs/heads/main'
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: Get current date (PowerShell)
|
||||||
|
id: date
|
||||||
|
run: echo "CURRENT_DATE=$(powershell (Get-Date -Format 'yyyy-MM-dd').ToString())" >> $GITHUB_ENV
|
||||||
|
- name: Create Release and Upload Asset
|
||||||
|
id: create_release
|
||||||
|
uses: softprops/action-gh-release@v2
|
||||||
|
with:
|
||||||
|
tag_name: ${{ env.CURRENT_DATE }}
|
||||||
|
name: Release ${{ env.CURRENT_DATE }}
|
||||||
|
draft: false
|
||||||
|
prerelease: false
|
||||||
|
files: ./winutil.ps1
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
2
.github/workflows/unittests.yaml
vendored
2
.github/workflows/unittests.yaml
vendored
@ -33,7 +33,7 @@ jobs:
|
|||||||
- name: Run Pester tests
|
- name: Run Pester tests
|
||||||
run: |
|
run: |
|
||||||
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process
|
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process
|
||||||
Invoke-Pester -Path 'pester/*.Tests.ps1' -EnableExit
|
Invoke-Pester -Path 'pester/*.Tests.ps1' -Output Detailed
|
||||||
|
|
||||||
shell: pwsh
|
shell: pwsh
|
||||||
env:
|
env:
|
||||||
|
@ -1,44 +1,55 @@
|
|||||||
#===========================================================================
|
#===========================================================================
|
||||||
# Tests - Functions
|
# Tests - Functions
|
||||||
#===========================================================================
|
#===========================================================================
|
||||||
|
Describe "Comprehensive Checks for PS1 Files in Functions Folder" {
|
||||||
# Get all .ps1 files in the functions folder
|
BeforeAll {
|
||||||
$ps1Files = Get-ChildItem -Path ./functions -Filter *.ps1
|
# Get all .ps1 files in the functions folder
|
||||||
|
$ps1Files = Get-ChildItem -Path ./functions -Filter *.ps1 -Recurse
|
||||||
# Loop through each file
|
|
||||||
foreach ($file in $ps1Files) {
|
|
||||||
# Define the test name
|
|
||||||
$testName = "Syntax check for $($file.Name)"
|
|
||||||
|
|
||||||
# Define the test script
|
|
||||||
$testScript = {
|
|
||||||
# Import the script
|
|
||||||
. $file.FullName
|
|
||||||
|
|
||||||
# Check if any errors occurred
|
|
||||||
$scriptError = $error[0]
|
|
||||||
$scriptError | Should -Be $null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Add the test to the Pester test suite
|
foreach ($file in $ps1Files) {
|
||||||
Describe $testName $testScript
|
Context "Checking $($file.Name)" {
|
||||||
}
|
It "Should import without errors" {
|
||||||
|
{ . $file.FullName } | Should -Not -Throw
|
||||||
Describe "Functions"{
|
|
||||||
|
|
||||||
Get-ChildItem .\functions -Recurse -File | ForEach-Object {
|
|
||||||
|
|
||||||
context "$($psitem.BaseName)" {
|
|
||||||
BeforeEach -Scriptblock {
|
|
||||||
. $psitem.FullName
|
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Imports with no errors" -TestCases @{
|
It "Should have no syntax errors" {
|
||||||
basename = $($psitem.BaseName)
|
$syntaxErrors = $null
|
||||||
fullname = $psitem.FullName
|
$null = [System.Management.Automation.PSParser]::Tokenize((Get-Content -Path $file.FullName -Raw), [ref]$syntaxErrors)
|
||||||
} {
|
$syntaxErrors.Count | Should -Be 0
|
||||||
Get-ChildItem function:\$basename | Should -Not -BeNullOrEmpty
|
}
|
||||||
}
|
|
||||||
|
It "Should not use deprecated cmdlets or aliases" {
|
||||||
|
$content = Get-Content -Path $file.FullName -Raw
|
||||||
|
# Example check for a known deprecated cmdlet or alias
|
||||||
|
$content | Should -Not -Match 'DeprecatedCmdlet'
|
||||||
|
# Add more checks as needed
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Should follow naming conventions for functions" {
|
||||||
|
$functions = (Get-Command -Path $file.FullName).Name
|
||||||
|
foreach ($function in $functions) {
|
||||||
|
$function | Should -Match '^[a-z]+(-[a-z]+)*$' # Enforce lower-kebab-case
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Should define mandatory parameters for all functions" {
|
||||||
|
. $file.FullName
|
||||||
|
$functions = (Get-Command -Path $file.FullName).Name
|
||||||
|
foreach ($function in $functions) {
|
||||||
|
$parameters = (Get-Command -Name $function).Parameters.Values
|
||||||
|
$mandatoryParams = $parameters | Where-Object { $_.Attributes.Mandatory -eq $true }
|
||||||
|
$mandatoryParams.Count | Should -BeGreaterThan 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Should have all functions available after import" {
|
||||||
|
. $file.FullName
|
||||||
|
$functions = (Get-Command -Path $file.FullName).Name
|
||||||
|
foreach ($function in $functions) {
|
||||||
|
{ Get-Command -Name $function -CommandType Function } | Should -Not -BeNullOrEmpty
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
11032
winutil.ps1
11032
winutil.ps1
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user