Skip to content

Commit 23c2aa6

Browse files
committed
Output hashes from github action
1 parent cef2210 commit 23c2aa6

File tree

4 files changed

+40
-19
lines changed

4 files changed

+40
-19
lines changed

action.yml

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ inputs:
6868
required: false
6969
default: 'true'
7070
print-hash: # Canonical alias for `print_hash`
71-
description: Show hash values of files to be uploaded
71+
description: Show hash values of uploaded files
7272
required: false
7373
# default: 'false' # TODO: uncomment once alias removed
7474
print_hash: # DEPRECATED ALIAS; TODO: Remove in v3+
7575
description: >-
7676
[DEPRECATED]
77-
Show hash values of files to be uploaded
77+
Show hash values of uploaded files
7878
deprecationMessage: >-
7979
The inputs have been normalized to use kebab-case.
8080
Use `print-hash` instead.
@@ -86,6 +86,10 @@ inputs:
8686
Only works with PyPI and TestPyPI via Trusted Publishing.
8787
required: false
8888
default: 'true'
89+
outputs:
90+
hashes:
91+
description: Hash values of uploaded files
92+
value: ${{ steps.rundocker.outputs.hashes }}
8993
branding:
9094
color: yellow
9195
icon: upload-cloud
@@ -154,6 +158,7 @@ runs:
154158
}}
155159
shell: bash
156160
- name: Run Docker container
161+
id: rundocker
157162
# The generated trampoline action must exist in the allowlisted
158163
# runner-defined working directory so it can be referenced by the
159164
# relative path starting with `./`.
@@ -174,5 +179,19 @@ runs:
174179
verify-metadata: ${{ inputs.verify-metadata || inputs.verify_metadata }}
175180
skip-existing: ${{ inputs.skip-existing || inputs.skip_existing }}
176181
verbose: ${{ inputs.verbose }}
177-
print-hash: ${{ inputs.print-hash || inputs.print_hash }}
178182
attestations: ${{ inputs.attestations }}
183+
- name: Print hashes
184+
if: inputs.print-hash || inputs.print_hash
185+
run: |
186+
echo -n ${{ steps.rundocker.outputs.hashes }} | mapfile -d '' HASHES
187+
echo Showing hash values of uploaded files:
188+
for HASH in "${HASHES[@]}" ; do
189+
IFS=":" read -r SHA256 MD5 BLAKE2_256 FILE_OBJECT
190+
echo $FILE_OBJECT
191+
echo
192+
echo SHA256: $SHA256
193+
echo MD5: $MD5
194+
echo BLAKE2-256: $BLAKE_256
195+
echo
196+
done
197+
shell: bash

create-docker-action.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@ def set_image(ref: str, repo: str, repo_id: str) -> str:
5353
REQUIRED: False,
5454
},
5555
'verbose': {DESCRIPTION: 'Show verbose output.', REQUIRED: False},
56-
'print-hash': {
57-
DESCRIPTION: 'Show hash values of files to be uploaded',
58-
REQUIRED: False,
59-
},
6056
'attestations': {
6157
DESCRIPTION: (
6258
' Enable support for PEP 740 attestations.'
@@ -65,6 +61,11 @@ def set_image(ref: str, repo: str, repo_id: str) -> str:
6561
REQUIRED: False,
6662
},
6763
},
64+
'outputs': {
65+
'hashes': {
66+
DESCRIPTION: 'Hash values of uploaded files',
67+
},
68+
},
6869
'runs': {
6970
'using': 'docker',
7071
'image': image,

print-hash.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,25 @@
44

55
packages_dir = pathlib.Path(sys.argv[1]).resolve()
66

7-
print('Showing hash values of files to be uploaded:')
8-
97
for file_object in packages_dir.iterdir():
108
sha256 = hashlib.sha256()
119
md5 = hashlib.md5() # noqa: S324; only use for reference
1210
blake2_256 = hashlib.blake2b(digest_size=256 // 8)
1311

14-
print(file_object)
15-
print('')
16-
1712
content = file_object.read_bytes()
1813

1914
sha256.update(content)
2015
md5.update(content)
2116
blake2_256.update(content)
2217

23-
print(f'SHA256: {sha256.hexdigest()}')
24-
print(f'MD5: {md5.hexdigest()}')
25-
print(f'BLAKE2-256: {blake2_256.hexdigest()}')
26-
print('')
18+
print(
19+
":".join(
20+
(
21+
sha256.hexdigest(),
22+
md5.hexdigest(),
23+
blake2_256.hexdigest(),
24+
file_object.name,
25+
),
26+
),
27+
end="\0",
28+
)

twine-upload.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,8 @@ if [[ ${INPUT_ATTESTATIONS,,} != "false" ]] ; then
204204
TWINE_EXTRA_ARGS="--attestations $TWINE_EXTRA_ARGS"
205205
fi
206206

207-
if [[ ${INPUT_PRINT_HASH,,} != "false" || ${INPUT_VERBOSE,,} != "false" ]] ; then
208-
python /app/print-hash.py ${INPUT_PACKAGES_DIR%%/}
209-
fi
207+
echo -n "hashes=" >> ${GITHUB_OUTPUT}
208+
python /app/print-hash.py ${INPUT_PACKAGES_DIR%%/} >> ${GITHUB_OUTPUT}
210209

211210
TWINE_USERNAME="$INPUT_USER" \
212211
TWINE_PASSWORD="$INPUT_PASSWORD" \

0 commit comments

Comments
 (0)