Repository navigation
Expand file tree
/
Copy pathruby-sdk.dang
More file actions
72 lines (64 loc) · 3.06 KB
/
Copy pathruby-sdk.dang
File metadata and controls
72 lines (64 loc) · 3.06 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
"""
The Ruby SDK: creates and regenerates Ruby modules and the clients they and plain programs use, and checks the modules with Steep.
"""
type RubySdk {
"""
The starter of a new module: default or empty.
"""
pub template: String! = "default"
"""
Written to .ruby-version; the module then builds on the ruby:<version> image.
"""
pub rubyVersion: String! = ""
"""
The scope that contains the workspace cwd: the directory of the nearest Gemfile.
"""
pub findClientRoot(ws: Workspace!): String {
(JSON.decode(ruby.call("findClientRoot", JSON.encode({{ws: ws.id}}))) :: String)
}
"""
Generate one scope: its members, its dagger.gemfile, and for a module its manifest and entrypoint.
"""
pub generateScope(ws: Workspace!, isModule: Boolean!, name: String!, clients: [ModuleSource!]!): Workspace! {
let args = JSON.encode({{ws: ws.id, isModule: isModule, name: name, clients: clients.map { client => client.id }}})
let id = (JSON.decode(ruby.call("generateScope", args)) :: String!)
let generated = node(id: (id :: ID!)).{{... on Workspace!}}
# The Ruby half replaces sdk/ whole, so the configuration comes from ws, as the user left it.
let existing = ws.directory(".", include: [dangConfigPath])
let found = existing.exists(dangConfigPath)
if (isModule) {
# withWorkdir takes a path from the workspace root and refuses an absolute one.
let scope = "." + ws.cwd
sdkHelpers.dangConfig(loadToml: if (found) { existing.file(dangConfigPath) } else { null })
.withVersion("2.1")
.withDaggerImport(name: "Dagger", version: targetVersion)
.generate(generated.withWorkdir(scope + "/sdk/entrypoint"))
.withWorkdir(scope)
} else if (found) {
generated.withFile(dangConfigPath, existing.file(dangConfigPath))
} else {
generated
}
}
"""
dagger generate accepts every Ruby module this SDK generated in the workspace, unless sdk-helpers refuses its sdk/entrypoint/dang.toml, which the check does not read, and Steep passes on each with a Steepfile: a module is a directory whose manifest names ./sdk/entrypoint, whose sdk/ carries the SDK's marker, and which has a Gemfile. The check runs generation's own refusals on each, then Steep in the module's image with its Gemfile's development group, which the module's container never installs.
"""
pub steep(ws: Workspace!): Void @check {
ruby.call("steep", JSON.encode({{ws: ws.id}}))
null
}
"""
The Ruby module at or above a path of the workspace, to act on alone: dagger call ruby-sdk mod --path <module> steep.
"""
pub mod(ws: Workspace!, path: String! = "."): Mod! {
Mod(path: path, ws: ws, ruby: ruby)
}
let ruby: RubyHalf! {
RubyHalf(template: template, rubyVersion: rubyVersion, targetVersion: targetVersion)
}
# The Dagger version of what generation writes: the view of a scope's clients,
# and a module's DAGGER_CLIENT_VERSION and dang.toml. RubyHalf's clientVersion
# is the Ruby half's own.
let targetVersion: String! = "v1.0.0-beta.30"
let dangConfigPath: String! = "sdk/entrypoint/dang.toml"
}