-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathghpagescf.ps1
More file actions
executable file
·50 lines (40 loc) · 1.37 KB
/
Copy pathghpagescf.ps1
File metadata and controls
executable file
·50 lines (40 loc) · 1.37 KB
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
<#
.SYNOPSIS
Create a GitHub Pages and set up CloudFlare DNS to point to it
.DESCRIPTION
Depends on cfcli from https://www.npmjs.com/package/cloudflare-cli
Depends on gh from https://cli.github.com/
.PARAMETER Label
String like "myproj" that is the subdomain for your cloudflare account
#>
param(
[Parameter(Mandatory = $true)]
[string] $Label
)
$script:ErrorActionPreference = "Stop"
Set-StrictMode -Version Latest
$reg = '^[a-z0-9-]+$'
if (-not ($Label -match $reg)) {
throw "label doesn't match /$reg/"
}
$records = cfcli find $Label -f json | ConvertFrom-Json
if (!$records) {
$remote = git ls-remote --get-url
if (-not ($remote -match "github.com.(\w+)")) {
throw "$remote isn't a github URL?"
}
$owner = $Matches[1]
cfcli -t CNAME add $Label "$owner.github.io"
$records = cfcli find $Label -f json | ConvertFrom-Json
}
$defaultBranch = (git symbolic-ref refs/remotes/origin/HEAD) -replace 'refs/remotes/origin/', ''
$body = @{
source = @{
branch = $defaultBranch
path = "/"
}
}
# Little strange to need two calls; submitted feedback to GitHub
$body | ConvertTo-Json | gh api /repos/:owner/:repo/pages --input - --header "Accept:application/vnd.github.switcheroo-preview+json"
$body.cname = $($records.name)
$body | ConvertTo-Json | gh api -X PUT /repos/:owner/:repo/pages --input - --header "Accept:application/vnd.github.switcheroo-preview+json"