Skip to content
This repository was archived by the owner on Feb 24, 2021. It is now read-only.

Commit 8fc0fc4

Browse files
authored
Merge branch 'dev' into Test-PublishMetaData-Guid-Update
2 parents 9a46725 + 175d755 commit 8fc0fc4

File tree

7 files changed

+747
-12
lines changed

7 files changed

+747
-12
lines changed

AppVeyor.psm1

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,7 @@ function Invoke-AppVeyorDeployTask
12391239
param
12401240
(
12411241
[Parameter()]
1242-
[ValidateSet('PublishExample')]
1242+
[ValidateSet('PublishExample', 'PublishWikiContent')]
12431243
[String[]]
12441244
$OptIn = @(
12451245
'PublishExample'
@@ -1275,9 +1275,9 @@ function Invoke-AppVeyorDeployTask
12751275

12761276
$startGalleryDeployParameters = @{
12771277
ResourceModuleName = $ResourceModuleName
1278-
Path = (Join-Path -Path $MainModulePath -ChildPath 'Examples')
1279-
Branch = $env:APPVEYOR_REPO_BRANCH
1280-
ModuleRootPath = $ModuleRootPath
1278+
Path = (Join-Path -Path $MainModulePath -ChildPath 'Examples')
1279+
Branch = $env:APPVEYOR_REPO_BRANCH
1280+
ModuleRootPath = $ModuleRootPath
12811281
}
12821282

12831283
Start-GalleryDeploy @startGalleryDeployParameters
@@ -1286,6 +1286,25 @@ function Invoke-AppVeyorDeployTask
12861286
{
12871287
Write-Info -Message 'Skip publish examples to Gallery. Either not opt-in, or building on the wrong branch.'
12881288
}
1289+
1290+
# Will only publish Wiki Content on pull request merge to master.
1291+
if ($OptIn -contains 'PublishWikiContent' -and $Branch -contains $env:APPVEYOR_REPO_BRANCH)
1292+
{
1293+
Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath 'DscResource.DocumentationHelper')
1294+
1295+
$publishWikiContentParameters = @{
1296+
RepoName = $env:APPVEYOR_REPO_NAME
1297+
JobId = $env:APPVEYOR_JOB_ID
1298+
ResourceModuleName = $ResourceModuleName
1299+
Verbose = $true
1300+
}
1301+
1302+
Publish-WikiContent @publishWikiContentParameters
1303+
}
1304+
else
1305+
{
1306+
Write-Info -Message 'Skip publish Wiki Content. Either not opt-in, or building on the wrong branch.'
1307+
}
12891308
}
12901309

12911310
Export-ModuleMember -Function *

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
## Unreleased
44

5-
- Added processing to `Test-PublishMetaData` for the InvalidGUID error from Test-ScriptFileInfo ([issue #330](https://github.com/PowerShell/DscResource.Tests/issues/330)).
65
- Fixes issue where Reset-DSC causes a Warning to be logged if a DSC
76
configuration is not currently running.
87
- Added issue templates.
@@ -53,6 +52,10 @@
5352
the resource file.
5453
- There should be no additional localized string keys in the resource
5554
file that do not exist in the en-US resource file.
55+
- Added `Publish-WikiContent` helper function to publish auto-generated Wiki files
56+
to the relevant DSC resource GitHub Wiki ([issue #142](https://github.com/PowerShell/DscResource.Tests/issues/142)).
57+
- Added processing to `Test-PublishMetaData` for the InvalidGUID error from Test-ScriptFileInfo
58+
([issue #330](https://github.com/PowerShell/DscResource.Tests/issues/330)).
5659

5760
## 0.3.0.0
5861

DscResource.DocumentationHelper/WikiPages.psm1

Lines changed: 249 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ if (-not ([System.Management.Automation.PSTypeName]'WikiExampleBlockType').Type)
1616
Add-Type -TypeDefinition $typeDefinition
1717
}
1818

19+
$projectRootPath = Split-Path -Path $PSScriptRoot -Parent
20+
$testHelperPath = Join-Path -Path $projectRootPath -ChildPath 'TestHelper.psm1'
21+
Import-Module -Name $testHelperPath -Force
22+
23+
$script:localizedData = Get-LocalizedData -ModuleName 'WikiPages' -ModuleRoot $PSScriptRoot
24+
25+
$appVeyorApiUrl = 'https://ci.appveyor.com/api'
26+
1927
<#
2028
.SYNOPSIS
2129
New-DscResourceWikiSite generates wiki pages that can be uploaded to GitHub to use as
@@ -293,4 +301,244 @@ function Get-DscResourceWikiExampleContent
293301
return $exampleStringBuilder.ToString()
294302
}
295303

296-
Export-ModuleMember -Function New-DscResourceWikiSite
304+
<#
305+
.SYNOPSIS
306+
Publishes the Wiki Content from an AppVeyor job artifact.
307+
308+
.DESCRIPTION
309+
This function adds the content pages from the Wiki Content artifact of a specified
310+
AppVeyor job to the Wiki of a specified GitHub repository.
311+
312+
.PARAMETER RepoName
313+
The name of the Github Repo, in the format <account>/<repo>.
314+
315+
.PARAMETER JobId
316+
The AppVeyor job id that contains the wiki artifact to publish.
317+
318+
.PARAMETER ResourceModuleName
319+
The name of the Dsc Resource Module.
320+
321+
.PARAMETER BuildVersion
322+
The build version number to tag the Wiki Github commit with.
323+
324+
.PARAMETER GithubAccessToken
325+
The GitHub access token to allow a push to the GitHub Wiki.
326+
327+
.PARAMETER GitUserEmail
328+
The email address to use for the Git commit.
329+
330+
.PARAMETER GitUserName
331+
The user name to use for the Git commit.
332+
333+
.EXAMPLE
334+
Publish-WikiContent -RepoName 'PowerShell/xActiveDirectory' -JobId 'imy2wgp1ylo9bcpb' -ResourceModuleName 'xActiveDirectory' `
335+
-BuildVersion 'v1.0.0'
336+
337+
Adds the Content pages from the AppVeyor Job artifact to the Wiki for the specified GitHub repository.
338+
339+
.NOTES
340+
Appveyor - Push to remote Git repository from a build: https://www.appveyor.com/docs/how-to/git-push/
341+
#>
342+
function Publish-WikiContent
343+
{
344+
[CmdletBinding()]
345+
param
346+
(
347+
[Parameter()]
348+
[System.String]
349+
$RepoName = $env:APPVEYOR_REPO_NAME,
350+
351+
[Parameter()]
352+
[System.String]
353+
$JobId = $env:APPVEYOR_JOB_ID,
354+
355+
[Parameter()]
356+
[System.String]
357+
$ResourceModuleName = (($env:APPVEYOR_REPO_NAME -split '/')[1]),
358+
359+
[Parameter()]
360+
[System.String]
361+
$BuildVersion = $env:APPVEYOR_BUILD_VERSION,
362+
363+
[Parameter()]
364+
[System.String]
365+
$GithubAccessToken = $env:github_access_token,
366+
367+
[Parameter()]
368+
[System.String]
369+
$GitUserEmail = $env:APPVEYOR_REPO_COMMIT_AUTHOR_EMAIL,
370+
371+
[Parameter()]
372+
[System.String]
373+
$GitUserName = $env:APPVEYOR_REPO_COMMIT_AUTHOR
374+
)
375+
376+
$ErrorActionPreference = 'Stop'
377+
378+
$headers = @{
379+
'Content-type' = 'application/json'
380+
}
381+
382+
Write-Verbose -Message $script:localizedData.CreateTempDirMessage
383+
$path = New-TempFolder
384+
385+
try
386+
{
387+
Write-Verbose -Message $script:localizedData.ConfigGlobalGitMessage
388+
Invoke-Git config --global core.autocrlf true
389+
390+
$wikiRepoName = "https://github.com/$RepoName.wiki.git"
391+
Write-Verbose -Message ($script:localizedData.CloneWikiGitRepoMessage -f $WikiRepoName)
392+
Invoke-Git clone $wikiRepoName $path --quiet
393+
394+
$jobArtifactsUrl = "$appVeyorApiUrl/buildjobs/$JobId/artifacts"
395+
Write-Verbose -Message ($localizedData.DownloadAppVeyorArtifactDetailsMessage -f $JobId, $jobArtifactsUrl)
396+
397+
try
398+
{
399+
$artifacts = Invoke-RestMethod -Method Get -Uri $jobArtifactsUrl -Headers $headers -Verbose:$false
400+
}
401+
catch
402+
{
403+
switch (($_ | ConvertFrom-Json).Message)
404+
{
405+
'Job not found.'
406+
{
407+
throw ($script:localizedData.NoAppVeyorJobFoundError -f $JobId)
408+
}
409+
410+
default
411+
{
412+
throw $_
413+
}
414+
}
415+
}
416+
417+
$wikiContentArtifact = $artifacts | Where-Object -Property fileName -like "$ResourceModuleName_*_wikicontent.zip"
418+
419+
if ($null -eq $wikiContentArtifact)
420+
{
421+
throw ($LocalizedData.NoWikiContentArtifactError -f $JobId)
422+
}
423+
424+
$artifactUrl = "$appVeyorApiUrl/buildjobs/$JobId/artifacts/$($wikiContentArtifact.fileName)"
425+
426+
Write-Verbose -Message ($localizedData.DownloadAppVeyorWikiContentArtifactMessage -f $artifactUrl)
427+
$wikiContentArtifactPath = Join-Path -Path $Path -ChildPath $wikiContentArtifact.filename
428+
Invoke-RestMethod -Method Get -Uri $artifactUrl -OutFile $wikiContentArtifactPath -Headers $headers `
429+
-Verbose:$false
430+
431+
Write-Verbose -Message ($localizedData.UnzipWikiContentArtifactMessage -f $wikiContentArtifact.filename)
432+
Expand-Archive -Path $wikiContentArtifactPath -DestinationPath $path -Force
433+
Remove-Item -Path $wikiContentArtifactPath
434+
435+
Push-Location
436+
Set-Location -Path $path
437+
438+
Write-Verbose -Message $script:localizedData.ConfigLocalGitMessage
439+
Invoke-Git config --local user.email $GitUserEmail
440+
Invoke-Git config --local user.name $GitUserName
441+
Invoke-Git remote set-url origin "https://$($GitUserName):$($GithubAccessToken)@github.com/$RepoName.wiki.git"
442+
443+
Write-Verbose -Message $localizedData.AddWikiContentToGitRepoMessage
444+
Invoke-Git add *
445+
446+
Write-Verbose -Message ($localizedData.CommitAndTagRepoChangesMessage -f $BuildVersion)
447+
Invoke-Git commit --message ($localizedData.UpdateWikiCommitMessage -f $JobId) --quiet
448+
Invoke-Git tag --annotate $BuildVersion --message $BuildVersion
449+
450+
Write-Verbose -Message $localizedData.PushUpdatedRepoMessage
451+
Invoke-Git push origin --quiet
452+
Invoke-Git push origin $BuildVersion --quiet
453+
454+
Pop-Location
455+
}
456+
finally
457+
{
458+
Remove-Item -Path $path -Recurse -Force
459+
Write-Verbose -Message $localizedData.PublishWikiContentCompleteMessage
460+
}
461+
}
462+
463+
<#
464+
.SYNOPSIS
465+
Invokes the git command.
466+
467+
.PARAMETER Arguments
468+
The arguments to pass to the Git executable.
469+
470+
.EXAMPLE
471+
Invoke-Git clone https://github.com/X-Guardian/xActiveDirectory.wiki.git --quiet
472+
473+
Invokes the Git executable to clone the specified repository to the current working directory.
474+
#>
475+
476+
function Invoke-Git
477+
{
478+
[CmdletBinding()]
479+
param
480+
(
481+
[parameter(ValueFromRemainingArguments = $true)]
482+
[System.String[]]
483+
$Arguments
484+
)
485+
486+
Write-Debug -Message ($localizedData.InvokingGitMessage -f $Arguments)
487+
488+
try
489+
{
490+
& git.exe @Arguments 2>$null
491+
}
492+
catch
493+
{
494+
if ($LASTEXITCODE -ne 0)
495+
{
496+
throw $_
497+
}
498+
}
499+
}
500+
501+
<#
502+
.SYNOPSIS
503+
Creates a new temporary folder with a random name.
504+
505+
.EXAMPLE
506+
New-TempFolder
507+
508+
This command creates a new temporary folder with a random name.
509+
510+
.PARAMETER MaximumRetries
511+
Specifies the maximum number of time to retry creating the temp folder.
512+
513+
.OUTPUTS
514+
System.IO.DirectoryInfo
515+
#>
516+
function New-TempFolder
517+
{
518+
[CmdletBinding()]
519+
[OutputType([System.IO.DirectoryInfo])]
520+
param (
521+
[Parameter()]
522+
[Int]
523+
$MaximumRetries = 10
524+
)
525+
526+
$tempPath = [System.IO.Path]::GetTempPath()
527+
528+
$retries = 0
529+
do
530+
{
531+
$retries++
532+
if ($Retries -gt $MaximumRetries)
533+
{
534+
throw ($localizedData.NewTempFolderCreationError -f $tempPath)
535+
}
536+
$name = [System.IO.Path]::GetRandomFileName()
537+
$path = New-Item -Path $tempPath -Name $name -ItemType Directory -ErrorAction SilentlyContinue
538+
}
539+
while (-not $path)
540+
541+
return $path
542+
}
543+
544+
Export-ModuleMember -Function New-DscResourceWikiSite, Publish-WikiContent
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# culture="en-US"
2+
ConvertFrom-StringData @'
3+
CreateTempDirMessage = Creating a temporary working directory.
4+
ConfigGlobalGitMessage = Configuring global Git settings.
5+
ConfigLocalGitMessage = Configuring local Git settings.
6+
CloneWikiGitRepoMessage = Cloning the Wiki Git Repository '{0}'.
7+
DownloadAppVeyorArtifactDetailsMessage = Downloading the Appveyor Artifact Details for job '{0}' from '{1}'.
8+
DownloadAppVeyorWikiContentArtifactMessage = Downloading the Appveyor WikiContent Artifact '{0}'.
9+
AddWikiContentToGitRepoMessage = Adding the Wiki Content to the Git Repository.
10+
CommitAndTagRepoChangesMessage = Committing the changes to the Repository and adding build tag '{0}'.
11+
PushUpdatedRepoMessage = Pushing the updated Repository to the Git Wiki.
12+
PublishWikiContentCompleteMessage = Publish Wiki Content complete.
13+
UnzipWikiContentArtifactMessage = Unzipping the WikiContent Artifact '{0}'.
14+
UpdateWikiCommitMessage = Updating Wiki from AppVeyor Job ID '{0}'.
15+
NoAppVeyorJobFoundError = No AppVeyor Job found with ID '{0}'.
16+
NoWikiContentArtifactError = No Wiki Content artifact found in AppVeyor job id '{0}'.
17+
NewTempFolderCreationError = Unable to create a temporary working folder in '{0}'.
18+
InvokingGitMessage = Invoking Git '{0}'.
19+
'@

0 commit comments

Comments
 (0)