Skip to content

Commit ceff677

Browse files
committed
Merge bitcoin#34583: ci: [refactor] Drop last use of pwsh
fa36ade ci: [refactor] Drop last use of pwsh (MarcoFalke) fae31b1 ci: [refactor] Move github_import_vs_env to python script (MarcoFalke) Pull request description: The use of pwsh was a bit confusing and inconsistent around the exit code. See also bitcoin#32672 I think it is fine to drop it and purely use Bash/Python. This also moves a bit of code from the github yaml to the python script. ACKs for top commit: m3dwards: Looks good! re-ACK bitcoin@fa36ade hodlinator: re-ACK fa36ade Tree-SHA512: 78edffc60c58c476b0acca5224150169d154b0b818114844a04295af9ba19b7cdf1fb2afb738f6cafd6172f0f477d546018ebf95061eb5bd8bbb35e065a129d4
2 parents b0833b5 + fa36ade commit ceff677

3 files changed

Lines changed: 51 additions & 52 deletions

File tree

.github/ci-windows-cross.py

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,13 @@ def run_unit_tests():
134134

135135
def main():
136136
parser = argparse.ArgumentParser(description="Utility to run Windows CI steps.")
137-
steps = [
138-
"print_version",
139-
"check_manifests",
140-
"prepare_tests",
141-
"run_unit_tests",
142-
"run_functional_tests",
143-
]
137+
steps = list(map(lambda f: f.__name__, [
138+
print_version,
139+
check_manifests,
140+
prepare_tests,
141+
run_unit_tests,
142+
run_functional_tests,
143+
]))
144144
parser.add_argument("step", choices=steps, help="CI step to perform.")
145145
args = parser.parse_args()
146146

@@ -149,16 +149,7 @@ def main():
149149
str(Path.cwd() / "previous_releases"),
150150
)
151151

152-
if args.step == "print_version":
153-
print_version()
154-
elif args.step == "check_manifests":
155-
check_manifests()
156-
elif args.step == "prepare_tests":
157-
prepare_tests()
158-
elif args.step == "run_unit_tests":
159-
run_unit_tests()
160-
elif args.step == "run_functional_tests":
161-
run_functional_tests()
152+
exec(f'{args.step}()')
162153

163154

164155
if __name__ == "__main__":

.github/ci-windows.py

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,29 @@ def run(cmd, **kwargs):
3838
}
3939

4040

41+
def github_import_vs_env(_ci_type):
42+
vswhere_path = Path(os.environ["ProgramFiles(x86)"]) / "Microsoft Visual Studio" / "Installer" / "vswhere.exe"
43+
installation_path = run(
44+
[str(vswhere_path), "-latest", "-property", "installationPath"],
45+
capture_output=True,
46+
text=True,
47+
).stdout.strip()
48+
vsdevcmd = Path(installation_path) / "Common7" / "Tools" / "vsdevcmd.bat"
49+
comspec = os.environ["COMSPEC"]
50+
output = run(
51+
f'"{comspec}" /s /c ""{vsdevcmd}" -arch=x64 -no_logo && set"',
52+
capture_output=True,
53+
text=True,
54+
).stdout
55+
github_env = os.environ["GITHUB_ENV"]
56+
with open(github_env, "a") as env_file:
57+
for line in output.splitlines():
58+
if "=" not in line:
59+
continue
60+
name, value = line.split("=", 1)
61+
env_file.write(f"{name}={value}\n")
62+
63+
4164
def generate(ci_type):
4265
command = [
4366
"cmake",
@@ -50,7 +73,7 @@ def generate(ci_type):
5073
run(command)
5174

5275

53-
def build():
76+
def build(_ci_type):
5477
command = [
5578
"cmake",
5679
"--build",
@@ -180,26 +203,18 @@ def run_tests(ci_type):
180203
def main():
181204
parser = argparse.ArgumentParser(description="Utility to run Windows CI steps.")
182205
parser.add_argument("ci_type", choices=GENERATE_OPTIONS, help="CI type to run.")
183-
steps = [
184-
"generate",
185-
"build",
186-
"check_manifests",
187-
"prepare_tests",
188-
"run_tests",
189-
]
206+
steps = list(map(lambda f: f.__name__, [
207+
github_import_vs_env,
208+
generate,
209+
build,
210+
check_manifests,
211+
prepare_tests,
212+
run_tests,
213+
]))
190214
parser.add_argument("step", choices=steps, help="CI step to perform.")
191215
args = parser.parse_args()
192216

193-
if args.step == "generate":
194-
generate(args.ci_type)
195-
elif args.step == "build":
196-
build()
197-
elif args.step == "check_manifests":
198-
check_manifests(args.ci_type)
199-
elif args.step == "prepare_tests":
200-
prepare_tests(args.ci_type)
201-
elif args.step == "run_tests":
202-
run_tests(args.ci_type)
217+
exec(f'{args.step}("{args.ci_type}")')
203218

204219

205220
if __name__ == "__main__":

.github/workflows/ci.yml

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -238,26 +238,19 @@ jobs:
238238

239239
- *CHECKOUT
240240

241-
- &SET_UP_VS
242-
name: Set up VS Developer Prompt
243-
shell: pwsh -Command "$PSVersionTable; $PSNativeCommandUseErrorActionPreference = $true; $ErrorActionPreference = 'Stop'; & '{0}'"
244-
run: |
245-
$vswherePath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
246-
$installationPath = & $vswherePath -latest -property installationPath
247-
& "${env:COMSPEC}" /s /c "`"$installationPath\Common7\Tools\vsdevcmd.bat`" -arch=x64 -no_logo && set" | foreach-object {
248-
$name, $value = $_ -split '=', 2
249-
echo "$name=$value" >> $env:GITHUB_ENV
250-
}
241+
- &IMPORT_VS_ENV
242+
name: Import Visual Studio env vars
243+
run: py -3 .github/ci-windows.py "standard" github_import_vs_env
251244

252245
- name: Get tool information
253-
shell: pwsh
254246
run: |
255-
cmake -version | Tee-Object -FilePath "cmake_version"
256-
Write-Output "---"
257-
msbuild -version | Tee-Object -FilePath "msbuild_version"
258-
$env:VCToolsVersion | Tee-Object -FilePath "toolset_version"
247+
set -o errexit -o pipefail -o xtrace -o nounset
248+
249+
cmake -version | tee cmake_version
250+
echo '---'
251+
msbuild.exe -version | tee msbuild_version
252+
echo "${VCToolsVersion-}" | tee toolset_version
259253
py -3 --version
260-
Write-Host "PowerShell version $($PSVersionTable.PSVersion.ToString())"
261254
bash --version
262255
263256
- name: Using vcpkg with MSBuild
@@ -430,7 +423,7 @@ jobs:
430423
- name: Run bitcoind.exe
431424
run: py -3 .github/ci-windows-cross.py print_version
432425

433-
- *SET_UP_VS
426+
- *IMPORT_VS_ENV
434427

435428
- name: Check executable manifests
436429
run: py -3 .github/ci-windows-cross.py check_manifests

0 commit comments

Comments
 (0)