Skip to content

Commit

Permalink
Fix upload action
Browse files Browse the repository at this point in the history
  • Loading branch information
luismedel committed Nov 14, 2024
1 parent bdb756d commit b902001
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/bluish/actions/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,15 @@ def run(

class UploadFile(bluish.actions.base.Action):
FQN: str = "core/upload-file"
REQUIRED_INPUTS: tuple[str, ...] = ("source_file", "destination_file", "replace")
REQUIRED_INPUTS: tuple[str, ...] = ("source_file", "destination_file")

def run(
self, step: bluish.contexts.step.StepContext
) -> bluish.process.ProcessResult:
inputs = step.inputs

contents: str

source_file = inputs["source_file"]
source_file = os.path.expanduser(source_file)

Expand All @@ -94,19 +96,14 @@ def run(
contents = f.read()
info(f" - Read {len(contents)} bytes.")

replace = inputs["replace"]
replace = step.expand_expr(replace)

destination_file = inputs.get("destination_file")
assert destination_file is not None

info(f"Updating file: {destination_file}...")
updated_contents = contents.replace(replace[0], replace[1])


job = cast(bluish.contexts.job.JobContext, step.job)

info(f"Writing file to: {destination_file}...")
try:
job.write_file(destination_file, updated_contents.encode())
job.write_file(destination_file, contents.encode())
result = bluish.process.ProcessResult()
except IOError as e:
error(f"Failed to write file: {str(e)}")
Expand Down

0 comments on commit b902001

Please sign in to comment.