main 98594d0

convert_container.go RawHistoryFolder

1// SPDX-License-Identifier: MIT
2
3package workflow
4
5import (
6	"bnema.dev/ermite-actions/template"
7)
8
9// convertContainer validates a job container or, when service is set, a
10// service container. A token that contains an expression is not checked, as
11// in the reference.
12func (c *converter) convertContainer(t template.Token, service bool) {
13	if template.HasExpression(t) {
14		return
15	}
16	if _, ok := t.(*template.String); ok {
17		return
18	}
19	var image template.Token
20	c.handle(t, func() {
21		m := asMap(t, "container item")
22		for _, p := range m.Pairs {
23			key := asString(p.Key, "container item key")
24			v := p.Value
25			switch key.Value {
26			case "image":
27				image = asString(v, "container image")
28			case "credentials":
29				c.convertCredentials(v)
30			case "env":
31				for _, e := range asMap(v, "container env").Pairs {
32					asString(e.Key, "container env value")
33				}
34			case "ports":
35				for _, it := range asSeq(v, "container ports").Items {
36					asString(it, "container port")
37				}
38			case "volumes":
39				for _, it := range asSeq(v, "container volumes").Items {
40					asString(it, "container volume")
41				}
42			case "options":
43				asString(v, "container options")
44			case "entrypoint":
45				if !service {
46					c.ctx.Errorf(key, "Unexpected container item key: %s", key.Value)
47					continue
48				}
49				asString(v, "container entrypoint")
50			case "command":
51				if !service {
52					c.ctx.Errorf(key, "Unexpected container item key: %s", key.Value)
53					continue
54				}
55				asString(v, "container command")
56			default:
57				c.ctx.Errorf(key, "Unexpected container item key: %s", key.Value)
58			}
59		}
60	})
61	if image == nil {
62		if _, isMap := t.(*template.Mapping); isMap {
63			c.ctx.ErrorAt(t, "Container image cannot be empty")
64		}
65	}
66}
67
68func (c *converter) convertCredentials(t template.Token) {
69	for _, p := range asMap(t, "credentials").Pairs {
70		key := asString(p.Key, "credentials item")
71		switch key.Value {
72		case "username":
73			asString(p.Value, "credentials username")
74		case "password":
75			asString(p.Value, "credentials password")
76		default:
77			c.ctx.Errorf(key, "credentials key %s", key.Value)
78		}
79	}
80}
81
82// convertServices validates the services mapping of a job.
83func (c *converter) convertServices(t template.Token) {
84	for _, p := range asMap(t, "services").Pairs {
85		asString(p.Key, "service key")
86		c.convertContainer(p.Value, true)
87	}
88}

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