v0.1.0 28f9d6e

parse.go RawHistoryFolder

1// SPDX-License-Identifier: MIT
2
3package workflow
4
5import (
6	"bnema.dev/ermite-actions/template"
7)
8
9// rootType is the schema definition a workflow file is read against; its
10// "on" key is required.
11const rootType = "workflow-root-strict"
12
13// Parse reads, validates and converts a workflow file. path is only used in
14// error messages, which read "path (Line: l, Col: c): message".
15//
16// The errors are the reference's: syntax errors, schema violations, unknown
17// contexts and functions in expressions, and the checks of the converter (job
18// and step ids, needs, filters, inputs). When there is any error the workflow
19// is nil. As in the reference, the converter only runs when the file passes
20// the schema. One check is not the reference's: an event that uses both a
21// filter and its "-ignore" counterpart (branches and branches-ignore, tags and
22// tags-ignore, paths and paths-ignore) is an error, as on GitHub.
23func Parse(path string, content []byte) (*Workflow, []Error) {
24	schema, err := template.WorkflowSchema()
25	if err != nil {
26		return nil, []Error{{Raw: "internal error: " + err.Error()}}
27	}
28	ctx := template.NewContext(schema)
29	root := template.ReadYAML(ctx, rootType, path, content)
30	w := &Workflow{File: path}
31	if root != nil && !ctx.HasErrors() {
32		c := &converter{ctx: ctx, schema: schema, w: w, jobIDs: newIDBuilder()}
33		c.convertRoot(root)
34		c.validateFilters()
35	}
36	errs := collect(ctx)
37	if len(errs) > 0 {
38		return nil, errs
39	}
40	return w, nil
41}
42
43func collect(ctx *template.Context) []Error {
44	var out []Error
45	for _, e := range ctx.Errors() {
46		out = append(out, *e)
47	}
48	return out
49}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 3

↑↓ moveenter openesc close