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 8a0a372
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 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,17 @@ 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)
if env:
print("export", *env.keys(), file = fh)
print(run_shell, file = fh)

print(step_output_file, end = terminator)
Expand Down

0 comments on commit 8a0a372

Please sign in to comment.