|
4 | 4 |
|
5 | 5 |
|
6 | 6 | class RuntimeConfig(NamedTuple): |
7 | | - image: str # Full Docker image reference |
8 | | - file_name: str # Name that will be mounted under /scripts/ |
| 7 | + image: str # Full Docker image reference |
| 8 | + file_name: str # Name that will be mounted under /scripts/ |
9 | 9 | command: List[str] # Entrypoint executed inside the container |
10 | 10 |
|
11 | 11 |
|
@@ -38,10 +38,105 @@ class RuntimeConfig(NamedTuple): |
38 | 38 | "versions": ["1.20", "1.21", "1.22"], |
39 | 39 | "image_tpl": "golang:{version}-alpine", |
40 | 40 | "file_ext": "go", |
41 | | - "interpreter": ["sh", "-c", "go run /scripts/main.go"], |
| 41 | + "interpreter": ["go", "run"], |
42 | 42 | }, |
43 | 43 | } |
44 | 44 |
|
| 45 | +EXAMPLE_SCRIPTS: Dict[str, str] = { |
| 46 | + "python": """ |
| 47 | +# This f-string formatting works on all supported Python versions (3.7+) |
| 48 | +py_version = "3.x" |
| 49 | +print(f"Hello from a Python {py_version} script!") |
| 50 | +
|
| 51 | +# The following block uses Structural Pattern Matching, |
| 52 | +# which was introduced in Python 3.10. |
| 53 | +# THIS WILL CAUSE A SYNTAX ERROR ON VERSIONS < 3.10. |
| 54 | +
|
| 55 | +lang_code = 1 |
| 56 | +match lang_code: |
| 57 | + case 1: |
| 58 | + print("Structural Pattern Matching is available on this version (Python 3.10+).") |
| 59 | + case _: |
| 60 | + print("Default case.") |
| 61 | +""", |
| 62 | + "node": """ |
| 63 | +// This works on all supported Node versions (18+) |
| 64 | +console.log(`Hello from Node.js ${process.version}!`); |
| 65 | +
|
| 66 | +// The Promise.withResolvers() static method was introduced in Node.js 22. |
| 67 | +// This will throw a TypeError on versions < 22. |
| 68 | +if (typeof Promise.withResolvers === 'function') { |
| 69 | + const { promise, resolve } = Promise.withResolvers(); |
| 70 | + console.log("Promise.withResolvers() is supported (Node.js 22+)."); |
| 71 | + resolve('Success'); |
| 72 | + promise.then(msg => console.log(`Resolved with: ${msg}`)); |
| 73 | +} else { |
| 74 | + console.log("Promise.withResolvers() is not supported on this version."); |
| 75 | +} |
| 76 | +""", |
| 77 | + "ruby": """ |
| 78 | +# This works on all supported Ruby versions (3.1+) |
| 79 | +puts "Hello from Ruby #{RUBY_VERSION}!" |
| 80 | +
|
| 81 | +# The Data class for immutable value objects was introduced in Ruby 3.2. |
| 82 | +# This will cause an error on Ruby 3.1. |
| 83 | +begin |
| 84 | + # This line will fail on Ruby < 3.2 |
| 85 | + Point = Data.define(:x, :y) |
| 86 | + p = Point.new(1, 2) |
| 87 | + puts "Data objects are supported (Ruby 3.2+). Created point: #{p.inspect}" |
| 88 | +rescue NameError |
| 89 | + puts "Data objects are not supported on this version." |
| 90 | +end |
| 91 | +""", |
| 92 | + "bash": """ |
| 93 | +# This works on any modern Bash version |
| 94 | +echo "Hello from Bash version $BASH_VERSION" |
| 95 | +
|
| 96 | +# BASH_VERSINFO is an array holding version details. |
| 97 | +# We can check the major and minor version numbers. |
| 98 | +echo "Bash major version: ${BASH_VERSINFO[0]}" |
| 99 | +echo "Bash minor version: ${BASH_VERSINFO[1]}" |
| 100 | +
|
| 101 | +# The ${var@U} expansion for uppercasing was added in Bash 5.2 |
| 102 | +if [[ "${BASH_VERSINFO[0]}" -ge 5 && "${BASH_VERSINFO[1]}" -ge 2 ]]; then |
| 103 | + my_var="hello" |
| 104 | + echo "Testing variable expansion (Bash 5.2+ feature)..." |
| 105 | + echo "Original: $my_var, Uppercased: ${my_var@U}" |
| 106 | +else |
| 107 | + echo "The '${var@U}' expansion is not available in this Bash version." |
| 108 | +fi |
| 109 | +""", |
| 110 | + "go": """ |
| 111 | +package main |
| 112 | +
|
| 113 | +import ( |
| 114 | + "fmt" |
| 115 | + "runtime" |
| 116 | +) |
| 117 | +
|
| 118 | +// This function uses generics, available since Go 1.18, |
| 119 | +// so it will work on all supported versions (1.20+). |
| 120 | +func Print[T any](s T) { |
| 121 | + fmt.Println(s) |
| 122 | +} |
| 123 | +
|
| 124 | +func main() { |
| 125 | + Print(fmt.Sprintf("Hello from Go version %s!", runtime.Version())) |
| 126 | +
|
| 127 | + // The built-in 'clear' function for maps and slices |
| 128 | + // was introduced in Go 1.21. |
| 129 | + // THIS WILL FAIL TO COMPILE on Go 1.20. |
| 130 | + myMap := make(map[string]int) |
| 131 | + myMap["a"] = 1 |
| 132 | + Print(fmt.Sprintf("Map before clear: %v", myMap)) |
| 133 | + clear(myMap) // This line will fail on Go < 1.21 |
| 134 | + Print(fmt.Sprintf("Map after 'clear' (Go 1.21+ feature): length is %d", len(myMap))) |
| 135 | +} |
| 136 | +""", |
| 137 | +} |
| 138 | + |
| 139 | + |
45 | 140 | def _make_runtime_configs() -> Dict[str, Dict[str, RuntimeConfig]]: |
46 | 141 | registry: Dict[str, Dict[str, RuntimeConfig]] = {} |
47 | 142 |
|
|
0 commit comments