@@ -41,15 +41,23 @@ async function clearGithubCaches(octokit, { repo, owner, clearDevelop, clearPend
4141 /** @type {Map<string, ReturnType<typeof octokit.rest.actions.listWorkflowRunsForRepo>> } */
4242 const cachedWorkflows = new Map ( ) ;
4343
44+ let deletedCaches = 0 ;
45+ let remainingCaches = 0 ;
46+
47+ let deletedSize = 0 ;
48+ let remainingSize = 0 ;
49+
4450 if ( ! response . data . length ) {
4551 break ;
4652 }
4753
48- for ( const { id, ref } of response . data ) {
54+ for ( const { id, ref, size_in_bytes } of response . data ) {
4955 core . info ( `Checking cache ${ id } for ${ ref } ...` ) ;
5056 // Do not clear develop caches if clearDevelop is false.
5157 if ( ! clearDevelop && ref === 'refs/heads/develop' ) {
5258 core . info ( '> Keeping cache because it is on develop.' ) ;
59+ remainingCaches ++ ;
60+ remainingSize += size_in_bytes ;
5361 continue ;
5462 }
5563
@@ -109,24 +117,39 @@ async function clearGithubCaches(octokit, { repo, owner, clearDevelop, clearPend
109117 // Case 2: This is a PR, but we do not want to clear pending PRs
110118 // In this case, this cache should never be cleared
111119 core . info ( '> Keeping cache of every PR workflow run.' ) ;
120+ remainingCaches ++ ;
121+ remainingSize += size_in_bytes ;
112122 continue ;
113123 } else if ( clearBranches ) {
114124 // Case 3: This is not a PR, and we want to clean branches
115125 core . info ( '> Clearing cache because it is not a PR.' ) ;
116126 } else {
117127 // Case 4: This is not a PR, and we do not want to clean branches
118128 core . info ( '> Keeping cache for non-PR workflow run.' ) ;
129+ remainingCaches ++ ;
130+ remainingSize += size_in_bytes ;
119131 continue ;
120132 }
121133
122134 core . info ( `> Clearing cache ${ id } ...` ) ;
123135
124- await octokit . rest . actions . deleteActionsCacheById ( {
136+ deletedCaches ++ ;
137+ deletedSize += size_in_bytes ;
138+
139+ /* await octokit.rest.actions.deleteActionsCacheById({
125140 owner,
126141 repo,
127142 cache_id: id,
128- } ) ;
143+ }); */
129144 }
145+
146+ const format = new Intl . NumberFormat ( 'en-US' , {
147+ style : 'decimal' ,
148+ } ) ;
149+
150+ core . info ( 'Summary:' ) ;
151+ core . info ( `Deleted ${ deletedCaches } caches, freeing up ~${ format . format ( deletedSize / 1000 / 1000 ) } mb.` ) ;
152+ core . info ( `Remaining ${ remainingCaches } caches, using ~${ format . format ( remainingSize / 1000 / 1000 ) } mb.` ) ;
130153 }
131154}
132155
0 commit comments