Skip to content

Commit

Permalink
Merge pull request #35 from theohbrothers/enhancement/ci-add-integrat…
Browse files Browse the repository at this point in the history
…ion-tests

Enhancement (ci): Add integration tests
  • Loading branch information
joeltimothyoh authored Sep 24, 2023
2 parents 9a42f04 + cc79ebe commit b1b4102
Show file tree
Hide file tree
Showing 6 changed files with 336 additions and 0 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/ci-master-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ jobs:
runs-on: windows-2019
steps:
- uses: actions/checkout@v3
- uses: actions/setup-dotnet@v3
with:
dotnet-version: '6'
- name: Powershell version
run: |
powershell -NoLogo -NonInteractive -NoProfile -Command '$PSVersionTable'
Expand All @@ -32,6 +35,12 @@ jobs:
image: mcr.microsoft.com/powershell:6.0.2-ubuntu-16.04
steps:
- uses: actions/checkout@v3
- name: Install wget
run: |
apt-get update && apt-get install -y wget
- uses: actions/setup-dotnet@v3
with:
dotnet-version: '6'
- name: Powershell version
run: |
pwsh -NoLogo -NonInteractive -NoProfile -Command '$PSVersionTable'
Expand All @@ -45,6 +54,12 @@ jobs:
image: mcr.microsoft.com/powershell:6.1.3-ubuntu-18.04
steps:
- uses: actions/checkout@v3
- name: Install wget
run: |
apt-get update && apt-get install -y wget
- uses: actions/setup-dotnet@v3
with:
dotnet-version: '6'
- name: Powershell version
run: |
pwsh -NoLogo -NonInteractive -NoProfile -Command '$PSVersionTable'
Expand All @@ -58,6 +73,12 @@ jobs:
image: mcr.microsoft.com/powershell:6.2.4-ubuntu-18.04
steps:
- uses: actions/checkout@v3
- name: Install wget
run: |
apt-get update && apt-get install -y wget
- uses: actions/setup-dotnet@v3
with:
dotnet-version: '6'
- name: Powershell version
run: |
pwsh -NoLogo -NonInteractive -NoProfile -Command '$PSVersionTable'
Expand All @@ -71,6 +92,12 @@ jobs:
image: mcr.microsoft.com/powershell:7.0.3-ubuntu-18.04
steps:
- uses: actions/checkout@v3
- name: Install wget
run: |
apt-get update && apt-get install -y wget
- uses: actions/setup-dotnet@v3
with:
dotnet-version: '6'
- name: Powershell version
run: |
pwsh -NoLogo -NonInteractive -NoProfile -Command '$PSVersionTable'
Expand All @@ -84,6 +111,12 @@ jobs:
image: mcr.microsoft.com/powershell:7.1.3-ubuntu-18.04
steps:
- uses: actions/checkout@v3
- name: Install wget
run: |
apt-get update && apt-get install -y wget
- uses: actions/setup-dotnet@v3
with:
dotnet-version: '6'
- name: Powershell version
run: |
pwsh -NoLogo -NonInteractive -NoProfile -Command '$PSVersionTable'
Expand All @@ -97,6 +130,12 @@ jobs:
image: mcr.microsoft.com/powershell:7.2.2-ubuntu-20.04
steps:
- uses: actions/checkout@v3
- name: Install wget
run: |
apt-get update && apt-get install -y wget
- uses: actions/setup-dotnet@v3
with:
dotnet-version: '6'
- name: Powershell version
run: |
pwsh -NoLogo -NonInteractive -NoProfile -Command '$PSVersionTable'
Expand All @@ -110,6 +149,12 @@ jobs:
image: mcr.microsoft.com/powershell:7.3-ubuntu-20.04
steps:
- uses: actions/checkout@v3
- name: Install wget
run: |
apt-get update && apt-get install -y wget
- uses: actions/setup-dotnet@v3
with:
dotnet-version: '6'
- name: Powershell version
run: |
pwsh -NoLogo -NonInteractive -NoProfile -Command '$PSVersionTable'
Expand Down
57 changes: 57 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"inputs": [
{
"id": "NUGET_API_KEY",
"description": "NUGET_API_KEY?",
"type": "promptString",
"default": "xxx",
},
{
"id": "MODULE_VERSION",
"description": "MODULE_VERSION?",
"type": "promptString",
"default": "0.0.0",
},
],
"tasks": [
{
"label": "Test (pwsh)",
"type": "shell",
"command": "pwsh -Command test/test.ps1",
"group": "build"
},
{
"label": "Test (powershell)",
"type": "shell",
"command": "powershell -Command test/test.ps1",
"group": "build"
},
{
"label": "Build: Generate module manifest",
"type": "shell",
"command": "MODULE_VERSION=${input:MODULE_VERSION} pwsh src/PSModulePublisher/Public/Invoke-Build.ps1",
"group": "build"
},
{
"label": "Publish module (dry run)",
"dependsOn":[
"Build: Generate module manifest"
],
"type": "shell",
"command": "MODULE_NAME=$(basename $(pwd)); NUGET_API_KEY=${input:NUGET_API_KEY} MODULE_VERSION=${input:MODULE_VERSION} pwsh src/PSModulePublisher/Public/Invoke-Publish.ps1 -ModuleManifestPath src/$MODULE_NAME/$MODULE_NAME.psd1 -Repository PSGallery -DryRun",
"group": "build"
},
{
"label": "Publish module",
"dependsOn":[
"Build: Generate module manifest"
],
"type": "shell",
"command": "MODULE_NAME=$(basename $(pwd)); NUGET_API_KEY=${input:NUGET_API_KEY} MODULE_VERSION=${input:MODULE_VERSION} pwsh src/PSModulePublisher/Public/Invoke-Publish.ps1 -ModuleManifestPath src/$MODULE_NAME/$MODULE_NAME.psd1 -Repository PSGallery",
"group": "build"
},
]
}
24 changes: 24 additions & 0 deletions src/PSModulePublisher/Invoke-PSModulePublisher.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Describe "Invoke-PSModulePublisher" -Tag 'Integration' {
BeforeEach {
$moduleDir = $PSScriptRoot
$mockModuleRepoDir = (Resolve-Path "$PSScriptRoot/../../test/Mock-Module").Path
$mockModuleManifest = (Resolve-Path "$mockModuleRepoDir/src/Mock-Module/Mock-Module.psd1").Path
Push-Location $mockModuleRepoDir
$env:PROJECT_BASE_DIR = $mockModuleRepoDir # Override the project base
}
AfterEach {
Pop-Location
}
It "Runs Invoke-Build.ps1" {
$moduleManifest = & "$moduleDir/Public/Invoke-Build.ps1"
$moduleManifest | Should -Be $mockModuleManifest
}
It "Runs Invoke-Publish.ps1" {
$env:MODULE_VERSION = '0.0.0'
$env:NUGET_API_KEY = 'xxx'
& "$moduleDir/Public/Invoke-Publish.ps1" -ModuleManifestPath $mockModuleManifest -Repository PSGallery -DryRun
}
It "Runs Invoke-Test.ps1" {
& "$moduleDir/Public/Invoke-Test.ps1" -ModuleManifestPath $mockModuleManifest
}
}
62 changes: 62 additions & 0 deletions test/Mock-Module/build/definitions/modulemanifest.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# - Initial setup: Fill in the GUID value. Generate one by running the command 'New-GUID'. Then fill in all relevant details.
# - Ensure all relevant details are updated prior to publishing each version of the module.
# - To simulate generation of the manifest based on this definition, run the included development entrypoint script Invoke-PSModulePublisher.ps1.
# - To publish the module, tag the associated commit and push the tag.
@{
RootModule = 'Mock-Module.psm1'
# ModuleVersion = '' # Value will be set for each publication based on the tag ref. Defaults to '0.0.0' in development environments and regular CI builds
GUID = 'e3df9fcc-9f83-4c93-9d06-4d2523376af7'
Author = 'The Oh Brothers'
CompanyName = 'The Oh Brothers'
Copyright = '(c) 2023 The Oh Brothers'
Description = 'Some description'
PowerShellVersion = '3.0'
# PowerShellHostName = ''
# PowerShellHostVersion = ''
# DotNetFrameworkVersion = ''
# CLRVersion = ''
# ProcessorArchitecture = ''
# RequiredModules = @(
# @{
# ModuleName = "PSMockModule"
# RequiredVersion = '0.0.2'
# }
# )
# RequiredAssemblies = @()
# ScriptsToProcess = @()
# TypesToProcess = @()
# FormatsToProcess = @()
# NestedModules = @()
FunctionsToExport = @(
Get-ChildItem $PSScriptRoot/../../src/Mock-Module/Public -Exclude *.Tests.ps1 | % { $_.BaseName }
)
CmdletsToExport = @()
VariablesToExport = @()
AliasesToExport = @()
# DscResourcesToExport = @()
# ModuleList = @()
# FileList = @(
# & {
# Set-Location $PSScriptRoot/../../../src/Generate-DockerImageVariants/
# Get-ChildItem -File -Recurse -Force | Resolve-Path -Relative
# Set-Location -
# }
# )
PrivateData = @{
# PSData = @{ # Properties within PSData will be correctly added to the manifest via Update-ModuleManifest without the PSData key. Leave the key commented out.
Tags = @(
'mock'
'module'
)
LicenseUri = 'https://raw.githubusercontent.com/theohbrothers/Mock-Module/master/LICENSE'
ProjectUri = 'https://github.com/theohbrothers/Mock-Module'
# IconUri = ''
# ReleaseNotes = ''
# Prerelease = ''
# RequireLicenseAcceptance = $false
ExternalModuleDependencies = @()
# }
# HelpInfoURI = ''
# DefaultCommandPrefix = ''
}
}
132 changes: 132 additions & 0 deletions test/Mock-Module/src/Mock-Module/Mock-Module.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
#
# Module manifest for module 'Mock-Module'
#
# Generated by: The Oh Brothers
#
# Generated on: 09/08/2023
#

@{

# Script module or binary module file associated with this manifest.
RootModule = 'Mock-Module.psm1'

# Version number of this module.
ModuleVersion = '0.0.0'

# Supported PSEditions
# CompatiblePSEditions = @()

# ID used to uniquely identify this module
GUID = 'e3df9fcc-9f83-4c93-9d06-4d2523376af7'

# Author of this module
Author = 'The Oh Brothers'

# Company or vendor of this module
CompanyName = 'The Oh Brothers'

# Copyright statement for this module
Copyright = '(c) 2023 The Oh Brothers'

# Description of the functionality provided by this module
Description = 'Some description'

# Minimum version of the PowerShell engine required by this module
PowerShellVersion = '3.0'

# Name of the PowerShell host required by this module
# PowerShellHostName = ''

# Minimum version of the PowerShell host required by this module
# PowerShellHostVersion = ''

# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
# DotNetFrameworkVersion = ''

# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
# ClrVersion = ''

# Processor architecture (None, X86, Amd64) required by this module
# ProcessorArchitecture = ''

# Modules that must be imported into the global environment prior to importing this module
# RequiredModules = @()

# Assemblies that must be loaded prior to importing this module
# RequiredAssemblies = @()

# Script files (.ps1) that are run in the caller's environment prior to importing this module.
# ScriptsToProcess = @()

# Type files (.ps1xml) to be loaded when importing this module
# TypesToProcess = @()

# Format files (.ps1xml) to be loaded when importing this module
# FormatsToProcess = @()

# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
# NestedModules = @()

# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
FunctionsToExport = @()

# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
CmdletsToExport = @()

# Variables to export from this module
# VariablesToExport = @()

# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
AliasesToExport = @()

# DSC resources to export from this module
# DscResourcesToExport = @()

# List of all modules packaged with this module
# ModuleList = @()

# List of all files packaged with this module
# FileList = @()

# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
PrivateData = @{

PSData = @{

# Tags applied to this module. These help with module discovery in online galleries.
Tags = 'mock','module'

# A URL to the license for this module.
LicenseUri = 'https://raw.githubusercontent.com/theohbrothers/Mock-Module/master/LICENSE'

# A URL to the main website for this project.
ProjectUri = 'https://github.com/theohbrothers/Mock-Module'

# A URL to an icon representing this module.
# IconUri = ''

# ReleaseNotes of this module
# ReleaseNotes = ''

# Prerelease string of this module
# Prerelease = ''

# Flag to indicate whether the module requires explicit user acceptance for install/update/save
# RequireLicenseAcceptance = $false

# External dependent modules of this module
# ExternalModuleDependencies = @()

} # End of PSData hashtable

} # End of PrivateData hashtable

# HelpInfo URI of this module
# HelpInfoURI = ''

# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
# DefaultCommandPrefix = ''

}

16 changes: 16 additions & 0 deletions test/Mock-Module/src/Mock-Module/Mock-Module.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
$script:MODULE_BASE_DIR = Split-Path $MyInvocation.MyCommand.Path -Parent
# $script:MODULE_HELPER_DIR = Join-Path $MODULE_BASE_DIR 'Helper'
# $script:MODULE_PRIVATE_DIR = Join-Path $MODULE_BASE_DIR 'Private'
# $script:MODULE_PUBLIC_DIR = Join-Path $MODULE_BASE_DIR 'Public'

# Get-ChildItem "$script:MODULE_HELPER_DIR/*.ps1" -Exclude *.Tests.ps1 | % {
# . $_.FullName
# }

# Get-ChildItem "$script:MODULE_PRIVATE_DIR/*.ps1" -Exclude *.Tests.ps1 | % {
# . $_.FullName
# }

# Get-ChildItem "$script:MODULE_PUBLIC_DIR/*.ps1" -Exclude *.Tests.ps1 | % {
# . $_.FullName
# }

0 comments on commit b1b4102

Please sign in to comment.