ci: [refactor] Move github_import_vs_env to python script
What changed, and why it matters
This is a routine cleanup of Bitcoin Core's Windows CI (continuous integration) scripts. It moves a PowerShell snippet that imports Visual Studio environment variables into a Python helper, renames a YAML anchor, and simplifies some repetitive code. There is no security-relevant change.
No security action required. Treat as normal CI maintenance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors GitHub Actions Windows CI logic. The PowerShell step that runs vswhere.exe and vsdevcmd.bat to populate GITHUB_ENV is relocated into a new Python function github_import_vs_env() in .github/ci-windows.py. The YAML anchor is renamed from SET_UP_VS to IMPORT_VS_ENV, and the step name is updated. Additionally, both Python scripts replace explicit if/elif step dispatch with exec(f'{args.step}()') and derive the step name list from function objects. No cryptographic, consensus, networking, or privilege-sensitive code is modified.
Changed components
.github/ci-windows.py.github/ci-windows-cross.py.github/workflows/ci.ymlInspect captured patch +45 / −46
diff --git a/.github/ci-windows-cross.py b/.github/ci-windows-cross.py
index 13ca3b49..90cd59c7 100755
--- a/.github/ci-windows-cross.py
+++ b/.github/ci-windows-cross.py
@@ -134,13 +134,13 @@ def run_unit_tests():
def main():
parser = argparse.ArgumentParser(description="Utility to run Windows CI steps.")
- steps = [
- "print_version",
- "check_manifests",
- "prepare_tests",
- "run_unit_tests",
- "run_functional_tests",
- ]
+ steps = list(map(lambda f: f.__name__, [
+ print_version,
+ check_manifests,
+ prepare_tests,
+ run_unit_tests,
+ run_functional_tests,
+ ]))
parser.add_argument("step", choices=steps, help="CI step to perform.")
args = parser.parse_args()
@@ -149,16 +149,7 @@ def main():
str(Path.cwd() / "previous_releases"),
)
- if args.step == "print_version":
- print_version()
- elif args.step == "check_manifests":
- check_manifests()
- elif args.step == "prepare_tests":
- prepare_tests()
- elif args.step == "run_unit_tests":
- run_unit_tests()
- elif args.step == "run_functional_tests":
- run_functional_tests()
+ exec(f'{args.step}()')
if __name__ == "__main__":
diff --git a/.github/ci-windows.py b/.github/ci-windows.py
index caa2d52c..16d7db7a 100755
--- a/.github/ci-windows.py
+++ b/.github/ci-windows.py
@@ -38,6 +38,29 @@ GENERATE_OPTIONS = {
}
+def github_import_vs_env(_ci_type):
+ vswhere_path = Path(os.environ["ProgramFiles(x86)"]) / "Microsoft Visual Studio" / "Installer" / "vswhere.exe"
+ installation_path = run(
+ [str(vswhere_path), "-latest", "-property", "installationPath"],
+ capture_output=True,
+ text=True,
+ ).stdout.strip()
+ vsdevcmd = Path(installation_path) / "Common7" / "Tools" / "vsdevcmd.bat"
+ comspec = os.environ["COMSPEC"]
+ output = run(
+ f'"{comspec}" /s /c ""{vsdevcmd}" -arch=x64 -no_logo && set"',
+ capture_output=True,
+ text=True,
+ ).stdout
+ github_env = os.environ["GITHUB_ENV"]
+ with open(github_env, "a") as env_file:
+ for line in output.splitlines():
+ if "=" not in line:
+ continue
+ name, value = line.split("=", 1)
+ env_file.write(f"{name}={value}\n")
+
+
def generate(ci_type):
command = [
"cmake",
@@ -50,7 +73,7 @@ def generate(ci_type):
run(command)
-def build():
+def build(_ci_type):
command = [
"cmake",
"--build",
@@ -180,26 +203,18 @@ def run_tests(ci_type):
def main():
parser = argparse.ArgumentParser(description="Utility to run Windows CI steps.")
parser.add_argument("ci_type", choices=GENERATE_OPTIONS, help="CI type to run.")
- steps = [
- "generate",
- "build",
- "check_manifests",
- "prepare_tests",
- "run_tests",
- ]
+ steps = list(map(lambda f: f.__name__, [
+ github_import_vs_env,
+ generate,
+ build,
+ check_manifests,
+ prepare_tests,
+ run_tests,
+ ]))
parser.add_argument("step", choices=steps, help="CI step to perform.")
args = parser.parse_args()
- if args.step == "generate":
- generate(args.ci_type)
- elif args.step == "build":
- build()
- elif args.step == "check_manifests":
- check_manifests(args.ci_type)
- elif args.step == "prepare_tests":
- prepare_tests(args.ci_type)
- elif args.step == "run_tests":
- run_tests(args.ci_type)
+ exec(f'{args.step}("{args.ci_type}")')
if __name__ == "__main__":
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 9bc798dc..2059adc4 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -227,16 +227,9 @@ jobs:
- *CHECKOUT
- - &SET_UP_VS
- name: Set up VS Developer Prompt
- shell: pwsh -Command "$PSVersionTable; $PSNativeCommandUseErrorActionPreference = $true; $ErrorActionPreference = 'Stop'; & '{0}'"
- run: |
- $vswherePath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
- $installationPath = & $vswherePath -latest -property installationPath
- & "${env:COMSPEC}" /s /c "`"$installationPath\Common7\Tools\vsdevcmd.bat`" -arch=x64 -no_logo && set" | foreach-object {
- $name, $value = $_ -split '=', 2
- echo "$name=$value" >> $env:GITHUB_ENV
- }
+ - &IMPORT_VS_ENV
+ name: Import Visual Studio env vars
+ run: py -3 .github/ci-windows.py "standard" github_import_vs_env
- name: Get tool information
shell: pwsh
@@ -418,7 +411,7 @@ jobs:
- name: Run bitcoind.exe
run: py -3 .github/ci-windows-cross.py print_version
- - *SET_UP_VS
+ - *IMPORT_VS_ENV
- name: Check executable manifests
run: py -3 .github/ci-windows-cross.py check_manifests
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.