Skip to content

Commit 2b318b6

Browse files
CI: Remove package versions older than 30 days (#33)
* CI: Remove package versions older than 30 days * Add curl and jq to environment requirements. * Use output from the anaconda.org API to get latest upload time for each release of a package. If the upload date is older than 30 days add the package release for removal. * Use anaconda.org API over anaconda-client CLI API to get package versions as easier to understand. * Guard against duplicate entries
1 parent b4720c6 commit 2b318b6

1 file changed

Lines changed: 27 additions & 6 deletions

File tree

.github/workflows/remove-wheels.yml

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ jobs:
3737
create-args: >-
3838
python=3.11
3939
anaconda-client=1.12.0
40+
curl
41+
jq
4042
4143
- name: Show environment
4244
run: env
@@ -55,21 +57,40 @@ jobs:
5557
5658
- name: Remove old uploads to save space
5759
run: |
58-
# Remove all _but_ the last ${N_LATEST_UPLOADS} package versions
59-
# N.B.: `anaconda show` places the newest packages at the bottom of the output
60-
# of the 'Versions' section and package versions are preceded with a ' + '.
60+
# Remove all _but_ the last ${N_LATEST_UPLOADS} package versions and
61+
# remove all package versions older than 30 days.
6162
6263
if [ -s package-names.txt ]; then
64+
threshold_date="$(date +%F -d '30 days ago')"
65+
6366
# Remember can't quote subshell as need to split on (space seperated) token
6467
for package_name in $(cat package-names.txt); do
6568
6669
echo -e "\n# package: ${package_name}"
6770
68-
anaconda show "${ANACONDA_USER}/${package_name}" &> >(grep '+') | \
69-
awk '{print $2}' | \
70-
head --lines "-${N_LATEST_UPLOADS}" > remove-package-versions.txt
71+
curl --silent https://api.anaconda.org/package/"${ANACONDA_USER}/${package_name}" | \
72+
jq -r '.releases[].version' > package-versions.txt
73+
head --lines "-${N_LATEST_UPLOADS}" package-versions.txt > remove-package-versions.txt
74+
75+
for package_version in $(cat package-versions.txt); do
76+
# c.f. https://github.com/Anaconda-Platform/anaconda-client/issues/682#issuecomment-1677283067
77+
upload_date=$(curl --silent https://api.anaconda.org/release/"${ANACONDA_USER}/${package_name}/${package_version}" | \
78+
jq -r '.distributions[].upload_time' | \
79+
sort | \
80+
tail --lines 1 | \
81+
awk '{print $1}')
82+
83+
if [[ "${upload_date}" < "${threshold_date}" ]]; then
84+
echo "# ${ANACONDA_USER}/${package_name}/${package_version} last uploaded on ${upload_date}"
85+
echo "${package_version}" >> remove-package-versions.txt
86+
fi
87+
done
7188
7289
if [ -s remove-package-versions.txt ]; then
90+
# Guard against duplicate entries from packages over
91+
# count and time thresholds
92+
sort --output remove-package-versions.txt --unique remove-package-versions.txt
93+
7394
for package_version in $(cat remove-package-versions.txt); do
7495
echo "# Removing ${ANACONDA_USER}/${package_name}/${package_version}"
7596
anaconda --token ${{ secrets.ANACONDA_TOKEN }} remove \

0 commit comments

Comments
 (0)