Skip to content

Commit

Permalink
Merge pull request #37 from karthickgandhiTV/main
Browse files Browse the repository at this point in the history
Final version to merge
  • Loading branch information
karthickgandhiTV authored Sep 19, 2023
2 parents 6c219bd + 9f30e0a commit 4d70b5d
Show file tree
Hide file tree
Showing 326 changed files with 5,914 additions and 1,789 deletions.
80 changes: 40 additions & 40 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,48 @@ name: CI

# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches: [ main ]
pull_request:
branches: [ main ]
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches: [main]
pull_request:
branches: [main]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
verify:
runs-on: ubuntu-latest
verify:
runs-on: windows-latest

steps:
# Checks-out the repository under $GITHUB_WORKSPACE, so the job can access it
- uses: actions/checkout@v3
steps:
# Checks-out the repository under $GITHUB_WORKSPACE, so the job can access it
- uses: actions/checkout@v3

# Print Powershell version
- name: Powershell Environment
shell: pwsh
run: |
$PSVersionTable
# Run linter
- name: Run linter (via PSScriptAnalyzer)
shell: pwsh
run: |
$ProgressPreference = 'SilentlyContinue'
$ErrorActionPreference = 'Stop'
Install-Module -Name PSScriptAnalyzer -SkipPublisherCheck -Scope CurrentUser -MinimumVersion 1.19.1 -Force -Verbose
Invoke-ScriptAnalyzer -Path $env:GITHUB_WORKSPACE -Recurse -Settings (Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath 'PSScriptAnalyzerSettings.psd1') -ReportSummary -EnableExit
# Run tests
- name: Run tests (via Pester)
shell: pwsh
run: |
$ProgressPreference = 'SilentlyContinue'
Install-Module -Name Pester -SkipPublisherCheck -Scope CurrentUser -MinimumVersion 5.1.1 -Force -Verbose
Invoke-Pester -Path $env:GITHUB_WORKSPACE -Output Detailed -CI
# Build package
- name: Package Build
shell: pwsh
run: |
$ProgressPreference = 'SilentlyContinue'
$ErrorActionPreference = 'Stop'
Install-Module -Name platyPS, BuildHelpers -SkipPublisherCheck -Scope CurrentUser -Force
& $env:GITHUB_WORKSPACE/Build/New-TeamViewerPSPackage.ps1 -Verbose
# Print Powershell version
- name: Powershell Environment
shell: pwsh
run: |
$PSVersionTable
# Run linter
- name: Run linter (via PSScriptAnalyzer)
shell: pwsh
run: |
$ProgressPreference = 'SilentlyContinue'
$ErrorActionPreference = 'Stop'
Install-Module -Name PSScriptAnalyzer -SkipPublisherCheck -Scope CurrentUser -MinimumVersion 1.19.1 -Force -Verbose
Invoke-ScriptAnalyzer -Path $env:GITHUB_WORKSPACE -Recurse -Settings (Join-Path -Path $env:GITHUB_WORKSPACE/Linters -ChildPath 'PSScriptAnalyzer.psd1') -ReportSummary -EnableExit
# Run tests
- name: Run tests (via Pester)
shell: pwsh
run: |
$ProgressPreference = 'SilentlyContinue'
Install-Module -Name Pester -SkipPublisherCheck -Scope CurrentUser -MinimumVersion 5.1.1 -Force -Verbose
Invoke-Pester -Path $env:GITHUB_WORKSPACE -Output Detailed -CI
# Build package
- name: Package Build
shell: pwsh
run: |
$ProgressPreference = 'SilentlyContinue'
$ErrorActionPreference = 'Stop'
Install-Module -Name platyPS, BuildHelpers -SkipPublisherCheck -Scope CurrentUser -Force
& $env:GITHUB_WORKSPACE/Build/New-Package.ps1 -Verbose
2 changes: 1 addition & 1 deletion .github/workflows/powershell-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ on:
jobs:
build:
name: PSScriptAnalyzer
runs-on: ubuntu-latest
runs-on: windows-latest
steps:
- uses: actions/checkout@v2

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/publish_production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
publish:
runs-on: ubuntu-latest
runs-on: windows-latest

steps:
- uses: actions/checkout@v2
Expand All @@ -17,7 +17,7 @@ jobs:
run: |
$ProgressPreference='SilentlyContinue'
Install-Module platyPS,BuildHelpers -Force -SkipPublisherCheck -Scope CurrentUser
& $env:GITHUB_WORKSPACE/Build/New-TeamViewerPSPackage.ps1 -Verbose
& $env:GITHUB_WORKSPACE/Build/New-Package.ps1 -Verbose
- name: Publish to powershellgallery.com
env:
Expand All @@ -26,5 +26,5 @@ jobs:
run: |
$ProgressPreference='SilentlyContinue'
Publish-Module `
-Path $env:GITHUB_WORKSPACE/BuildOutput/TeamViewerPS/ `
-Path $env:GITHUB_WORKSPACE/Build/Output/ `
-NuGetApiKey $env:NUGET_APIKEY_PRODUCTION
6 changes: 3 additions & 3 deletions .github/workflows/publish_testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:

jobs:
publish:
runs-on: ubuntu-latest
runs-on: windows-latest

steps:
- uses: actions/checkout@v2
Expand All @@ -15,7 +15,7 @@ jobs:
run: |
$ProgressPreference='SilentlyContinue'
Install-Module platyPS,BuildHelpers -Force -SkipPublisherCheck -Scope CurrentUser
& $env:GITHUB_WORKSPACE/Build/New-TeamViewerPSPackage.ps1 -Verbose
& $env:GITHUB_WORKSPACE/Build/New-Package.ps1 -Verbose
- name: Publish to poshtestgallery.com
env:
Expand All @@ -27,7 +27,7 @@ jobs:
-Name PSTestGallery `
-SourceLocation https://www.poshtestgallery.com/api/v2
Publish-Module `
-Path $env:GITHUB_WORKSPACE/BuildOutput/TeamViewerPS/ `
-Path $env:GITHUB_WORKSPACE/Build/Output/ `
-NuGetApiKey $env:NUGET_APIKEY_TESTING `
-Repository PSTestGallery `
-Force
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/BuildOutput
/Build/Output
File renamed without changes.
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"label": "Lint (via PSScriptAnalyzer)",
"type": "shell",
"command": "Invoke-ScriptAnalyzer -Path '${workspaceFolder}' -Severity Information, Warning, Error -Recurse",
"command": "Invoke-ScriptAnalyzer -Path '${workspaceFolder}/Linters' -Severity Information, Warning, Error -Recurse",
"group": {
"kind": "build",
"isDefault": true
Expand Down
36 changes: 18 additions & 18 deletions Build/New-TeamViewerPSPackage.ps1 → Build/New-Package.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
param(
[Parameter()]
[string]
$BuildOutputPath = "$(Resolve-Path "$PSScriptRoot/..")/BuildOutput"
$BuildOutputPath = "$(Resolve-Path "$PSScriptRoot/..")/Build/Output"
)

$repoPath = Resolve-Path "$PSScriptRoot/.."
Expand All @@ -14,18 +14,18 @@ if (Test-Path $BuildOutputPath) {
}
Write-Verbose 'Creating build output directories.'
New-Item -Type Directory $BuildOutputPath | Out-Null
New-Item -Type Directory "$BuildOutputPath/TeamViewerPS" | Out-Null


# Compile all functions into a single psm file
$targetFile = "$BuildOutputPath/TeamViewerPS/TeamViewerPS.psm1"
$targetFile = "$BuildOutputPath/TeamViewerPS.psm1"
Write-Verbose 'Compiling single-file TeamViewer module.'
$ModuleTypes = @(Get-ChildItem -Path "$repoPath/TeamViewerPS/TeamViewerPS.Types.ps1")
$ModuleTypes = @(Get-ChildItem -Path "$repoPath/Docs/TeamViewerPS.Types.ps1")
$PrivateFunctions = @(Get-ChildItem `
-Path "$repoPath/TeamViewerPS/Private/*.ps1" `
-Path "$repoPath/Docs/Cmdlets/Private/*.ps1" `
-ErrorAction SilentlyContinue)
Write-Verbose "Found $($PrivateFunctions.Count) private function files."
$PublicFunctions = @(Get-ChildItem `
-Path "$repoPath/TeamViewerPS/Public/*.ps1" `
-Path "$repoPath/Docs/Cmdlets/Public/*.ps1" `
-ErrorAction SilentlyContinue)
Write-Verbose "Found $($PublicFunctions.Count) public function files."
@($ModuleTypes + $PrivateFunctions + $PublicFunctions) | `
Expand All @@ -36,39 +36,39 @@ Write-Verbose "Found $($PublicFunctions.Count) public function files."
# Create help from markdown
Write-Verbose 'Building help from Markdown'
New-ExternalHelp `
-Path "$repoPath/docs" `
-OutputPath "$BuildOutputPath/TeamViewerPS/en-US" | `
-Path "$repoPath/Docs" `
-OutputPath "$BuildOutputPath/en-US" | `
Out-Null
New-ExternalHelp `
-Path "$repoPath/docs/commands" `
-OutputPath "$BuildOutputPath/TeamViewerPS/en-US" | `
-Path "$repoPath/Docs/Cmdlets_help" `
-OutputPath "$BuildOutputPath/en-US" | `
Out-Null

# Create module manifest
Write-Verbose 'Creating module manifest'
Copy-Item `
-Path "$repoPath/TeamViewerPS/TeamViewerPS.psd1" `
-Destination "$BuildOutputPath/TeamViewerPS/"
-Path "$repoPath/Docs/TeamViewerPS.psd1" `
-Destination "$BuildOutputPath/"
Copy-Item `
-Path "$repoPath/TeamViewerPS/*.format.ps1xml" `
-Destination "$BuildOutputPath/TeamViewerPS/"
-Path "$repoPath/Docs/*.format.ps1xml" `
-Destination "$BuildOutputPath/"
Update-Metadata `
-Path "$BuildOutputPath/TeamViewerPS/TeamViewerPS.psd1" `
-Path "$BuildOutputPath/TeamViewerPS.psd1" `
-PropertyName 'FunctionsToExport' `
-Value $PublicFunctions.BaseName

# Copy additional package files
Write-Verbose 'Copying additional files into the package'
Copy-Item `
-Path `
"$repoPath/LICENSE", `
"$repoPath/LICENSE.md", `
"$repoPath/CHANGELOG.md", `
"$repoPath/README.md"`
-Destination "$BuildOutputPath/TeamViewerPS/"
-Destination "$BuildOutputPath/"

Write-Verbose 'Listing package files:'
Push-Location $BuildOutputPath
Get-ChildItem -Recurse "$BuildOutputPath/TeamViewerPS" | `
Get-ChildItem -Recurse "$BuildOutputPath/" | `
Sort-Object -Property FullName | `
Resolve-Path -Relative
Pop-Location
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
# Change Log

## 2.0.0 (2023-09-13)

### Added

-Added 'Set-TeamViewerApiURi' to use TeamViewer test API.
-Added user role commands to remotely manage user roles of a TeamViewer company.
-Added `Add-TeamViewerAssignment` and `Remove-TeamViewerAssignment` commands to assign and unassign a device from a TeamViewer company.
-Added `Add-TeamViewerCustomization` and `Remove-TeamViewerCustomization` commands to apply and remove customization.
-Added `Export-TeamViewerSystemInformation` to create zip file for support.
-Added `Set-TeamViewerPSProxy` and `Remove-TeamViewerPSProxy` to set proxy to access WebAPI.
-Added `Get-TeamViewerInstallationDirectory` to return installation directory.
-Added `Remove-TeamViewerPolicyFromManagedDevice` to remove policies from managed devices.

### Changed

-Extended `Invoke-TeamViewerPackageDownload` with MSI package type.
-Folder structure modified.
-`-RemovePolicy` switch removed from `Set-TeamViewerManagedDevice`.

### Fixed

-Fixed `Get-TeamViewerLinuxGlobalConfig` to handle null values.

## 1.5.1 (2023-07-18)

- Improved `User ID` parameter handling for `Add-TeamViewerUserGroupMember` and `Remove-TeamViewerUserGroupMember`
Expand Down
File renamed without changes.
4 changes: 4 additions & 0 deletions Linters/PSScriptAnalyzer.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@{
Severity = @('Error', 'Warning')
ExcludeRules = @('PSUseToExportFieldsInManifest','PSAvoidGlobalVars')
}
4 changes: 0 additions & 4 deletions PSScriptAnalyzerSettings.psd1

This file was deleted.

3 changes: 0 additions & 3 deletions TeamViewerPS/Private/Get-TeamViewerApiUri.ps1

This file was deleted.

18 changes: 0 additions & 18 deletions TeamViewerPS/Public/Test-TeamViewerInstallation.ps1

This file was deleted.

68 changes: 68 additions & 0 deletions Tests/Public/Add-TeamViewerAssignment.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
BeforeAll {
. "$PSScriptRoot/../../docs/Cmdlets/Public/Add-TeamViewerAssignment.ps1"
. "$PSScriptRoot/../../docs/Cmdlets/Public/Get-TeamViewerInstallationDirectory.ps1"
. "$PSScriptRoot/../../docs/Cmdlets/Public/Test-TeamViewerInstallation.ps1"
. "$PSScriptRoot/../../docs/Cmdlets/Public/Get-TeamViewerVersion.ps1"
@(Get-ChildItem -Path "$PSScriptRoot/../../docs/Cmdlets/Private/*.ps1") | `
ForEach-Object { . $_.FullName }
}
Describe 'Add-TeamViewerAssignment' {
Context 'Windows' {
BeforeAll {
# Testing independent behavior using mocked dependencies
Mock Get-TeamViewerInstallationDirectory { 'testPath' }
Mock Get-TeamViewerVersion { '15.50' }
Mock Test-TeamViewerInstallation { $true }
Mock Set-Location {}
Mock Start-Process {}
Mock Resolve-AssignmentErrorCode {}
Mock Start-Process {
$process = New-Object PSObject -Property @{
ExitCode = 0
}
$process
}
}

It 'Should set the location to the installation directory' {
Add-TeamViewerAssignment -AssignmentId '123' -DeviceAlias 'TestAlias' -Retries 3
Assert-MockCalled Set-Location -Scope It -Times 1 -ParameterFilter {
$Path -eq 'testPath'
}
}

It 'Should call TeamViewer.exe assignment with device alias and retries' {
Mock Start-Process -ParameterFilter { $_.FilePath -eq 'TeamViewer.exe' -and $_.ArgumentList -eq 'assignment --id 123 --device-alias=TestAlias --retries=3' }
Add-TeamViewerAssignment -AssignmentId '123' -DeviceAlias 'TestAlias' -Retries 3
Assert-MockCalled Start-Process -Scope It -Times 1
}

It 'Should call TeamViewer.exe assignment with device alias' {
Mock Start-Process -ParameterFilter { $_.FilePath -eq 'TeamViewer.exe' -and $_.ArgumentList -eq 'assignment --id 123 --device-alias=TestAlias' }
Add-TeamViewerAssignment -AssignmentId '123' -DeviceAlias 'TestAlias'
Assert-MockCalled Start-Process -Scope It -Times 1
}

It 'Should call TeamViewer.exe assignment with retries' {
Mock Start-Process -ParameterFilter { $_.FilePath -eq 'TeamViewer.exe' -and $_.ArgumentList -eq 'assignment --id 123 --retries=3' }
Add-TeamViewerAssignment -AssignmentId '123' -Retries 3
Assert-MockCalled Start-Process -Scope It -Times 1
}

It 'Should call TeamViewer.exe assignment without device alias or retries' {
Mock Start-Process -ParameterFilter { $_.FilePath -eq 'TeamViewer.exe' -and $_.ArgumentList -eq 'assignment --id 123' }
Add-TeamViewerAssignment -AssignmentId '123'
Assert-MockCalled Start-Process -Scope It -Times 1
}

It 'Should restore the current directory after calling cmd.exe' {
$currentDirectory = Get-Location
Add-TeamViewerAssignment -AssignmentId '123' -DeviceAlias 'TestAlias'
Assert-MockCalled Set-Location -Scope It -Times 1 -ParameterFilter {
$Path -eq $currentDirectory
}
}
}
}


Loading

0 comments on commit 4d70b5d

Please sign in to comment.