From 8a0a37288481a497fb3f51e6579b81e0cf5413ee 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 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/actions/shellcheck/extract-shell-from-gh-actions-files b/actions/shellcheck/extract-shell-from-gh-actions-files index 78a698e..fbdf491 100755 --- a/actions/shellcheck/extract-shell-from-gh-actions-files +++ b/actions/shellcheck/extract-shell-from-gh-actions-files @@ -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)