File tree Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change
1
+ name : Prune Actions caches
2
+
3
+ on :
4
+ schedule :
5
+ - cron : ' 0 21 * * *'
6
+ workflow_dispatch :
7
+
8
+ permissions :
9
+ contents : read
10
+ actions : write
11
+
12
+ jobs :
13
+ prune :
14
+ runs-on : ubuntu-latest
15
+ steps :
16
+ - run : rake ci:prune_caches
17
+ env :
18
+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
Original file line number Diff line number Diff line change @@ -132,6 +132,40 @@ namespace :ci do
132
132
end
133
133
end
134
134
135
+ desc "Purge old caches in GitHub Actions"
136
+ task :purge_caches , [ :days ] do |_ , args |
137
+ RubyWasm ::Toolchain . check_executable ( "gh" )
138
+
139
+ days = ( args [ :days ] || 1 ) . to_i
140
+ repo = ENV [ "GITHUB_REPOSITORY" ] || "ruby/ruby.wasm"
141
+ cutoff = ( Time . now . utc - days * 86_400 ) . iso8601
142
+
143
+ puts "Deleting caches last accessed before #{ cutoff } …"
144
+
145
+ page = 1
146
+ deleted = 0
147
+
148
+ loop do
149
+ resp = `gh api -H 'Accept: application/vnd.github+json' "/repos/#{ repo } /actions/caches?per_page=100&page=#{ page } "`
150
+ raise "gh api failed" unless $?. success?
151
+
152
+ data = JSON . parse ( resp )
153
+ caches = data [ "actions_caches" ]
154
+
155
+ old = caches . select { |c | c [ "last_accessed_at" ] < cutoff }
156
+ old . each do |c |
157
+ id = c [ "id" ]
158
+ system ( "gh api -X DELETE /repos/#{ repo } /actions/caches/#{ id } " )
159
+ deleted += 1
160
+ end
161
+
162
+ break if caches . size < 100
163
+ page += 1
164
+ end
165
+
166
+ puts "Deleted #{ deleted } caches older than #{ days } days."
167
+ end
168
+
135
169
desc "Publish artifacts as a GitHub Release"
136
170
task :publish , [ :tag ] do |t , args |
137
171
RubyWasm ::Toolchain . check_executable ( "gh" )
You can’t perform that action at this time.
0 commit comments