Skip to content

Commit e3dede5

Browse files
committed
Add support for some GitHub Actions capabilities
1 parent c72b3be commit e3dede5

7 files changed

+214
-0
lines changed
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
function Add-GitHubRunnerLabel {
2+
<#
3+
.SYNOPSIS
4+
Add a new label to a GitHub Runner that's registered to a GitHub repository.
5+
#>
6+
[CmdletBinding()]
7+
[OutputType('PSGitHub.RunnerLabels')]
8+
param(
9+
[Parameter(Mandatory, Position = 0)]
10+
[string] $Owner,
11+
12+
[Parameter(Mandatory, Position = 1)]
13+
[Alias('RepositoryName')]
14+
[string] $Repo,
15+
16+
[Parameter(Mandatory, Position = 2)]
17+
[string] $RunnerId,
18+
19+
[Parameter(Mandatory, Position = 2)]
20+
[string[]] $Label,
21+
22+
# Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
23+
# Defaults to "https://api.github.com"
24+
[Uri] $BaseUri = [Uri]::new('https://api.github.com'),
25+
[Security.SecureString] $Token
26+
)
27+
28+
process {
29+
$Body = @{
30+
labels = $Label
31+
} | ConvertTo-Json
32+
$Path = 'repos/{0}/{1}/actions/runners/{2}/labels' -f $Owner, $Repo, $RunnerId
33+
Invoke-GitHubApi $Path -BaseUri $BaseUri -Token $Token -Method Post -Body $Body |
34+
ForEach-Object { $_ } |
35+
ForEach-Object {
36+
$_.PSTypeNames.Insert(0, 'PSGitHub.RunnerLabels')
37+
$_
38+
}
39+
}
40+
}

Functions/Public/Get-GitHubRunner.ps1

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
function Get-GitHubRunner {
2+
<#
3+
.SYNOPSIS
4+
Retrieves the GitHub Runners registered to a GitHub repository.
5+
#>
6+
[CmdletBinding()]
7+
[OutputType('PSGitHub.Runner')]
8+
param(
9+
[Parameter(Mandatory, Position = 0)]
10+
[string] $Owner,
11+
12+
[Parameter(Mandatory, Position = 1)]
13+
[Alias('RepositoryName')]
14+
[string] $Repo,
15+
16+
# Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
17+
# Defaults to "https://api.github.com"
18+
[Uri] $BaseUri = [Uri]::new('https://api.github.com'),
19+
[Security.SecureString] $Token
20+
)
21+
22+
process {
23+
$Path = 'repos/{0}/{1}/actions/runners' -f $Owner, $Repo
24+
Invoke-GitHubApi $Path -BaseUri $BaseUri -Token $Token |
25+
ForEach-Object { $_.runners } |
26+
ForEach-Object {
27+
$_.PSTypeNames.Insert(0, 'PSGitHub.Runner')
28+
$_
29+
}
30+
}
31+
}
32+
33+
Export-ModuleMember -Alias @(
34+
(New-Alias -Name gghrun -Value Get-GitHubRunner -PassThru)
35+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
function Get-GitHubRunnerApplication {
2+
<#
3+
.SYNOPSIS
4+
Retrieves the URLs to download the GitHub Runner application archive, with the installation files.
5+
#>
6+
[CmdletBinding()]
7+
[OutputType('PSGitHub.RunnerApplication')]
8+
param(
9+
[Parameter(Mandatory, Position = 0)]
10+
[string] $Owner,
11+
12+
[Parameter(Mandatory, Position = 1)]
13+
[Alias('RepositoryName')]
14+
[string] $Repo,
15+
16+
# Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
17+
# Defaults to "https://api.github.com"
18+
[Uri] $BaseUri = [Uri]::new('https://api.github.com'),
19+
[Security.SecureString] $Token
20+
)
21+
22+
process {
23+
$Path = 'repos/{0}/{1}/actions/runners/downloads' -f $Owner, $Repo
24+
Invoke-GitHubApi $Path -BaseUri $BaseUri -Token $Token |
25+
ForEach-Object { $_ } |
26+
ForEach-Object {
27+
$_.PSTypeNames.Insert(0, 'PSGitHub.RunnerApplication')
28+
$_
29+
}
30+
}
31+
}
32+
33+
Export-ModuleMember -Alias @(
34+
(New-Alias -Name gghrunapp -Value Get-GitHubRunner -PassThru)
35+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
function Get-GitHubRunnerRegistrationToken {
2+
<#
3+
.SYNOPSIS
4+
Retrieves a registration token for GitHub Actions self-hosted runners. Pass this token to the GitHub Runner configuration script, to register it with a GitHub repository.
5+
#>
6+
[CmdletBinding()]
7+
[OutputType('PSGitHub.RunnerRegistrationToken')]
8+
param(
9+
[Parameter(Mandatory, Position = 0)]
10+
[string] $Owner,
11+
12+
[Parameter(Mandatory, Position = 1)]
13+
[Alias('RepositoryName')]
14+
[string] $Repo,
15+
16+
# Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
17+
# Defaults to "https://api.github.com"
18+
[Uri] $BaseUri = [Uri]::new('https://api.github.com'),
19+
[Security.SecureString] $Token
20+
)
21+
22+
process {
23+
$Path = 'repos/{0}/{1}/actions/runners/registration-token' -f $Owner, $Repo
24+
Invoke-GitHubApi $Path -BaseUri $BaseUri -Token $Token -Method Post |
25+
ForEach-Object { $_ } |
26+
ForEach-Object {
27+
$_.PSTypeNames.Insert(0, 'PSGitHub.RunnerRegistrationToken')
28+
$_
29+
}
30+
}
31+
}
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
function Remove-GitHubRunner {
2+
<#
3+
.SYNOPSIS
4+
Removes a registered GitHub Runner from a GitHub repository.
5+
#>
6+
[CmdletBinding()]
7+
[OutputType('PSGitHub.Runner')]
8+
param(
9+
[Parameter(Mandatory, Position = 0)]
10+
[string] $Owner,
11+
12+
[Parameter(Mandatory, Position = 1)]
13+
[string] $Repo,
14+
15+
[Parameter(Mandatory, Position = 2)]
16+
[int] $RunnerId,
17+
18+
# Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
19+
# Defaults to "https://api.github.com"
20+
[Uri] $BaseUri = [Uri]::new('https://api.github.com'),
21+
[Security.SecureString] $Token
22+
)
23+
24+
process {
25+
$Path = 'repos/{0}/{1}/actions/runners/{2}' -f $Owner, $Repo, $RunnerId
26+
$null = Invoke-GitHubApi $Path -BaseUri $BaseUri -Token $Token -Method Delete
27+
}
28+
}
29+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
function Remove-GitHubRunnerLabel {
2+
<#
3+
.SYNOPSIS
4+
Removes a label from a GitHub Runner that's registered to a GitHub repository.
5+
#>
6+
[CmdletBinding()]
7+
[OutputType('PSGitHub.RunnerLabels')]
8+
param(
9+
[Parameter(Mandatory, Position = 0)]
10+
[string] $Owner,
11+
12+
[Parameter(Mandatory, Position = 1)]
13+
[string] $Repo,
14+
15+
[Parameter(Mandatory, Position = 2)]
16+
[string] $RunnerId,
17+
18+
[Parameter(Mandatory, Position = 2)]
19+
[string] $Label,
20+
21+
# Optional base URL of the GitHub API, for example "https://ghe.mycompany.com/api/v3/" (including the trailing slash).
22+
# Defaults to "https://api.github.com"
23+
[Uri] $BaseUri = [Uri]::new('https://api.github.com'),
24+
[Security.SecureString] $Token
25+
)
26+
27+
process {
28+
$Path = 'repos/{0}/{1}/actions/runners/{2}/labels/{3}' -f $Owner, $Repo, $RunnerId, $Label
29+
Invoke-GitHubApi $Path -BaseUri $BaseUri -Token $Token -Method Delete -Body $Body |
30+
ForEach-Object { $_ } |
31+
ForEach-Object {
32+
$_.PSTypeNames.Insert(0, 'PSGitHub.RunnerLabels')
33+
$_
34+
}
35+
}
36+
}

PSGitHub.psd1

+8
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,14 @@
196196
'Find-GitHubLabel',
197197
'Remove-GitHubLabel',
198198

199+
### GitHub Actions
200+
'Add-GitHubRunnerLabel',
201+
'Get-GitHubRunner',
202+
'Get-GitHubRunnerApplication',
203+
'Get-GitHubRunnerRegistrationToken',
204+
'Remove-GitHubRunner',
205+
'Remove-GitHubRunnerLabel'
206+
199207
### Miscellaneous
200208
'Get-GitHubLicense',
201209

0 commit comments

Comments
 (0)