@@ -31,27 +31,36 @@ def get_sha256_hash(file_path: str) -> str:
3131
3232
3333def main ():
34- target_subproject_env = os .environ .get ('TARGET_SUBPROJECT' , '' )
35- target_subprojects = list (filter (None , target_subproject_env .split (',' ) if target_subproject_env != '' else []))
34+ warnings : list [str ] = []
35+
36+ target_subproject_env : str = os .environ .get ('TARGET_SUBPROJECT' , '' )
37+ target_subprojects : list [str ] = [x for x in target_subproject_env .split (',' ) if x ]
3638 print ('target_subprojects: {}' .format (target_subprojects ))
3739
40+ workflow_artifacts_json_str = os .environ .get ('WORKFLOW_ARTIFACTS' , '{"artifacts":[]}' )
41+ artifacts : dict [str , dict ] = {}
42+ try :
43+ artifacts = {artifact ['name' ]: artifact for artifact in json .loads (workflow_artifacts_json_str )['artifacts' ]}
44+ print ({artifact ['name' ]: artifact ['id' ] for artifact in artifacts .values ()})
45+ except Exception as e :
46+ warnings .append (f'Failed to parse workflow artifacts JSON: { e } , { workflow_artifacts_json_str !r} ' )
47+
3848 with open ('settings.json' ) as f :
3949 settings : dict = json .load (f )
4050
4151 with open (os .environ ['GITHUB_STEP_SUMMARY' ], 'w' ) as f :
4252 f .write ('## Build Artifacts Summary\n \n ' )
43- f .write ('| Subproject | for Minecraft | File | Size | SHA-256 |\n ' )
53+ f .write ('| Subproject | For Minecraft | File | Size | SHA-256 |\n ' )
4454 f .write ('| --- | --- | --- | --- | --- |\n ' )
4555
46- warnings = []
4756 for subproject in settings ['versions' ]:
4857 if len (target_subprojects ) > 0 and subproject not in target_subprojects :
4958 print ('skipping {}' .format (subproject ))
5059 continue
51- game_versions = read_prop ('versions/{}/gradle.properties' . format ( subproject ) , 'game_versions' )
60+ game_versions = read_prop (f 'versions/{ subproject } /gradle.properties' , 'game_versions' )
5261 game_versions = game_versions .strip ().replace ('\r ' , '' ).replace ('\n ' , ', ' )
53- file_paths = glob .glob ('build-artifacts/{}/build/libs/*.jar' . format ( subproject ) )
54- file_paths = list ( filter ( lambda fp : not fp . endswith ( '-sources.jar' ) and not fp .endswith ('-dev .jar' ) and not fp . endswith ( '-shadow.jar' ), file_paths ))
62+ file_paths = glob .glob (f 'build-artifacts/{ subproject } /build/libs/*.jar' )
63+ file_paths = [ fp for fp in sorted ( file_paths ) if all ( not fp .endswith (f'- { classifier } .jar' ) for classifier in [ 'sources' , 'dev' , 'shadow' ])]
5564 if len (file_paths ) == 0 :
5665 file_name = '*not found*'
5766 sha256 = '*N/A*'
@@ -62,12 +71,39 @@ def main():
6271 if len (file_paths ) > 1 :
6372 warnings .append ('Found too many build files in subproject {}: {}' .format (subproject , ', ' .join (file_paths )))
6473
65- f .write ('| {} | {} | {} | {} | {} |\n ' .format (subproject , game_versions , file_name , file_size , sha256 ))
74+ f .write (f'| { subproject } | { game_versions } | { file_name } | { file_size } | { sha256 } |\n ' )
75+ f .write ('\n ' )
76+
77+ f .write ('## Artifact Files\n \n ' )
78+ all_digests_are_sha256 = all (artifact ['digest' ].startswith ('sha256:' ) for artifact in artifacts .values ())
79+ f .write ('| Artifact | For | Size | {} | \n ' .format ('SHA-256' if all_digests_are_sha256 else 'Digest' ))
80+ f .write ('| --- | --- | --- | --- |\n ' )
81+ for artifact_name , artifact_usage in [
82+ ('mod-jars' , 'Players who want to grab and install the mod jar into their Minecraft clients' ),
83+ ('build-artifacts' , 'Mod developers who want to inspect the complete build artifacts' ),
84+ ]:
85+ artifact_display_name = f'`{ artifact_name } `'
86+ artifact_size = 'unknown'
87+ artifact_digest = 'unknown'
88+ if artifact_name in artifacts :
89+ # https://docs.github.com/en/rest/actions/artifacts?apiVersion=2022-11-28#list-workflow-run-artifacts
90+ artifact : dict = artifacts [artifact_name ]
91+ try :
92+ download_url = f'{ os .environ ["GITHUB_SERVER_URL" ]} /{ os .environ ["GITHUB_REPOSITORY" ]} /actions/runs/{ os .environ ["GITHUB_RUN_ID" ]} /artifacts/{ artifact ["id" ]} '
93+ artifact_display_name = f'[`{ artifact_name } `]({ download_url } )'
94+ artifact_size = f'{ artifact ["size_in_bytes" ]} B'
95+ artifact_digest = '`{}`' .format (artifact ["digest" ].split (':' , 1 )[- 1 ] if all_digests_are_sha256 else artifact ["digest" ])
96+ except Exception as e :
97+ warnings .append (f'Failed to collect artifact info for { artifact_name } : { e } -- { artifact } ' )
98+
99+ f .write (f'| { artifact_display_name } | { artifact_usage } | { artifact_size } | { artifact_digest } |\n ' )
100+ f .write ('\n ' )
66101
67102 if len (warnings ) > 0 :
68- f .write ('\n # ## Warnings\n \n ' )
103+ f .write ('## Warnings\n \n ' )
69104 for warning in warnings :
70105 f .write ('- {}\n ' .format (warning ))
106+ f .write ('\n ' )
71107
72108
73109if __name__ == '__main__' :
0 commit comments