-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #122 from StartAutomating/GitHubWorkFlowImprovments
GitHub Workflow Improvements
- Loading branch information
Showing
10 changed files
with
630 additions
and
109 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
@{ | ||
"runs-on" = "ubuntu-latest" | ||
if = '${{ success() }}' | ||
steps = @( | ||
@{ | ||
name = 'Check out repository' | ||
uses = 'actions/checkout@v2' | ||
}, 'ReleaseModule' | ||
) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
@{ | ||
"runs-on" = "ubuntu-latest" | ||
if = '${{ success() }}' | ||
steps = @( | ||
@{ | ||
name = 'Check out repository' | ||
uses = 'actions/checkout@v2' | ||
}, 'TagModuleVersion','ReleaseModule','PublishPowerShellGallery' | ||
) | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
param( | ||
[string] | ||
$ModulePath, | ||
|
||
# The user email associated with a git commit. | ||
[string] | ||
$UserEmail, | ||
|
||
# The user name associated with a git commit. | ||
[string] | ||
$UserName, | ||
|
||
# The tag version format (default value: 'v$(imported.Version)') | ||
# This can expand variables. $imported will contain the imported module. | ||
[string] | ||
$TagVersionFormat = 'v$($imported.Version)' | ||
) | ||
|
||
|
||
$gitHubEvent = if ($env:GITHUB_EVENT_PATH) { | ||
[IO.File]::ReadAllText($env:GITHUB_EVENT_PATH) | ConvertFrom-Json | ||
} else { $null } | ||
|
||
|
||
@" | ||
::group::GitHubEvent | ||
$($gitHubEvent | ConvertTo-Json -Depth 100) | ||
::endgroup:: | ||
"@ | Out-Host | ||
|
||
if (-not ($gitHubEvent.head_commit.message -match "Merge Pull Request #(?<PRNumber>\d+)") -and | ||
(-not $gitHubEvent.psobject.properties['inputs'])) { | ||
"::warning::Pull Request has not merged, skipping GitHub release" | Out-Host | ||
return | ||
} | ||
|
||
|
||
|
||
$imported = | ||
if (-not $ModulePath) { | ||
$orgName, $moduleName = $env:GITHUB_REPOSITORY -split "/" | ||
Import-Module ".\$moduleName.psd1" -Force -PassThru -Global | ||
} else { | ||
Import-Module $modulePath -Force -PassThru -Global | ||
} | ||
|
||
if (-not $imported) { return } | ||
|
||
$targetVersion =$ExecutionContext.InvokeCommand.ExpandString($TagVersionFormat) | ||
$targetReleaseName = $targetVersion | ||
$releasesURL = 'https://api.github.com/repos/${{github.repository}}/releases' | ||
"Release URL: $releasesURL" | Out-Host | ||
$listOfReleases = Invoke-RestMethod -Uri $releasesURL -Method Get -Headers @{ | ||
"Accept" = "application/vnd.github.v3+json" | ||
"Authorization" = 'Bearer ${{ secrets.GITHUB_TOKEN }}' | ||
} | ||
|
||
$releaseExists = $listOfReleases | Where-Object tag_name -eq $targetVersion | ||
|
||
if ($releaseExists) { | ||
"::warning::Release '$($releaseExists.Name )' Already Exists" | Out-Host | ||
return | ||
} | ||
|
||
|
||
Invoke-RestMethod -Uri $releasesURL -Method Post -Body ( | ||
[Ordered]@{ | ||
owner = '${{github.owner}}' | ||
repo = '${{github.repository}}' | ||
tag_name = $targetVersion | ||
name = "$($imported.Name) $targetVersion" | ||
body = | ||
if ($env:RELEASENOTES) { | ||
$env:RELEASENOTES | ||
} elseif ($imported.PrivateData.PSData.ReleaseNotes) { | ||
$imported.PrivateData.PSData.ReleaseNotes | ||
} else { | ||
"$($imported.Name) $targetVersion" | ||
} | ||
draft = if ($env:RELEASEISDRAFT) { [bool]::Parse($env:RELEASEISDRAFT) } else { $false } | ||
prerelease = if ($env:PRERELEASE) { [bool]::Parse($env:PRERELEASE) } else { $false } | ||
} | ConvertTo-Json | ||
) -Headers @{ | ||
"Accept" = "application/vnd.github.v3+json" | ||
"Content-type" = "application/json" | ||
"Authorization" = 'Bearer ${{ secrets.GITHUB_TOKEN }}' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#requires -Module PSDevOps | ||
New-GitHubWorkflow -Name "Analyze, Test, Tag, and Publish" -On Push, PullRequest, Demand -Job PowerShellStaticAnalysis, TestPowerShellOnLinux, TagReleaseAndPublish -Environment @{ | ||
SYSTEM_ACCESSTOKEN = '${{ secrets.AZUREDEVOPSPAT }}' | ||
NoCoverage = $true | ||
}| | ||
Set-Content .\.github\workflows\TestAndPublish.yml -Encoding UTF8 -PassThru |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters