Guidedog Handbuch 0.6.3
Sprache
Auf dieser Seite
Guidedog / Dokumentation 0.6.3

pages

Package pages publishes Guidedog sites to GitHub Pages from a local machine (GDS 0008): it is the pages publisher of lib/plugins, linked into the guidedog-pages program, and reached by guidedog publish –publisher=pages through the process protocol. It allocates with context.allocator and frees nothing but tokens (forget clears them), so run it in an arena: guidedog-pages does, and lib/plugins gives each session, plan, and result an arena of its own.

A publication is one Git push to a branch that holds nothing but the site: the site’s files become Git objects (lib/git), and one receive-pack request over HTTPS carries the objects the branch lacks with the update of the branch from the commit last seen to the new one. GitHub applies the update only if the branch still has that commit, so a publication never overwrites a newer one. Pages then deploys the branch; publish waits for that deployment, for the new commit, and reports it Live only when GitHub says so.

What may be published where is the user’s decision, kept on their machine: a binding (bind) ties a credential profile to one repository, by its GitHub ID, and one branch; a project’s pages.toml can name a target, but never authorize one. Tokens stay in the system’s credential store (credential.odin). A journal written before the push lets recover settle a publication whose answer was lost.

Types

pages.Account :: struct

Account is the GitHub account a token belongs to.

login: string
name: string
id: i64
pages.Binding :: struct

Binding is a target the user authorized for a profile.

profile: string
repository: string

OWNER/REPO as GitHub named it when it was bound.

repository_id: i64
branch: string
account: string
account_id: i64
adopted: string

a commit the branch held, not made by Guidedog, adopted at bind.

bound: string
pages.Build :: struct

Build is a Pages build of a commit: its status („queued“, „building“, „built“, „errored“) and error.

status: string
commit: string
error: string
pages.Client :: struct

Client is a connection’s settings: the token it sends (none for the device flow), the roots it reaches, and the flag that cancels its transfers.

token: Secret
api: string
web: string
cancel: ^bool
pages.Config :: struct

Config is a pages.toml: where a site comes from and which repository and branch it is published to. It holds no secret: profile only names a stored token. Paths are absolute, resolved from the file’s folder.

path: string
owner: string
repo: string
branch: string
project: string

a Guidedog project, built as HTML; or

site: string

a site already built, published as it is.

profile: string
site_url: string
strict: bool
wait_seconds: int
debounce_ms: int
max_wait_ms: int
pages.Device_Code :: struct

Device_Code is what GitHub gives to start a device authorization.

device_code: string
user_code: string
verification_uri: string
expires_in: int
interval: int
pages.Journal :: struct

Journal is a publication in progress: what the branch held and what it is moved to.

operation: string

the candidate commit’s ID, which names the operation.

repository: string
repository_id: i64
branch: string
observed: string

the branch’s commit before, „“ for a new branch.

candidate: string
generation: string
accepted: bool

GitHub accepted the update.

started: string
pages.Pages_Plan :: struct

Pages_Plan is a plan’s state: the branch’s commit and tree as read, the new tree, and what is sent.

branch: string
head: git.Id
has_head: bool
remote_tree: string
tree: git.Id
trees: []git.Tree
send: []Send_File
site: Site
pages.Pages_Session :: struct

Pages_Session is a session’s state: the configuration, the binding that authorizes its target, the token, what GitHub says of the account and repository, the target’s key and lock, and the folder packs are written in.

config: Config
binding: Binding
token: Secret
client: Client
account: Account
repository: Repository
key: string
lock: ^os.File
work: string
pages.Problem :: plugins.Problem
pages.Profile :: struct

Profile is a stored token’s account.

name: string
account: string
account_id: i64
method: string

„device“ or „token“.

stored: string

the date it was stored.

pages.Push_Outcome :: enum u8

Push_Outcome is how a push ended: accepted, refused (nothing changed), or unknown (the answer was lost after the request was sent).

Accepted
Refused
Unknown
pages.Repository :: struct

Repository is what GitHub says of a repository.

id: i64
full_name: string
default_branch: string
private: bool
can_push: bool
can_admin: bool
pages.Review :: struct

Review is what a target is, read before it is authorized: the token’s account, the repository, its Pages settings, and what the branch holds.

account: Account
repository: Repository
site: Site
head: string

the branch’s commit, „“ when it does not exist.

others: bool

the branch holds a commit this publisher did not make.

pages.Secret :: struct

Secret is a token: bytes of its own, which forget clears and frees.

bytes: []u8
allocator: runtime.Allocator

the bytes‘ owner; zero uses the caller’s allocator.

pages.Send_File :: struct

Send_File is a blob a publication sends: a file of the snapshot, or (path „“) the empty .nojekyll the branch needs.

path: string
size: i64
id: git.Id
pages.Site :: struct

Site is a repository’s GitHub Pages settings, as far as the token may read them.

readable: bool

false: the token may not read them (they are then unknown).

exists: bool

the repository has a Pages site.

build_type: string

„legacy“ (from a branch) or „workflow“ (GitHub Actions).

branch: string
path: string

„/“ or „/docs“.

html_url: string
cname: string
public: bool

Procedures

pages.account :: proc(c: ^Client) -> (Account, Problem)

account reads the account of c’s token.

pages.bind :: proc(c: Config, profile: string, r: Review, adopt: bool) -> Problem

bind authorizes the target of c for profile, as review found it. A branch that holds work this publisher did not make is adopted (replaced by the next publication) only when adopt is set.

pages.branch_head :: proc(c: ^Client, owner, repo, branch: string) -> (id: git.Id, found: bool, p: Problem)

branch_head reads the commit refs/heads/BRANCH of owner/repo names; found is false when the branch does not exist.

pages.build_dir :: proc(s: ^plugins.Session) -> (string, Problem)

build_dir is where a project is built for the session’s target: a folder of this publisher’s cache, which no other build writes to.

pages.client :: proc(token: Secret, cancel: ^bool = nil) -> Client

client makes a client that sends token, which it borrows.

pages.commit_tree :: proc(c: ^Client, owner, repo, id: string) -> (tree, message: string, p: Problem)

commit_tree reads the tree and message of the commit id.

pages.configure_pages :: proc(c: ^Client, owner, repo, branch: string, create: bool) -> Problem

configure_pages makes GitHub Pages publish branch, from its root: it creates the site when there is none (create), and changes its source otherwise. It needs the Pages and Administration permissions.

pages.default_site_url :: proc(owner, repo: string) -> string

default_site_url is where GitHub serves a repository’s site: the root of OWNER.github.io for the repository of that name, and a folder of it for any other.

pages.delete_token :: proc(profile: string) -> (found: bool, p: Problem)

delete_token removes the token of profile from the store; found is false when it had none. It does not revoke the token at GitHub.

pages.drop_journal :: proc(key: string) -> Problem

drop_journal removes the journal of key, once its publication is settled.

pages.env_credential :: proc() -> bool

env_credential tells whether this run uses TOKEN_VARIABLE.

pages.find_binding :: proc(repository, branch: string) -> (Binding, bool, Problem)

find_binding is the binding of repository (OWNER/REPO, in any case) and branch.

pages.find_profile :: proc(name: string) -> (Profile, bool, Problem)

find_profile is the profile named name, and whether there is one.

pages.forget :: proc(s: ^Secret)

forget clears the secret’s bytes and frees them; a zero Secret is harmless.

pages.load_token :: proc(profile: string) -> (Secret, Problem)

load_token reads the token of profile from the store, or, for the profile „env“, from TOKEN_VARIABLE. The caller forgets it once it is done.

pages.lock :: proc(key: string) -> (^os.File, Problem)

lock takes the lock of key, held until unlock: one publication of a target runs at a time on this machine. A lock another process holds is refused at once, not waited for.

pages.noreply :: proc(a: Account) -> string

noreply is an account’s private commit address at GitHub, which publication commits use: no personal address enters the published branch.

pages.pages_build :: proc(c: ^Client, owner, repo, commit: string) -> (b: Build, found, readable: bool, p: Problem)

pages_build reads the most recent Pages build of commit; found is false when GitHub lists none yet, and readable false when the token may not read builds.

pages.pages_site :: proc(c: ^Client, owner, repo: string) -> (Site, Problem)

pages_site reads the Pages settings of owner/repo.

pages.plugin :: proc() -> plugins.Plugin

plugin describes GitHub Pages as a publication service in the common plugin table. Its publisher API and process protocol remain compatible with released hosts.

pages.publisher :: proc() -> plugins.Publisher

publisher is the pages publisher, for a registry.

pages.push :: proc(c: ^Client, owner, repo, branch, request: string, size: i64) -> (Push_Outcome, Problem)

push sends the request file at request, which moves the branch, and reads the report.

pages.read_bindings :: proc() -> ([]Binding, Problem)

read_bindings reads bindings.toml; none is an empty list.

pages.read_config :: proc(path: string) -> (c: Config, p: Problem)

read_config reads the configuration at path. A mistake is a problem that names its line and the fix.

pages.read_journal :: proc(key: string) -> (j: Journal, found: bool, p: Problem)

read_journal reads the journal of key; found is false when there is none.

pages.read_last :: proc(key: string) -> (Journal, bool, Problem)

read_last reads the last settled publication of key.

pages.read_profiles :: proc() -> ([]Profile, Problem)

read_profiles reads profiles.toml; none is an empty list.

pages.read_repository :: proc(c: ^Client, owner, repo: string) -> (Repository, Problem)

read_repository reads owner/repo.

pages.remember_token :: proc(profile: string, token: Secret, method: string, replace: bool) -> (Account, Problem)

remember_token checks token with GitHub and stores it as profile, by method („device“ or „token“). It refuses to replace a profile’s token with another account’s unless replace is set.

pages.remote_files :: proc(c: ^Client, owner, repo, id: string) -> (files: map[string]string, complete: bool, p: Problem)

remote_files reads the files of the tree id: each blob’s path and ID. complete is false when GitHub cut the list short, as it does for very large trees.

pages.remove_binding :: proc(repository, branch: string) -> (bool, Problem)

remove_binding removes the binding of repository and branch; false when there was none.

pages.remove_profile :: proc(name: string) -> Problem

remove_profile removes the profile named name from profiles.toml.

pages.render_config :: proc(owner, repo, branch, project, site, profile: string) -> string

render_config writes a pages.toml for repository and project (or site), with a comment on each setting.

pages.review_target :: proc(c: Config, token: Secret) -> (r: Review, p: Problem)

review_target reads the target of c with token.

pages.save_binding :: proc(binding: Binding) -> Problem

save_binding adds binding, replacing the binding of its repository and branch.

pages.save_profile :: proc(profile: Profile) -> Problem

save_profile adds or replaces the profile named profile.name.

pages.setup :: proc(c: Config, token: Secret, site: Site) -> Problem

setup makes GitHub Pages publish the branch of c from its root, creating the Pages site when there is none. It needs the Pages and Administration permissions.

pages.start_device :: proc(c: ^Client, client_id, scope: string) -> (Device_Code, Problem)

start_device asks GitHub for a device code for client_id, with scope (an OAuth App’s scopes, such as „public_repo“; a GitHub App ignores it).

pages.state_dir :: proc() -> (string, Problem)

state_dir is the publisher’s state folder, which it creates, readable only by the user.

pages.store_token :: proc(profile: string, token: Secret) -> Problem

store_token stores token under profile, replacing the profile’s token.

pages.target_key :: proc(repository_id: i64, branch: string) -> string

target_key names a target’s files: its repository ID and branch, with the branch’s slashes written as „~“.

pages.text :: proc(s: Secret) -> string

text is the secret as a string, borrowing its bytes.

pages.today :: proc() -> string

today is the date, YYYY-MM-DD, in UTC.

pages.unlock :: proc(f: ^os.File)

unlock releases a lock taken by lock; nil is harmless.

pages.valid_branch :: proc(name: string) -> bool

valid_branch tells whether name is a branch name Git accepts, from a safe alphabet.

pages.valid_owner :: proc(name: string) -> bool

valid_owner tells whether name can be a GitHub user or organization: 1 to 39 letters, digits, and single hyphens, not at either end.

pages.valid_profile :: proc(name: string) -> bool

valid_profile tells whether name can name a credential profile.

pages.valid_repo :: proc(name: string) -> bool

valid_repo tells whether name can be a repository: 1 to 100 letters, digits, and . _ -.

pages.valid_token :: proc(text: string) -> bool

valid_token tells whether text looks like a GitHub token: 20 to MAX_TOKEN letters, digits, and underscores. It does not tell whether GitHub accepts it.

pages.wait_device :: proc(c: ^Client, client_id: string, d: Device_Code) -> (Secret, Problem)

wait_device polls GitHub until the user authorizes the device code d, at the interval GitHub asks for (longer after slow_down), and returns the token. It stops at the code’s expiry, when the user denies it, or when cancel is set.

pages.write_journal :: proc(key: string, j: Journal) -> Problem

write_journal writes the journal of key, synced.

pages.write_last :: proc(key: string, j: Journal) -> Problem

write_last records j as the last settled publication of key.

Constants

pages.API_ROOT :: "https://api.github.com"

The GitHub roots publications reach. Only GitHub.com is supported: an Enterprise Server needs its own qualification. Tests point a client at a local server instead.

pages.CACHE_VARIABLE :: "GUIDEDOG_CACHE_DIR"

CACHE_VARIABLE, when set, names the folder that holds builds and packs instead of the user’s cache folder, for tests and portable installations.

pages.CLIENT_ID :: #config(GUIDEDOG_PAGES_CLIENT_ID, "")

CLIENT_ID is the client ID a release is built with (-define:GUIDEDOG_PAGES_CLIENT_ID=…), „“ when it has none; auth login –client-id names another.

pages.CONFIG_FILE :: "pages.toml"

CONFIG_FILE is the usual name of a publication’s configuration.

pages.CREDENTIAL_VARIABLE :: "GUIDEDOG_PAGES_CREDENTIAL"

CREDENTIAL_VARIABLE, set to „env“, chooses TOKEN_VARIABLE for runs the command line cannot reach, such as guidedog publish: the user’s explicit choice, as –credential=env.

pages.ENV_PROFILE :: "env"

ENV_PROFILE is the profile name that means TOKEN_VARIABLE.

pages.ID :: "pages"

ID is the publisher’s ID in a registry.

pages.MARK :: "Guidedog-Publication: "

MARK is the trailer a publication commit carries, with the generation it publishes: it tells this publisher’s commits from others on the branch.

pages.MAX_TOKEN :: 1024

MAX_TOKEN is the longest token accepted.

pages.ROOT_VARIABLE :: "GUIDEDOG_PAGES_TEST_ROOT"

ROOT_VARIABLE is the test server’s address in a test build.

pages.SERVICE :: "guidedog-pages"

SERVICE is the name tokens are stored under, with the profile as the account.

pages.STORE_NAME :: "the macOS Keychain"

Verfügbarkeit: Darwin.

STORE_NAME names the store in messages.

pages.STORE_NAME :: "the Secret Service (libsecret)"

Verfügbarkeit: Linux.

STORE_NAME names the store in messages.

pages.STORE_NAME :: "the Windows Credential Manager"

Verfügbarkeit: Windows.

STORE_NAME names the store in messages.

pages.TEST_BUILD :: #config(GUIDEDOG_PAGES_TEST_BUILD, false)

TEST_BUILD, set only by test builds (-define:GUIDEDOG_PAGES_TEST_BUILD=true), lets ROOT_VARIABLE point the program at a test server. A release cannot be pointed away from GitHub: its token goes nowhere else.

pages.TOKEN_VARIABLE :: "GUIDEDOG_PAGES_TOKEN"

TOKEN_VARIABLE holds a token for one process, read only with –credential=env.

pages.VERSION :: "0.6.3"

VERSION is the publisher’s version, which its handshake declares.

pages.WEB_ROOT :: "https://github.com"

Variables

pages.credential_override := ""

credential_override, when „env“, makes a session use TOKEN_VARIABLE instead of the profile’s stored token; the guidedog-pages command sets it for –credential=env.

Foreign imports

foreign import pages.advapi32 "system:Advapi32.lib"

Verfügbarkeit: Windows.

foreign import pages.corefoundation "system:CoreFoundation.framework"

Verfügbarkeit: Darwin.

foreign import pages.security "system:Security.framework"

Verfügbarkeit: Darwin.