Skip to content

Commit 4992a00

Browse files
authored
Merge pull request #87 from meowmeowmeowcat/show-hash-values
This patch calculates SHA256, MD5, and BLAKE2-256 hash digests of every file in the packages directory and prints out their HEX representations to the log. Resolves #62
2 parents bea5cda + 977d067 commit 4992a00

File tree

5 files changed

+46
-0
lines changed

5 files changed

+46
-0
lines changed

Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ RUN \
1414
WORKDIR /app
1515
COPY LICENSE.md .
1616
COPY twine-upload.sh .
17+
COPY print-hash.py .
1718

1819
RUN chmod +x twine-upload.sh
1920
ENTRYPOINT ["/app/twine-upload.sh"]

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,16 @@ Sometimes, `twine upload` can fail and to debug use the `verbose` setting as fol
162162
verbose: true
163163
```
164164

165+
### Showing hash values of files to be uploaded
166+
167+
You may want to verify whether the files on PyPI were automatically uploaded by CI script.
168+
It will show SHA256, MD5, BLAKE2-256 values of files to be uploaded.
169+
170+
```yml
171+
with:
172+
print_hash: true
173+
```
174+
165175
## License
166176

167177
The Dockerfile and associated scripts and documentation in this project

action.yml

+5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ inputs:
3030
description: Show verbose output.
3131
required: false
3232
default: false
33+
print_hash:
34+
description: Show hash values of files to be uploaded
35+
required: false
36+
default: false
3337
branding:
3438
color: yellow
3539
icon: upload-cloud
@@ -44,3 +48,4 @@ runs:
4448
- ${{ inputs.verify_metadata }}
4549
- ${{ inputs.skip_existing }}
4650
- ${{ inputs.verbose }}
51+
- ${{ inputs.print_hash }}

print-hash.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import hashlib
2+
import pathlib
3+
import sys
4+
5+
packages_dir = pathlib.Path(sys.argv[1]).resolve().absolute()
6+
7+
print("Showing hash values of files to be uploaded:")
8+
9+
for file_object in packages_dir.iterdir():
10+
sha256 = hashlib.sha256()
11+
md5 = hashlib.md5()
12+
blake2_256 = hashlib.blake2b(digest_size=256 // 8)
13+
14+
print(file_object)
15+
print("")
16+
17+
content = file_object.read_bytes()
18+
19+
sha256.update(content)
20+
md5.update(content)
21+
blake2_256.update(content)
22+
23+
print(f"SHA256: {sha256.hexdigest()}")
24+
print(f"MD5: {md5.hexdigest()}")
25+
print(f"BLAKE2-256: {blake2_256.hexdigest()}")
26+
print("")

twine-upload.sh

+4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ if [[ ${INPUT_VERBOSE,,} != "false" ]] ; then
4444
TWINE_EXTRA_ARGS="--verbose $TWINE_EXTRA_ARGS"
4545
fi
4646

47+
if [[ ${INPUT_PRINT_HASH,,} != "false" || ${INPUT_VERBOSE,,} != "false" ]] ; then
48+
python /app/print-hash.py "${INPUT_PACKAGES_DIR%%/}"
49+
fi
50+
4751
TWINE_USERNAME="$INPUT_USER" \
4852
TWINE_PASSWORD="$INPUT_PASSWORD" \
4953
TWINE_REPOSITORY_URL="$INPUT_REPOSITORY_URL" \

0 commit comments

Comments
 (0)