Skip to content

Commit

Permalink
feat(script): allow setting file extension
Browse files Browse the repository at this point in the history
Signed-off-by: Andrzej Ressel <[email protected]>
  • Loading branch information
andrzejressel committed Sep 15, 2024
1 parent 5ed1d83 commit fd469a3
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 99 deletions.
4 changes: 2 additions & 2 deletions docs/walk-through/scripts-and-results.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Scripts And Results

Often, you just want a template that executes a script specified as a here-script (also known as a `here document`) in the workflow spec. This example shows how to do that:
You can use a `script` template to execute an inline script (also known as a ["here document"](https://en.wikipedia.org/wiki/Here_document)):

```yaml
apiVersion: argoproj.io/v1alpha1
Expand Down Expand Up @@ -62,7 +62,7 @@ spec:
- name: gen-random-scala
script:
image: virtuslab/scala-cli:1.5.0
command: [scala-cli] # the scala-cli requires file to end in either `.scala` or `.sc`
command: [scala-cli] # the scala-cli requires files to end in either `.scala` or `.sc`
extension: sc # the file will now end in `.sc`
source: |
import scala.util.Random
Expand Down
4 changes: 2 additions & 2 deletions examples/scripts-java.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ spec:
- name: gen-random-int
script:
image: eclipse-temurin:22.0.2_9-jdk
command: [java]
extension: java
command: [java] # the Java interpreter requires files to end in `.java`
extension: java # the file will now end in `.java`
source: |
import java.util.*;
Expand Down
4 changes: 2 additions & 2 deletions examples/scripts-scala.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ spec:
- name: gen-random-int
script:
image: virtuslab/scala-cli:1.5.0
command: [scala-cli]
extension: sc
command: [scala-cli] # the scala-cli requires file to end in either `.scala` or `.sc`
extension: sc # the file will now end in `.sc`
source: |
import scala.util.Random
println(Random.between(0, 100))
Expand Down
3 changes: 1 addition & 2 deletions pkg/apis/workflow/v1alpha1/workflow_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -823,8 +823,7 @@ const (
)

func (tmpl *Template) GetScriptSourcePath() string {
extension := tmpl.Script.Extension
if len(extension) != 0 {
if tmpl.Script != nil && len(tmpl.Script.Extension) != 0 {
return executorScriptSourcePath + "." + tmpl.Script.Extension
} else {
return executorScriptSourcePath
Expand Down
47 changes: 0 additions & 47 deletions test/e2e/functional/scripts-java.yml

This file was deleted.

1 change: 1 addition & 0 deletions test/e2e/functional/scripts-java.yml
42 changes: 0 additions & 42 deletions test/e2e/functional/scripts-scala.yml

This file was deleted.

1 change: 1 addition & 0 deletions test/e2e/functional/scripts-scala.yml
3 changes: 1 addition & 2 deletions workflow/controller/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3088,8 +3088,7 @@ func (woc *wfOperationCtx) executeScript(ctx context.Context, nodeName string, t
if len(tmpl.Script.Source) == 0 {
woc.log.Warn("'script.source' is empty, suggest change template into 'container'")
} else {
scriptSourcePath := tmpl.GetScriptSourcePath()
mainCtr.Args = append(mainCtr.Args, scriptSourcePath)
mainCtr.Args = append(mainCtr.Args, tmpl.GetScriptSourcePath())
}
_, err = woc.createWorkflowPod(ctx, nodeName, []apiv1.Container{mainCtr}, tmpl, &createWorkflowPodOpts{
includeScriptOutput: includeScriptOutput,
Expand Down

0 comments on commit fd469a3

Please sign in to comment.