Skip to content

Commit

Permalink
Merge new-folder-structure-2 into master and !publish
Browse files Browse the repository at this point in the history
* Refactored Folder Structure

* Update PSTelegramAPI.Module.Tests.ps1

* Update task Test

* Changed filename for test/coverage results

* Update to CodeCoverage format

* Update PSTelegramAPI.build.ps1

* Update RequiredModules.psd1

* Update PSTelegramAPI.build.ps1

* Update azure-pipelines.yml

* Update azure-pipelines.yml

* Update azure-pipelines.yml

* Update azure-pipelines.yml

* Update azure-pipelines.yml

* Increased ModuleVersion

* Delete bootstrap.ps1

* Merged RequiredModules.psd1

* Fixed UpdateManifest task

* Added UpdateManifest task

* Updated ModuleVersion

* Update README.md

* Update azure-pipelines.yml

* Update azure-pipelines.yml

* Update azure-pipelines.yml

* Update README.md

* Added !publish requirement to publish to gallery.

* Update PSTelegramAPI.build.ps1

* Update PSTelegramAPI.build.ps1

* Update PSTelegramAPI.build.ps1

* Update PSTelegramAPI.bootstrap.ps1

* Update README.md
  • Loading branch information
mkellerman committed Jan 6, 2019
1 parent 3c06b24 commit b8dc5c8
Show file tree
Hide file tree
Showing 20 changed files with 112 additions and 128 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

*.dat
output/
output/
testresults/
10 changes: 9 additions & 1 deletion bootstrap.ps1 → PSTelegramAPI.bootstrap.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@ param(
[ValidateSet("CurrentUser", "AllUsers")]
$Scope = "CurrentUser"
)
[ModuleSpecification[]]$RequiredModules = Import-LocalizedData -BaseDirectory $PSScriptRoot -FileName RequiredModules

[ModuleSpecification[]]$RequiredModules = @(
@{ ModuleName = "InvokeBuild"; RequiredVersion = "5.4.2" }
@{ ModuleName = "Pester"; RequiredVersion = "4.4.4" }
@{ ModuleName = "BuildHelpers"; RequiredVersion = "2.0.3" }
)

$Policy = (Get-PSRepository PSGallery).InstallationPolicy
Set-PSRepository PSGallery -InstallationPolicy Trusted

try {
$RequiredModules | Install-Module -Scope $Scope -Repository PSGallery -SkipPublisherCheck -Verbose
} finally {
Set-PSRepository PSGallery -InstallationPolicy $Policy
}

$RequiredModules | Import-Module
142 changes: 61 additions & 81 deletions PSTelegramAPI.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,8 @@ param ($Configuration = 'Development')
Set-StrictMode -Version Latest
#endregion

#region Task to Update the PowerShell Module Help Files.
# Pre-requisites: PowerShell Module PlatyPS.
task UpdateHelp {
Import-Module .\PSTelegramAPI.psd1 -Force
Update-MarkdownHelp .\docs
New-ExternalHelp -Path .\docs -OutputPath .\en-US -Force
}
#endregion

#region Task to retrieve latest version of TLSharp Packages
# More info: https://www.nuget.org/packages/TLSharp
task GetLatestTLSharpPackage {
Find-Package -Name TLSharp -Provider Nuget -Source 'https://www.nuget.org/api/v2'
}
#region Set-BuildEnvironment
Set-BuildEnvironment -Force -ErrorAction SilentlyContinue
#endregion

#region Task to Update TLSharp Package if newer version is released
Expand Down Expand Up @@ -64,34 +52,21 @@ task UpdateTLSharpPackage {
}
#endregion

#region Task to Copy PowerShell Module files to output folder for release as Module
task CopyModuleFiles {

# Copy Module Files to Output Folder
if (-not (Test-Path .\output\PSTelegramAPI)) {
#region Task to run all Pester tests in folder .\tests
task Test {

$null = New-Item -Path .\output\PSTelegramAPI -ItemType Directory
$OutputPath = New-Item -Path '.\TestResults' -ItemType Directory -Force -Verbose

$PesterParams = @{
Script = '.\Tests'
OutputFile = "${OutputPath}\TestResults-PSTelegramAPI.xml"
CodeCoverage = 'PSTelegramAPI\*\*.ps1'
CodeCoverageOutputFile = "${OutputPath}\CodeCoverage-PSTelegramAPI.xml"
CodeCoverageOutputFileFormat = 'JaCoCo'
}

#Copy-Item -Path '.\en-US\' -Filter *.* -Recurse -Destination .\output\PSTelegramAPI -Force
Copy-Item -Path '.\lib\' -Filter *.* -Recurse -Destination .\output\PSTelegramAPI -Force
Copy-Item -Path '.\public\' -Filter *.* -Recurse -Destination .\output\PSTelegramAPI -Force
Copy-Item -Path '.\private\' -Filter *.* -Recurse -Destination .\output\PSTelegramAPI -Force
Copy-Item -Path '.\tests\' -Filter *.* -Recurse -Destination .\output\PSTelegramAPI -Force

#Copy Module Manifest files
Copy-Item -Path @(
'.\README.md'
'.\PSTelegramAPI.psd1'
'.\PSTelegramAPI.psm1'
) -Destination .\output\PSTelegramAPI -Force
}
#endregion
$Result = Invoke-Pester @PesterParams -PassThru

#region Task to run all Pester tests in folder .\tests
task Test {
$Result = Invoke-Pester .\tests -PassThru
if ($Result.FailedCount -gt 0) {
throw 'Pester tests failed'
}
Expand All @@ -102,62 +77,67 @@ task Test {
#region Task to update the Module Manifest file with info from the Changelog in Readme.
task UpdateManifest {
# Import PlatyPS. Needed for parsing README for Change Log versions
Import-Module -Name PlatyPS

# Find Latest Version in README file from Change log.
$README = Get-Content -Path .\README.md
$MarkdownObject = [Markdown.MAML.Parser.MarkdownParser]::new()
[regex]$regex = '\d\.\d\.\d'
$Versions = $regex.Matches($MarkdownObject.ParseString($README).Children.Spans.Text) | foreach-object {$_.value}
($Versions | Measure-Object -Maximum).Maximum

$manifestPath = '.\PSTelegramAPI.psd1'

# Start by importing the manifest to determine the version, then add 1 to the Build
$manifest = Test-ModuleManifest -Path $manifestPath
[System.Version]$version = $manifest.Version
[String]$newVersion = New-Object -TypeName System.Version -ArgumentList ($version.Major, $version.Minor, ($version.Build + 1))
Write-Output -InputObject ('New Module version: {0}' -f $newVersion)

# Update Manifest file with Release Notes
$README = Get-Content -Path .\README.md
$MarkdownObject = [Markdown.MAML.Parser.MarkdownParser]::new()
$ReleaseNotes = ((($MarkdownObject.ParseString($README).Children.Spans.Text) -match '\d\.\d\.\d') -split ' - ')[1]

#Update Module with new version
Update-ModuleManifest -ModuleVersion $newVersion -Path .\PSTelegramAPI.psd1 -ReleaseNotes $ReleaseNotes
#Import-Module -Name PlatyPS

$ManifestPath = '.\PSTelegramAPI\PSTelegramAPI.psd1'
$ModuleManifest = Test-ModuleManifest -Path $ManifestPath
[System.Version]$ManifestVersion = $ModuleManifest.Version
Write-Output -InputObject ('Manifest Version : {0}' -f $ManifestVersion)

$PSGalleryModule = Find-Module -Name PSTelegramAPI -Repository PSGallery
[System.Version]$PSGalleryVersion = $PSGalleryModule.Version
Write-Output -InputObject ('PSGallery Version : {0}' -f $PSGalleryVersion)

If ($PSGalleryVersion -ge $ManifestVersion) {

[System.Version]$Version = New-Object -TypeName System.Version -ArgumentList ($PSGalleryVersion.Major, $PSGalleryVersion.Minor, ($PSGalleryVersion.Build + 1))
Write-Output -InputObject ('Updated Version : {0}' -f $Version)
Update-ModuleManifest -ModuleVersion $Version -Path .\PSTelegramAPI\PSTelegramAPI.psd1 # -ReleaseNotes $ReleaseNotes

}

}
#endregion

#region Task to Publish Module to PowerShell Gallery
task PublishModule -If ($Configuration -eq 'Production') {
Try {
# Build a splat containing the required details and make sure to Stop for errors which will trigger the catch
$params = @{
Path = ('{0}\Output\PSTelegramAPI' -f $PSScriptRoot )
NuGetApiKey = $ENV:NuGetApiKey
ErrorAction = 'Stop'

# Publish to gallery with a few restrictions
if(
$env:BHModulePath -and
$env:BHBuildSystem -ne 'Unknown' -and
$env:BHBranchName -eq "master" -and
$env:BHCommitMessage -match '!publish'
)
{

# Build a splat containing the required details and make sure to Stop for errors which will trigger the catch
$params = @{
Path = ".\PSTelegramAPI"
NuGetApiKey = $ENV:NuGetApiKey
ErrorAction = 'Stop'
}
Publish-Module @params
Write-Output -InputObject ('PSTelegramAPI PowerShell Module version published to the PowerShell Gallery')

}
else
{
"Skipping deployment: To deploy, ensure that...`n" +
"`t* You are in a known build system (Current: $ENV:BHBuildSystem)`n" +
"`t* You are committing to the master branch (Current: $ENV:BHBranchName) `n" +
"`t* Your commit message includes !deploy (Current: $ENV:BHCommitMessage)" |
Write-Host
}
Publish-Module @params
Write-Output -InputObject ('PSTelegramAPI PowerShell Module version published to the PowerShell Gallery')

}
Catch {
throw $_
}
}
#endregion

#region Task clean up Output folder
task Clean {
# Clean output folder
if ((Test-Path .\output)) {

Remove-Item -Path .\Output -Recurse -Force

}
}
#endregion

#region Default Task. Runs Clean, Test, CopyModuleFiles Tasks
task . Clean, Test, CopyModuleFiles, PublishModule
#region Default Task. Runs Test, UpdateManifest, PublishModule Tasks
task . Test, UpdateManifest, PublishModule
#endregion
18 changes: 13 additions & 5 deletions PSTelegramAPI.psd1 → PSTelegramAPI/PSTelegramAPI.psd1
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#
# Module manifest for module 'PSTelegramAPI'
#
# Generated by: @mkellerman
# Generated by: Marc R Kellerman
#
# Generated on: 1/3/2019
# Generated on: 1/5/2019
#

@{
Expand All @@ -12,7 +12,7 @@
RootModule = 'PSTelegramAPI.psm1'

# Version number of this module.
ModuleVersion = '0.0.3'
ModuleVersion = '0.0.5'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down Expand Up @@ -109,9 +109,18 @@ PrivateData = @{
# ReleaseNotes of this module
# ReleaseNotes = ''

# Prerelease string of this module
# Prerelease = ''

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

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

} # End of PSData hashtable

} # End of PrivateData hashtable
} # End of PrivateData hashtable

# HelpInfo URI of this module
# HelpInfoURI = ''
Expand All @@ -121,4 +130,3 @@ PrivateData = @{

}


File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[![Build status](https://mkellerman.visualstudio.com/PSTelegramAPI/_apis/build/status/PSTelegramAPI-CI)](https://mkellerman.visualstudio.com/PSTelegramAPI/_build/latest?definitionId=3)

# PSTelegramAPI

PowerShell Module for Telegram APIs

# References

References:
https://github.com/mkellerman/TLSharp
https://stefanstranger.github.io/2018/12/30/UseAzurePipelinesToPublishPowerShellModule/
<https://github.com/sochix/TLSharp> : Telegram client library implemented in C#
5 changes: 0 additions & 5 deletions RequiredModules.psd1

This file was deleted.

53 changes: 22 additions & 31 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -1,49 +1,40 @@

# Docs: https://aka.ms/yaml
name: $(Build.DefinitionName)_$(Date:yyyyMMdd))
resources:
- repo: self
clean: true

name: $(Build.DefinitionName)_$(Date:yyyyMMdd)
pr:
- master
branches:
include:
- master
paths:
include:
- PSTelegram/*

queue:
name: Hosted VS2017

steps:
- powershell: .\bootstrap.ps1
displayName: 'Initialize Environment'

- powershell: Invoke-Build -Configuration 'Production' -Task Clean, CopyModuleFiles
displayName: 'Build PowerShell Module'
- powershell: './PSTelegramAPI.bootstrap.ps1'
displayName: 'Invoke Bootstrap'

- task: richardfennellBM.BM-VSTS-PesterRunner-Task.Pester-Task.Pester@8
displayName: 'Pester Test Runner'
inputs:
scriptFolder: '$(System.DefaultWorkingDirectory)\tests\*'
additionalModulePath: '$(System.DefaultWorkingDirectory)\output'
CodeCoverageFolder: '$(System.DefaultWorkingDirectory)\output'
resultsFile: '$(Common.TestResultsDirectory)\Test-$(Build.DefinitionName)_$(Build.BuildNumber).xml'
CodeCoverageOutputFile: '$(Common.TestResultsDirectory)\Coverage-$(Build.DefinitionName)_$(Build.BuildNumber).xml'
- powershell: 'Invoke-Build -Configuration Production -Task Test'
displayName: 'Invoke Pester Tests'

- task: PublishTestResults@2
displayName: 'Publish Test Results'
condition: always()
inputs:
testRunner: NUnit
searchFolder: '$(Common.TestResultsDirectory)'
testResultsFormat: NUnit
testResultsFiles: 'TestResults-*.xml'
searchFolder: '$(System.DefaultWorkingDirectory)/TestResults'

- task: PublishCodeCoverageResults@1
displayName: 'Publish Code Coverage'
inputs:
summaryFileLocation: '$(Common.TestResultsDirectory)\Coverage-$(Build.DefinitionName)_$(Build.BuildNumber).xml'

- powershell: Invoke-Build -Configuration 'Production' -Task PublishModule
displayName: 'Publish PowerShell Module'
summaryFileLocation: '$(System.DefaultWorkingDirectory)/TestResults/CodeCoverage-*.xml'
reportDirectory: '$(System.DefaultWorkingDirectory)/TestResults'

- task: PublishBuildArtifacts@1
displayName: 'Publish Build Artifacts'
displayName: 'Publish Artifact: PSTelegramAPI'
inputs:
ArtifactName: Module
PathtoPublish: '$(System.DefaultWorkingDirectory)\output'
PathtoPublish: '$(System.DefaultWorkingDirectory)/PSTelegramAPI'
ArtifactName: PSTelegramAPI

- powershell: 'Invoke-Build -Configuration Production -Task UpdateManifest, PublishModule'
displayName: 'Publish PowerShell Module'
2 changes: 1 addition & 1 deletion tests/PSTelegramAPI.Module.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
$ModuleName = 'PSTelegramAPI'
$ModuleManifestName = "${ModuleName}.psd1"
$ModuleManifestPath = "${PSScriptRoot}\..\${ModuleManifestName}"
$ModuleManifestPath = "${PSScriptRoot}\..\${ModuleName}\${ModuleManifestName}"

Describe 'General Module Tests' {
It 'Passes Test-ModuleManifest' {
Expand Down

0 comments on commit b8dc5c8

Please sign in to comment.