Skip to content

Commit 0f23d5f

Browse files
lidavidmkou
andauthored
ci: add script to remove old versions from Gemfury (#3296)
Fixes #3294. --------- Co-authored-by: Sutou Kouhei <kou@cozmixng.org>
1 parent ee94eb5 commit 0f23d5f

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

.github/workflows/packaging.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,11 +1093,31 @@ jobs:
10931093
env:
10941094
ANACONDA_API_TOKEN: ${{ secrets.ANACONDA_API_TOKEN }}
10951095

1096+
# This takes a while due to sleeping to avoid rate limits, so run it first
1097+
# and in parallel with the builds
1098+
clean-gemfury:
1099+
name: "Remove old Gemfury packages"
1100+
runs-on: ubuntu-latest
1101+
if: github.ref_name == 'main' && (github.event.schedule || inputs.upload_artifacts)
1102+
steps:
1103+
- uses: actions/checkout@v5
1104+
- name: Install Python
1105+
uses: actions/setup-python@v5
1106+
with:
1107+
python-version: '3.13'
1108+
- name: Clean
1109+
run: |
1110+
pip install requests
1111+
./ci/scripts/gemfury_clean.py
1112+
env:
1113+
GEMFURY_API_TOKEN: ${{ secrets.GEMFURY_API_TOKEN }}
1114+
10961115
upload-gemfury:
10971116
name: "Upload packages to Gemfury"
10981117
runs-on: ubuntu-latest
10991118
if: github.ref == 'refs/heads/main' && (github.event.schedule || inputs.upload_artifacts)
11001119
needs:
1120+
- clean-gemfury
11011121
- java
11021122
- python-manylinux
11031123
- python-macos

ci/scripts/gemfury_clean.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env python3
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
19+
"""Remove old packages from Gemfury."""
20+
21+
import datetime
22+
import os
23+
import random
24+
import time
25+
26+
import requests
27+
28+
BASE_URL = "https://api.fury.io/1"
29+
30+
31+
def main():
32+
token = os.environ["GEMFURY_API_TOKEN"]
33+
cutoff = datetime.datetime.now(datetime.UTC) - datetime.timedelta(days=7)
34+
35+
with requests.Session() as session:
36+
session.headers = {
37+
"Authorization": f"Bearer {token}",
38+
"Accept": "application/json",
39+
}
40+
41+
packages = session.get(f"{BASE_URL}/packages?limit=50").json()
42+
for i, package in enumerate(packages):
43+
if i > 0:
44+
time.sleep(random.randint(3, 8))
45+
46+
print("Cleaning", package["name"])
47+
versions = session.get(
48+
f"{BASE_URL}/packages/{package['id']}/versions?limit=50"
49+
).json()
50+
print(versions)
51+
versions.sort(key=lambda v: v["created_at"], reverse=True)
52+
53+
# Always keep at least 1 version
54+
to_delete = [
55+
version["id"]
56+
for version in versions[1:]
57+
if version["created_at"] < cutoff.isoformat()
58+
]
59+
print("Removing", len(to_delete), "version(s) of", len(versions))
60+
61+
for version_id in to_delete:
62+
session.delete(f"{BASE_URL}/versions/{version_id}").raise_for_status()
63+
time.sleep(random.randint(1, 3))
64+
65+
66+
if __name__ == "__main__":
67+
main()

0 commit comments

Comments
 (0)