Skip to content

Commit 05469e3

Browse files
Merge pull request #33 from usefulness/size_comment
Add size outputs
2 parents a8eda39 + c98a2c3 commit 05469e3

3 files changed

Lines changed: 58 additions & 3 deletions

File tree

.github/workflows/main.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ jobs:
3636
with:
3737
body: |
3838
### diffuse-smoke-test-1
39+
`size-old-bytes`: ${{ steps.diffuse.outputs.size-old-bytes }}
40+
`size-old-text`: ${{ steps.diffuse.outputs.size-old-text }}
41+
`size-new-bytes`: ${{ steps.diffuse.outputs.size-new-bytes }}
42+
`size-new-text`: ${{ steps.diffuse.outputs.size-new-text }}
43+
`size-diff-comment_style_1`: ${{ steps.diffuse.outputs.size-diff-comment_style_1 }}
3944
4045
`steps.diffuse.outputs.diff-gh-comment:`
4146
${{ steps.diffuse.outputs.diff-gh-comment }}
@@ -101,6 +106,11 @@ jobs:
101106
with:
102107
body: |
103108
### diffuse-smoke-test-2
109+
`size-old-bytes`: ${{ steps.diffuse.outputs.size-old-bytes }}
110+
`size-old-text`: ${{ steps.diffuse.outputs.size-old-text }}
111+
`size-new-bytes`: ${{ steps.diffuse.outputs.size-new-bytes }}
112+
`size-new-text`: ${{ steps.diffuse.outputs.size-new-text }}
113+
`size-diff-comment_style_1`: ${{ steps.diffuse.outputs.size-diff-comment_style_1 }}
104114
105115
`steps.diffuse.outputs.diff-gh-comment-no-dex:`
106116
${{ steps.diffuse.outputs.diff-gh-comment-no-dex }}

action.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ outputs:
4040
diff-gh-comment-no-dex-all-collapsed:
4141
description: "Diffuse full output as Github comment all collapsed, without dex section, workaround for https://github.com/JakeWharton/diffuse/issues/96"
4242
value: ${{ steps.run-diffuse.outputs.diff-gh-comment-no-dex-all-collapsed }}
43+
4344
summary:
4445
description: "Diffuse summary"
4546
value: ${{ steps.run-diffuse.outputs.summary }}
@@ -61,6 +62,22 @@ outputs:
6162
classes:
6263
description: "Diffuse classes info"
6364
value: ${{ steps.run-diffuse.outputs.classes }}
65+
66+
size-old-bytes:
67+
description: "Old artifact size, number, in Bytes"
68+
value: ${{ steps.run-diffuse.outputs.size-old-bytes }}
69+
size-old-text:
70+
description: "Old artifact size, text, formatted with unit i.e. 320 KiB"
71+
value: ${{ steps.run-diffuse.outputs.size-old-text }}
72+
size-new-bytes:
73+
description: "New artifact size, number, in Bytes"
74+
value: ${{ steps.run-diffuse.outputs.size-new-bytes }}
75+
size-new-text:
76+
description: "New artifact size, text, formatted with unit i.e. 320 KiB"
77+
value: ${{ steps.run-diffuse.outputs.size-new-text }}
78+
size-diff-comment_style_1:
79+
description: "Size diff in a human readable form. i.e. '+16.6MiB (16.1MiB -> 32.7MiB)'"
80+
value: ${{ steps.run-diffuse.outputs.size-diff-comment_style_1 }}
6481
branding:
6582
color: 'red'
6683
icon: 'check-square'

entrypoint.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,20 @@ def grouper(iterable, n, fillvalue=None):
4242
return zip_longest(*args, fillvalue=fillvalue)
4343

4444

45+
def sizeof_fmt(num, suffix='B', sign=False):
46+
for unit in ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi']:
47+
if abs(num) < 1024.0:
48+
if sign:
49+
return "%+3.1f%s%s" % (num, unit, suffix)
50+
else:
51+
return "%3.1f%s%s" % (num, unit, suffix)
52+
num /= 1024.0
53+
if sign:
54+
return "%+.1f%s%s" % (num, 'Yi', suffix)
55+
else:
56+
return "%.1f%s%s" % (num, 'Yi', suffix)
57+
58+
4559
url = "https://github.com/JakeWharton/diffuse/releases/download/{0}/diffuse-{0}-binary.jar" \
4660
.format(os.getenv("INPUT_VERSION"))
4761
downloadArgs = ""
@@ -70,11 +84,25 @@ def grouper(iterable, n, fillvalue=None):
7084
if os.getenv("INPUT_NEW_MAPPING_FILE").strip():
7185
java_call.extend(["--new-mapping", os.getenv("INPUT_NEW_MAPPING_FILE")])
7286

87+
oldSize = os.stat(oldFile).st_size
88+
oldSizeText = sizeof_fmt(oldSize)
89+
newSize = os.stat(newFile).st_size
90+
newSizeText = sizeof_fmt(newSize)
91+
diff = newSize - oldSize
92+
diffComment1 = f"{sizeof_fmt(diff, sign=True)} ({oldSizeText} -> {newSizeText})"
7393
if is_debug():
74-
print("Old: {} bytes".format(os.stat(oldFile).st_size))
75-
print("New: {} bytes".format(os.stat(newFile).st_size))
94+
print("Old: {} bytes".format(oldSizeText))
95+
print("New: {} bytes".format(newSizeText))
96+
print("Diff: {} bytes".format(diffComment1))
97+
print(diffComment1)
7698
print(" ".join(java_call))
7799

100+
os.system(f"echo \"::set-output name=size-old-bytes::{oldSize}\"")
101+
os.system(f"echo \"::set-output name=size-old-text::{oldSizeText}\"")
102+
os.system(f"echo \"::set-output name=size-new-bytes::{newSize}\"")
103+
os.system(f"echo \"::set-output name=size-new-text::{newSizeText}\"")
104+
os.system(f"echo \"::set-output name=size-diff-comment_style_1::{diffComment1}\"")
105+
78106
process = subprocess.Popen(java_call, stdout=subprocess.PIPE)
79107
out, _ = process.communicate()
80108

@@ -100,7 +128,7 @@ def grouper(iterable, n, fillvalue=None):
100128

101129
for (title, content) in grouper(sections, 2):
102130
key = title.lower().strip().replace(" ", "-")
103-
value = content.strip().replace("$", "_")
131+
value = content.rstrip().lstrip("\n").replace("$", "_")
104132
if len(value) > github_output_limit:
105133
value = value[0:github_output_limit] + "\n...✂"
106134

0 commit comments

Comments
 (0)