Skip to content

Commit 77ee113

Browse files
committed
Move out the Python script from the shell script
1 parent e5cc29f commit 77ee113

File tree

3 files changed

+29
-27
lines changed

3 files changed

+29
-27
lines changed

action.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ inputs:
3131
required: false
3232
default: false
3333
print_hash:
34-
description: Show hash values of files uploaded
34+
description: Show hash values of files to be uploaded
3535
required: false
3636
default: false
3737
branding:

print-hash.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import os
2+
import hashlib
3+
4+
sha256 = hashlib.sha256()
5+
md5 = hashlib.md5()
6+
blake2_256 = hashlib.blake2b(digest_size=256 // 8)
7+
8+
file_list = os.listdir(os.path.abspath(os.getenv("INPUT_PACKAGES_DIR")))
9+
10+
for file in file_list:
11+
print(file)
12+
print("")
13+
14+
with open(os.path.abspath(os.path.join(os.getenv("INPUT_PACKAGES_DIR"), file)), "rb") as f:
15+
content = f.read()
16+
17+
sha256.update(content)
18+
md5.update(content)
19+
blake2_256.update(content)
20+
21+
print(f"SHA256: {sha256.hexdigest()}")
22+
print(f"MD5: {md5.hexdigest()}")
23+
print(f"BLAKE2-256: {blake2_256.hexdigest()}")
24+
print("")

twine-upload.sh

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

47+
if [[ ${INPUT_PRINT_HASH,,} || ${INPUT_VERBOSE,,} != "false" ]] ; then
48+
python ./print-hash.py
49+
fi
50+
4751
TWINE_USERNAME="$INPUT_USER" \
4852
TWINE_PASSWORD="$INPUT_PASSWORD" \
4953
TWINE_REPOSITORY_URL="$INPUT_REPOSITORY_URL" \
5054
exec twine upload ${TWINE_EXTRA_ARGS} ${INPUT_PACKAGES_DIR%%/}/*
51-
52-
if [[ ${INPUT_PRINT_HASH,,} != "false" ]] ; then
53-
cat > ./print_hash.py << EOF
54-
import os
55-
import hashlib
56-
sha256 = hashlib.sha256()
57-
md5 = hashlib.md5()
58-
blake2_256 = hashlib.blake2b(digest_size=256 // 8)
59-
file_list = os.listdir(os.path.abspath("${INPUT_PACKAGES_DIR%%/}"))
60-
for i in file_list:
61-
print(i)
62-
print("")
63-
file = open(os.path.abspath(os.path.join("${INPUT_PACKAGES_DIR%%/}", i)), "rb")
64-
content = file.read()
65-
file.close()
66-
sha256.update(content)
67-
md5.update(content)
68-
blake2_256.update(content)
69-
print(f"SHA256: {sha256.hexdigest()}")
70-
print(f"MD5: {md5.hexdigest()}")
71-
print(f"BLAKE2-256: {blake2_256.hexdigest()}")
72-
print("")
73-
EOF
74-
python ./print_hash.py
75-
rm ./print_hash.py
76-
fi

0 commit comments

Comments
 (0)