Skip to content

Commit

Permalink
show sha256 in build summary
Browse files Browse the repository at this point in the history
  • Loading branch information
Fallen-Breath committed Jun 10, 2023
1 parent e956726 commit eba0d0e
Showing 1 changed file with 41 additions and 21 deletions.
62 changes: 41 additions & 21 deletions .github/workflows/scripts/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"""
__author__ = 'Fallen_Breath'

import functools
import glob
import hashlib
import json
import os

Expand All @@ -17,24 +19,42 @@ def read_prop(file_name: str, key: str) -> str:
)).split('=', 1)[1].lstrip()


target_subproject = os.environ.get('TARGET_SUBPROJECT', '')
with open('.github/workflows/matrix_includes.json') as f:
matrix: list[dict] = json.load(f)

with open(os.environ['GITHUB_STEP_SUMMARY'], 'w') as f:
f.write('## Build Artifacts Summary\n\n')
f.write('| Subproject | for Minecraft | Files |\n')
f.write('| --- | --- | --- |\n')

for m in matrix:
subproject = m['subproject_dir']
if target_subproject != '' and subproject != target_subproject:
continue
game_versions = read_prop('versions/{}/gradle.properties'.format(subproject), 'game_versions')
game_versions = game_versions.strip().replace('\\n', ', ')
file_names = glob.glob('build-artifacts/{}/build/libs/*.jar'.format(subproject))
file_names = ', '.join(map(
lambda fn: '`{}`'.format(os.path.basename(fn)),
filter(lambda fn: not fn.endswith('-sources.jar') and not fn.endswith('-dev.jar'), file_names)
))
f.write('| {} | {} | {} |\n'.format(subproject, game_versions, file_names))
def get_sha256_hash(file_path: str) -> str:
sha256_hash = hashlib.sha256()

with open(file_path, 'rb') as f:
for buf in iter(functools.partial(f.read, 4096), b''):
sha256_hash.update(buf)

return sha256_hash.hexdigest()


def main():
target_subproject = os.environ.get('TARGET_SUBPROJECT', '')
with open('.github/workflows/matrix_includes.json') as f:
matrix: list[dict] = json.load(f)

with open(os.environ['GITHUB_STEP_SUMMARY'], 'w') as f:
f.write('## Build Artifacts Summary\n\n')
f.write('| Subproject | for Minecraft | Files | SHA-256 |\n')
f.write('| --- | --- | --- | --- |\n')

for m in matrix:
subproject = m['subproject_dir']
if target_subproject != '' and subproject != target_subproject:
continue
game_versions = read_prop('versions/{}/gradle.properties'.format(subproject), 'game_versions')
game_versions = game_versions.strip().replace('\\n', ', ')
file_paths = glob.glob('build-artifacts/{}/build/libs/*.jar'.format(subproject))
file_paths = list(filter(lambda fp: not fp.endswith('-sources.jar') and not fp.endswith('-dev.jar'), file_paths))
if len(file_paths) == 0:
file_name = '*not found*'
sha256 = '*N/A*'
else:
file_name = '`{}`'.format(os.path.basename(file_paths[0]))
sha256 = get_sha256_hash(file_paths[0])
f.write('| {} | {} | {} | {} |\n'.format(subproject, game_versions, file_name, sha256))


if __name__ == '__main__':
main()

0 comments on commit eba0d0e

Please sign in to comment.