You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GitHub Actions中Ubuntu与Windows下hashlib哈希结果不一致问题排查

GitHub Actions中Windows平台LICENSE文件哈希验证失败

我创建了一项测试以确保LICENSE文件内容未被修改,测试代码如下:

license_file = context.root_dir.joinpath("LICENSE")

with open(license_file, "rb") as license_fd:
    content = license_fd.read()
license_hash = hashlib.sha224(content).hexdigest()

# Compare to "sha224sum LICENSE" of initial commit
# TODO: Figure out why Windows gives another hash
# assert license_hash == "45fd0b382919a02f391b9ce13e70ed703b9569cce812332d03c514a2"

我在GitHub Actions中设置了包含ubuntu-latest、macos-latest、windows-latest的操作系统矩阵,Python版本为3.8。该测试在Ubuntu和MacOS上均可通过,但在Windows上断言失败。

我了解到使用r模式打开文件时,Windows系统会替换换行符,但使用rb模式应不会修改文件内容。我也曾尝试改用r+b模式,测试仍仅在类Unix系统通过,Windows依然失败。

hashlib在Windows上的运行逻辑应该不会有差异,也不认为是流水线修改了文件。我没有Windows设备来验证到底是哪部分修改了文件,还是Windows版hashlib存在bug,大概率是前者。想问问我是否忽略了什么显而易见的问题?

内容的提问来源于stack exchange,提问作者YnkDK

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 23:05:30