Helpers/Publish-IBHGitHubArtifact.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
<#
.SYNOPSIS Upload an artifact to GitHub. #> function Publish-IBHGitHubArtifact { [CmdletBinding()] param ( # GitHub repository user. [Parameter(Mandatory = $true)] [System.String] $RepositoryUser, # GitHub repository name. [Parameter(Mandatory = $true)] [System.String] $RepositoryName, # Authentication token. [Parameter(Mandatory = $true)] [System.Security.SecureString] $Token, # Release id. [Parameter(Mandatory = $true)] [System.String] $ReleaseId, # Artifact file name. [Parameter(Mandatory = $true)] [System.String] $Name, # Artifact path. [Parameter(Mandatory = $true)] [System.String] $Path ) # Add TLS 1.2 for GitHub if (([System.Net.ServicePointManager]::SecurityProtocol -band [System.Net.SecurityProtocolType]::Tls12) -ne [System.Net.SecurityProtocolType]::Tls12) { [System.Net.ServicePointManager]::SecurityProtocol += [System.Net.SecurityProtocolType]::Tls12 } # Unprotect token $tokenCredentialStub = [System.Management.Automation.PSCredential]::new('Token', $Token) $plainToken = $tokenCredentialStub.GetNetworkCredential().Password # Upload artifact to GitHub $invokeRestMethodSplat = @{ Method = 'Post' Uri = "https://uploads.github.com/repos/$RepositoryUser/$RepositoryName/releases/$ReleaseId/assets?name=$Name" Headers = @{ 'Accept' = 'application/vnd.github.v3+json' 'Authorization' = "token $plainToken" 'Content-Type' = 'application/zip' } InFile = $Path } Invoke-RestMethod @invokeRestMethodSplat -ErrorAction Stop } |