Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show hash values of files to be uploaded #87

Merged
merged 11 commits into from Jan 9, 2022
1 change: 1 addition & 0 deletions Dockerfile
Expand Up @@ -14,6 +14,7 @@ RUN \
WORKDIR /app
COPY LICENSE.md .
COPY twine-upload.sh .
COPY print-hash.py .

RUN chmod +x twine-upload.sh
ENTRYPOINT ["/app/twine-upload.sh"]
10 changes: 10 additions & 0 deletions README.md
Expand Up @@ -162,6 +162,16 @@ Sometimes, `twine upload` can fail and to debug use the `verbose` setting as fol
verbose: true
```

### Showing hash values of files to be uploaded

You may want to verify whether the files on PyPI were automatically uploaded by CI script.
It will show SHA256, MD5, BLAKE2-256 values of files to be uploaded.

```yml
with:
print_hash: true
```

## License

The Dockerfile and associated scripts and documentation in this project
Expand Down
5 changes: 5 additions & 0 deletions action.yml
Expand Up @@ -30,6 +30,10 @@ inputs:
description: Show verbose output.
required: false
default: false
print_hash:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized that maybe it's better to make this plural. But it's too late now so I'll keep it as is.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be a breaking change of the public API. We'd have to wait until v2 or even v3 depending on how we decide to do deprecation. There are other things, I'd change like using kebab-case for the inputs but not today.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, and I just realized that.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may add a print_hashes, and treat the current name as an undocumented alias.

description: Show hash values of files to be uploaded
required: false
default: false
branding:
color: yellow
icon: upload-cloud
Expand All @@ -44,3 +48,4 @@ runs:
- ${{ inputs.verify_metadata }}
- ${{ inputs.skip_existing }}
- ${{ inputs.verbose }}
- ${{ inputs.print_hash }}
26 changes: 26 additions & 0 deletions print-hash.py
@@ -0,0 +1,26 @@
import os
import hashlib
webknjaz marked this conversation as resolved.
Show resolved Hide resolved

sha256 = hashlib.sha256()
md5 = hashlib.md5()
blake2_256 = hashlib.blake2b(digest_size=256 // 8)

file_list = os.listdir(os.path.abspath(os.getenv("INPUT_PACKAGES_DIR")))
webknjaz marked this conversation as resolved.
Show resolved Hide resolved

print("Showing hash values of files to be uploaded:")

for file in file_list:
print(file)
webknjaz marked this conversation as resolved.
Show resolved Hide resolved
print("")

with open(os.path.abspath(os.path.join(os.getenv("INPUT_PACKAGES_DIR"), file)), "rb") as f:
content = f.read()
webknjaz marked this conversation as resolved.
Show resolved Hide resolved

sha256.update(content)
md5.update(content)
blake2_256.update(content)

print(f"SHA256: {sha256.hexdigest()}")
print(f"MD5: {md5.hexdigest()}")
print(f"BLAKE2-256: {blake2_256.hexdigest()}")
print("")
4 changes: 4 additions & 0 deletions twine-upload.sh
Expand Up @@ -44,6 +44,10 @@ if [[ ${INPUT_VERBOSE,,} != "false" ]] ; then
TWINE_EXTRA_ARGS="--verbose $TWINE_EXTRA_ARGS"
fi

if [[ ${INPUT_PRINT_HASH,,} || ${INPUT_VERBOSE,,} != "false" ]] ; then
webknjaz marked this conversation as resolved.
Show resolved Hide resolved
python /app/print-hash.py
webknjaz marked this conversation as resolved.
Show resolved Hide resolved
fi

TWINE_USERNAME="$INPUT_USER" \
TWINE_PASSWORD="$INPUT_PASSWORD" \
TWINE_REPOSITORY_URL="$INPUT_REPOSITORY_URL" \
Expand Down