From ad2945fc489056ab3ac969885c15b8bce371b90f Mon Sep 17 00:00:00 2001 From: Thomas Sibley Date: Thu, 6 Jun 2024 11:26:44 -0700 Subject: [PATCH] actions/shellcheck: Hint to ShellCheck what job and step env vars are 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. --- actions/shellcheck/extract-shell-from-gh-actions-files | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/actions/shellcheck/extract-shell-from-gh-actions-files b/actions/shellcheck/extract-shell-from-gh-actions-files index 78a698e..3fba868 100755 --- a/actions/shellcheck/extract-shell-from-gh-actions-files +++ b/actions/shellcheck/extract-shell-from-gh-actions-files @@ -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)