mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2024-11-13 22:25:51 -06: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:
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ github.head_ref }}
|
||||
- name: Create local changes
|
||||
shell: pwsh
|
||||
run: |
|
||||
powershell.exe -f Compile.ps1
|
||||
- uses: stefanzweifel/git-auto-commit-action@v4.16.0
|
||||
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process
|
||||
./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:
|
||||
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
|
||||
run: |
|
||||
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process
|
||||
Invoke-Pester -Path 'pester/*.Tests.ps1' -EnableExit
|
||||
Invoke-Pester -Path 'pester/*.Tests.ps1' -Output Detailed
|
||||
|
||||
shell: pwsh
|
||||
env:
|
||||
|
@ -1,44 +1,55 @@
|
||||
#===========================================================================
|
||||
# Tests - Functions
|
||||
#===========================================================================
|
||||
|
||||
# Get all .ps1 files in the functions folder
|
||||
$ps1Files = Get-ChildItem -Path ./functions -Filter *.ps1
|
||||
|
||||
# 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
|
||||
Describe "Comprehensive Checks for PS1 Files in Functions Folder" {
|
||||
BeforeAll {
|
||||
# Get all .ps1 files in the functions folder
|
||||
$ps1Files = Get-ChildItem -Path ./functions -Filter *.ps1 -Recurse
|
||||
}
|
||||
|
||||
# Add the test to the Pester test suite
|
||||
Describe $testName $testScript
|
||||
}
|
||||
|
||||
Describe "Functions"{
|
||||
|
||||
Get-ChildItem .\functions -Recurse -File | ForEach-Object {
|
||||
|
||||
context "$($psitem.BaseName)" {
|
||||
BeforeEach -Scriptblock {
|
||||
. $psitem.FullName
|
||||
foreach ($file in $ps1Files) {
|
||||
Context "Checking $($file.Name)" {
|
||||
It "Should import without errors" {
|
||||
{ . $file.FullName } | Should -Not -Throw
|
||||
}
|
||||
|
||||
It "Imports with no errors" -TestCases @{
|
||||
basename = $($psitem.BaseName)
|
||||
fullname = $psitem.FullName
|
||||
} {
|
||||
Get-ChildItem function:\$basename | Should -Not -BeNullOrEmpty
|
||||
}
|
||||
It "Should have no syntax errors" {
|
||||
$syntaxErrors = $null
|
||||
$null = [System.Management.Automation.PSParser]::Tokenize((Get-Content -Path $file.FullName -Raw), [ref]$syntaxErrors)
|
||||
$syntaxErrors.Count | Should -Be 0
|
||||
}
|
||||
|
||||
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