I have created a test, to ensure that the content of the license file does not change. The test looks like the following:
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"
In GitHub I'm running the test in a matrix with the os set to "ubuntu-latest", "macos-latest", and "windows-latest". Version of Python is set to 3.8.
For both Ubuntu and MacOS the test is passing. But the assertion fails on Windows.
I have read that open
replaces line endings on Windows, if the mode is set to r
. But opening the file with rb
should not alter the file. I have also tried to replace the mode with r+b
. The tests pasases on both Unix systems, but not Windows.
Are hashlib working different on Windows? It shouldn't. Are the pipeline altering files? It shouldn't.
I don't have a Windows machine to validate which part is altering the file or if hashlib have a bug in the Windows implementation. Most likely the first part.
Am I missing the obvious?
Are the pipeline altering files? It shouldn't.
Following Iłya Bursov's advice showed that the checkout of source code changed file endings as default on Windows.
It's a known hurdle (but not a bug): https://github.com/actions/checkout/issues/135#issuecomment-602171132
Fixed using:
steps:
- name: Set git to use LF
run: |
git config --global core.autocrlf false
- uses: actions/checkout@v2
However I didn't force line endings to be lf
as posted in the answer on GitHub.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.