Repository: kestra-io/kestra (java)

Issue:
Can't use variables for inputFiles:
### Describe the issue

I'm using the git push task to commit a file to a git repo. It seems that `inputFiles` only supports static filenames such as:

```
inputFiles:
  file.tmp: "{{ inputs['my-file'] }}"
```
You can't use variables in the filename such as:

```
  - id: push
	type: io.kestra.plugin.git.Push
	username: kestra
	password: "{{ secret('GITLAB_PAT') }}"
	#branch: kestra
	branch: main
	inputFiles:
	  drafts/draft_"{{trigger.body.post.id}}".md: "{{ inputs['my-file'] }}"
```
Or:

```
inputFiles:
  drafts/draft_{{ trigger.body.post.id }}.md: "{{ inputs['my-file'] }}"
  ```
  
  This creates files such as:
  
  - draft_"{{trigger.body.post.id}}".md
  - draft_{{trigger.body.post.id}}.md

### Environment

- Kestra Version: 0.16.8
- Operating System (OS/Docker/Kubernetes): Docker

Pull request:
fix(core): render input files
Fixes #3853

Patch:
diff --git a/core/src/main/java/io/kestra/core/runners/FilesService.java b/core/src/main/java/io/kestra/core/runners/FilesService.java
index 823f1e197..c8b30a27d 100644
--- a/core/src/main/java/io/kestra/core/runners/FilesService.java
+++ b/core/src/main/java/io/kestra/core/runners/FilesService.java
@@ -37,7 +37,7 @@ public abstract class FilesService {
 
          inputFiles
              .forEach(throwBiConsumer((fileName, input) -> {
-                 var file = new File(runContext.tempDir().toString(), fileName);
+                 var file = new File(runContext.tempDir().toString(), runContext.render(fileName, additionalVars));
 
                  if (!file.getParentFile().exists()) {
                      //noinspection ResultOfMethodCallIgnored
diff --git a/core/src/main/java/io/kestra/core/tasks/PluginUtilsService.java b/core/src/main/java/io/kestra/core/tasks/PluginUtilsService.java
index e3615b5b9..27e32acc9 100644
--- a/core/src/main/java/io/kestra/core/tasks/PluginUtilsService.java
+++ b/core/src/main/java/io/kestra/core/tasks/PluginUtilsService.java
@@ -27,8 +27,9 @@ import jakarta.validation.constraints.NotNull;
 import static io.kestra.core.utils.Rethrow.throwConsumer;
 
 abstract public class PluginUtilsService {
-    protected static final ObjectMapper MAPPER = JacksonMapper.ofJson();
+    private static final ObjectMapper MAPPER = JacksonMapper.ofJson();
     private static final Pattern PATTERN = Pattern.compile("^::(\\{.*})::$");
+    private static final TypeReference<Map<String, String>> MAP_TYPE_REFERENCE = new TypeReference<>() {};
 
     public static Map<String, String> createOutputFiles(
         Path tempDirectory,
@@ -90,13 +91,13 @@ abstract public class PluginUtilsService {
     @SuppressWarnings("unchecked")
     public static Map<String, String> transformInputFiles(RunContext runContext, Map<String, Object> additionalVars, @NotNull Object inputFiles) throws IllegalVariableEvaluationException, JsonProcessingException {
         if (inputFiles instanceof Map) {
-            return (Map<String, String>) inputFiles;
+            return runContext.renderMap((Map<String, String>) inputFiles);
         } else if (inputFiles instanceof String) {
-            final TypeReference<Map<String, String>> reference = new TypeReference<>() {};
+
 
             return JacksonMapper.ofJson(false).readValue(
                 runContext.render((String) inputFiles, additionalVars),
-                reference
+                MAP_TYPE_REFERENCE
             );
         } else {
             throw new IllegalVariableEvaluationException("Invalid `files` properties with type '" + (inputFiles != null ? inputFiles.getClass() : "null") + "'");


Test patch:
diff --git a/core/src/test/java/io/kestra/core/runners/FilesServiceTest.java b/core/src/test/java/io/kestra/core/runners/FilesServiceTest.java
index 09e3ac20c..f1dba2ca1 100644
--- a/core/src/test/java/io/kestra/core/runners/FilesServiceTest.java
+++ b/core/src/test/java/io/kestra/core/runners/FilesServiceTest.java
@@ -5,6 +5,7 @@ import jakarta.inject.Inject;
 import org.apache.commons.io.FileUtils;
 import org.junit.jupiter.api.Test;
 
+import java.net.URI;
 import java.util.Map;
 
 import static org.hamcrest.MatcherAssert.assertThat;
@@ -25,4 +26,20 @@ class FilesServiceTest {
         String fileContent = FileUtils.readFileToString(runContext.tempDir().resolve("file.txt").toFile(), "UTF-8");
         assertThat(fileContent, is("overriden content"));
     }
+
+    @Test
+    void renderInputFile() throws Exception {
+        RunContext runContext = runContextFactory.of(Map.of("filename", "file.txt", "content", "Hello World"));
+        Map<String, String> content = FilesService.inputFiles(runContext, Map.of("{{filename}}", "{{content}}"));
+        assertThat(content.get("file.txt"), is("Hello World"));
+    }
+
+    @Test
+    void outputFiles() throws Exception {
+        RunContext runContext = runContextFactory.of();
+        Map<String, String> files = FilesService.inputFiles(runContext, Map.of("file.txt", "content"));
+
+        Map<String, URI> outputs = FilesService.outputFiles(runContext, files.keySet().stream().toList());
+        assertThat(outputs.size(), is(1));
+    }
 }