簡體   English   中英

Hashlib 通過 GitHub 動作對 Ubuntu 和 Windows 產生不同的結果

[英]Hashlib produces different results on Ubuntu and Windows via GitHub actions

我創建了一個測試,以確保許可證文件的內容不會改變。 測試如下所示:

    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 中,我在一個矩陣中運行測試,操作系統設置為“ubuntu-latest”、“macos-latest”和“windows-latest”。 Python 的版本設置為 3.8。

對於 Ubuntu 和 MacOS,測試都通過了。 但是 Windows 上的斷言失敗。

我讀過open替換 Windows 上的行尾,如果模式設置為r 但是用rb打開文件不應該改變文件。 我也嘗試用r+b替換模式。 測試在 Unix 系統上都通過了,但在 Windows 上沒有通過。

hashlib 在 Windows 上的工作方式是否不同? 它不應該。 管道是否在更改文件? 它不應該。

我沒有 Windows 機器來驗證哪個部分正在更改文件,或者 hashlib 在 Windows 實現中是否存在錯誤。 很可能是第一部分。

我錯過了顯而易見的事情嗎?

管道是否在更改文件? 它不應該。

遵循 Iłya Bursov 的建議表明,在 Windows 上,源代碼的簽出更改了文件結尾作為默認值。

這是一個已知的障礙(但不是錯誤): https://github.com/actions/checkout/issues/135#issuecomment-602171132

固定使用:

    steps:
      - name: Set git to use LF
        run: |
          git config --global core.autocrlf false

      - uses: actions/checkout@v2

但是,我並沒有像 GitHub 上的答案中那樣強制行結尾為lf

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM