Skip to content

Commit

Permalink
actions/shellcheck: Hint to ShellCheck what job and step env vars are…
Browse files Browse the repository at this point in the history
… defined

By default it already assumes UPPERCASE vars are always defined
externally, but it will warn about lowercase vars that it doesn't know
about.  Resolves a warning about the use of a "runtime" env var in
actions/setup-nextstrain-cli.
  • Loading branch information
tsibley committed Jun 6, 2024
1 parent f3b5e25 commit ad2945f
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions actions/shellcheck/extract-shell-from-gh-actions-files
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,16 @@ def extract_shell_steps(workflow, job, job_output_dir, terminator):
# by ShellCheck.
run_shell = re.sub(r'\$\{\{.+?\}\}', "…", run_shell)

# Use job and step env to hint to ShellCheck what env vars are defined.
# By default it already assumes UPPERCASE vars are always defined, but
# it will warn about lowercase vars that it doesn't know about.
env = {**job.get("env", {}), **step.get("env", {})}

step_output_file = job_output_dir / f"step-{fssafe(step_name)}"

with step_output_file.open("w", encoding = "utf-8") as fh:
print(f"#!/bin/{shell}", file = fh)
print("export", *env.keys(), file = fh)
print(run_shell, file = fh)

print(step_output_file, end = terminator)
Expand Down

0 comments on commit ad2945f

Please sign in to comment.